Sign in to follow this  

GLSL Lighting Problem

This topic is 4160 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
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

This topic is 4160 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this