OpenGL lighting with glOrtho
So I have a 开发者_如何学运维3D object that I'm drawing with the following light:
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 0.9}; /* White light. */
GLfloat light_position[] = {300.0, 300.0, 300.0, 0.0};
glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
My object is illuminated as I expect when I draw it in a "normal" context (i.e. no glOrtho).
However, I'm working on the orthogonal projections of the object and use glOrtho for that purpose (on the ModelView matrix). I initialize the light after the glOrtho call, then draw the object in the exact same way as I did in the case that worked (the 3D case). But for some reason, the lighting does not work on the orthogonal projections, i.e. once I did the glOrtho call.
This is not a problem with normals since it works in the 3D case. I'm guessing that with the glOrtho call, everything gets pressed together on a thin layer, which explains why the light doesn't behave as expected... but honestly, I have not experience with lighting so this might be wrong.
Anyone knows what's going on?
Lighting happens in eye space, i.e. before the projection is applied at all. You probably use the transformations matrices in a wrong way. glOrtho, glFrustung or gluPerspective go into GL_PROJECTION matrix, gluLookAt and other camera placement stuff go into GL_MODELVIEW.
精彩评论