Jump to content
  • Advertisement
Sign in to follow this  
dTr

OpenGL specular lighting

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

Hi all!! I am learning opengl and I have a problem with specular lighting. I have a light above what will be a pool table, and I turned specular lighting on to see what happened. I assume the specular highlights should appear below the light source but instead they appear to go off to one side. Any help would be appreciated. Here is part of my source -
void RenderScene(void)

{

	static GLfloat yRot = 0.5f;         // Rotation angle for animation
	GLfloat  specref[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
	
	yRot += 0.1f;

	// Clear the window with current clearing color

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();

		//glTranslatef(-3.0f, 0.0f, -10.0f);
		gluLookAt(-12.0f,0.0f,2.0f, 0.0f, 0.0f, 2.0f, 0.0f, 0.0f, 1.0f);
		glRotatef(yRot,0.0f,0.0f,1.0f);

		glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
		glMaterialfv(GL_FRONT, GL_SPECULAR,specref);
	
		glMateriali(GL_FRONT,GL_SHININESS,128);	

		glPushMatrix();
			pObj = gluNewQuadric();
	
			gluQuadricNormals(pObj, GLU_SMOOTH);
			glTranslatef(3.0f, 3.0f, 1.0f);
			glColor3f(0.0f,1.0f,1.0f);
			gluSphere(pObj, 0.2f,20,20);
			glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
		glPopMatrix();
	

	
		glBegin(GL_QUADS);
	
			//Table Top
			glColor3f(0.0f, 0.5f, 0.0f);

			for (int i=-100; i<100; i++)
			{
				for(int j=-50; j<50; j++)
				{
					//glNormal3f((float)(rand()%10)/900, (float)(rand()%10)/900, 0.95f);
					glNormal3f(0.0f, 0.0f, 1.0f);
					glVertex3f(((float)i)/10,((float)j)/10+0.1,0.0f);
					glVertex3f(((float)i)/10,((float)j)/10,0.0f);
					glVertex3f(((float)i)/10+0.1,((float)j)/10,0.0f);
					glVertex3f(((float)i)/10+0.1,((float)j)/10+0.1,0.0f);
				}
			}

		glEnd();

	
	glPopMatrix();

	//Do the buffer Swap

	glutSwapBuffers();

}

Thanks

Share this post


Link to post
Share on other sites
Advertisement
How tessalated is the surface of the pool table? OpenGL's built in specular highlights won't give you a big round highlight I the middle of the polygon. The highlights are interpolated between vertices, so the shiny spots are going to be near the vertices.

Share this post


Link to post
Share on other sites
yeah, I realized that. The surface is made up of 200x100 rectangles.

Share this post


Link to post
Share on other sites
ok, here is a screenshot showing what I mean. The floating blue sphere is the light source.
Photo Sharing and Video Hosting at Photobucket

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!