Reputation: 1066
I'm trying to draw some simple triangles in OpenGL. The problem is that my triangle is always white, wheras I put some color with the glColor3f function:
def OnDraw(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glClearColor(.1, 0.1, 0.1, 1.0)
glBegin (GL_TRIANGLES)
glColor3f (1.0, 0.0, 0.0)
glVertex2f (0.25, 0.25)
glColor3f (0.0, 1.0, 0.0)
glVertex2f (0.12, 0.25)
glColor3f (0.0, 0.0, 1.0)
glVertex2f (0.25, 0.4)
glEnd()
and here is my initialization:
def InitGL(self):
# set viewing projection
glMatrixMode(GL_PROJECTION)
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0)
# position viewer
glMatrixMode(GL_MODELVIEW)
glTranslatef(0.0, 0.0, -2.0)
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
Any idea?
Upvotes: 0
Views: 849
Reputation: 1066
I solved the problem my removing: glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0)
Can somebody explained me why is it working now?
Upvotes: 0
Reputation: 162164
With lighting enabled vertex colors are no longer considered for the calculations. Instead you have to set material properties. However vertex colors are quite convenient so there's a method to use vertex colors to set material properties.
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
However note that for lighting to work you must provide vertex normals otherwise things will look strange. It might be best to disable lighting for the time being.
On a different note: Please stop using old and dusted immediate mode, fixed function pipeline OpenGL. Instead learn about modern OpenGL. I recommend http://arcsynthesis.org/gltut for a start.
Upvotes: 2