[PyOpenGL-Users] Trouble with lighting
Brought to you by:
mcfletch
From: Matt B. <ma...@rt...> - 2005-06-08 08:45:26
|
Howdy folks, I've been looking at the NeHe7 tutorial included with OpenGLcontext, trying to get normals working. I'm not worrying about the math for now, just copying & pasting some code from NeHe7 into my script. Here's my OpenGL-relevant code: # the following lines are called at startup screen = pygame.display.set_mode((x_res,y_res), OPENGL|DOUBLEBUF|FULLSCREEN) glMatrixMode(GL_PROJECTION) glEnable(GL_DEPTH_TEST) gluPerspective(45.0,x_res/y_res,0.1,100.0) glRotatef(15, 1, 0, 0) glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, .2, .2, 1.0)); glLightfv(GL_LIGHT0, GL_DIFFUSE, (.8,.8,.8)); glLightfv(GL_LIGHT0, GL_POSITION, (-2,0,3,1)); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (0.5, 0.1, 0.7, 1.0)) glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE) # everything after this gets called every frame glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) x = 1 y = 1 z = -1 glRotatef(1, 1, 1, 0) # I then define some quads with normals, like this one (copied from the tutorial): glBegin(GL_QUADS); glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 1.0); glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, 1.0); glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, 1.0); glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 1.0); # etc........ glEnd() pygame.display.flip() That's it. Note I did change the code that enables lighting, slightly. I tried it the way the tutorial said, didn't work, so I tried changing it a bit to remove the redundancy of setting up GL_LIGHT1 and disabling GL_LIGHT1 (any particular reason this is done?). Is there a "gotcha" with this lighting setup somewhere, or something dumb I'm doing? Everything looks fine compared to the tutorial, but my quads continue to have no shading whatsoever. FWIW, I do have textures on these quads. Is it possible for texture parameters to cause problems with lighting? I've scoured the net, read the OpenGL docs, and examined the NeHe7 tutorial carefully, no progress at all. -Matt Bailey |