I am making a game in PyOpenGL and I want to let the light to be darkened when the player dies. How can I do that?
I've tried several resources like Tweak the brightness/gamma of the whole scene in OpenGL and https://www.gamedev.net/forums/topic/535812-disable-opengl-lighting-completely-to-dark-scene/ with no luck.
#!/usr/local/bin/python3
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
#[...]
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glShadeModel(GL_SMOOTH)
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_BLEND)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
glEnable(GL_LIGHT0)
glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5, 1])
glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1])
#[...]
while True:
#[...]
glClearColor(0.53, 0.63, 0.98, 1) #Change background colour (sky blue)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
#[...]
if health <= 0:
pass #this is where the darkening should go
#---Tried---
glDisable(GL_LIGHT1)
glDisable(GL_LIGHT2)
glDisable(GL_LIGHT3)
glDisable(GL_LIGHT4)
glDisable(GL_LIGHT5)
glDisable(GL_LIGHT6)
glDisable(GL_LIGHT7)
glMaterialfv(GL_FRONT, GL_SPECULAR, @mat_specular)
glMaterialfv(GL_FRONT, GL_SHININESS, @mat_shininess)
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, @globala )
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
#---Tried---
pygame.display.flip()
I expected the scene to be dark, but instead it returns a traceback about decorators. Even if I delete these, nothing changes on my scene.