Jump to content
  • Advertisement
Sign in to follow this  
brainsocket

GLSL Lighting Problem

This topic is 4445 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm adding normal mapping to a Quake 3 BSP map via a GLSL shader, and so far, everything has worked great. However, I've come to a problem with regards to my light in the scene (there is currently only one) moving with my camera. I'm guessing this is a matrix error somewhere, but so far I haven't been able to correct it. When the camera shifts left, the light moves with it, and when rotated, does the same. Weird. Here is my rendering code:
void RenderScene() 
{
	glLightfv (GL_LIGHT0,GL_POSITION,g_lightpos);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	Camera.Look();  //Note: Camera.Look() just calls gluLookAt...could this 
                        //be the problem?

	BSP.Render(Camera.Position());

	SwapBuffers(g_hDC);	
}
And here is my vertex shader:
varying vec4 pos;

void main( void )
{
	gl_Position = ftransform();
	pos = gl_ModelViewMatrix * gl_Vertex;
	gl_TexCoord[0] = gl_MultiTexCoord0;
}
The BSP level is rendered fine. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Setting fixed-function light postion has to be done in eye space. So call

glLightfv (GL_LIGHT0,GL_POSITION,g_lightpos);

after You called Camera.Look();

BTW. If You want to use GLSL then using uniforms and pixel shaders instead fixed-fuction lights gives better results.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!