开发者

multiple lights in GLObjViewer (OpenGL)

I am building a 3D-house in OpenGL. I decided to use GLObjViewer to load the models and textures. That works fine. But GLObjViewer's shading modules just support "a single 开发者_StackOverflowfixed directional light source shining down the OpenGL default negative z-axis" as its documentation states. So when I fix the light, some walls become dark;when I make the light move with the camera, the wall's shades changes continuously.

What I want now is to make all the walls well illuminated and their shades do not change after moving camera. Please suggest me how to afford it? (How to use multiple lights in GLObjViewer or another solution).

You can find GLObjViewer documentation and source code here: http://www.dhpoware.com/demos/glObjViewer.html


OpenGL-2 light positioning is transformed by the modelview matrix. That means that you must set light position after placing the camera but before applying the object local transformations.

OpenGL before version 3 supports at least 8 lights (GL_LIGHT0 … GL_LIGHT7). Which can be enabled and set independently. Later OpenGL versions are completely shader driven; lights are implemented through apropriate shaders, light parameters are passed through uniforms.

OpenGL-3 compatibility and earlier versions have predefined uniforms like gl_LightPosition[], which is used in this application. You set those predefined uniforms through the appropriate OpenGL state setters. glLight… in your case.

OpenGL-3.1 core and later abandon predefined light uniforms alltogether and place the burden on the programmer to implement it.


You might also have some luck doing:

glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

This will compute the specular reflections from the origin of the eye coordinate system instead of statically (direction parallel to and towards the -z axis).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜