使用 glOrtho 进行 OpenGL 光照
因此,我有一个使用以下光线绘制的 3D 对象:
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);
当我在“正常”上下文(即没有 glOrtho)中绘制它时,我的对象会按照我的预期被照亮。
但是,我正在研究对象的正交投影,并使用 glOrtho 来实现此目的(在 ModelView 矩阵上)。我在 glOrtho 调用后初始化灯光,然后以与工作情况(3D 情况)中完全相同的方式绘制对象。但由于某种原因,照明在正交投影上不起作用,即一旦我进行了 glOrtho 调用。
这对于法线来说不是问题,因为它适用于 3D 情况。我猜测通过 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
照明发生在眼睛空间中,即在应用投影之前。您可能以错误的方式使用变换矩阵。 glOrtho、glFrustung 或 gluPerspective 进入 GL_PROJECTION 矩阵,gluLookAt 和其他相机放置内容进入 GL_MODELVIEW。
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.