Lighting question

Started by
6 comments, last by YellowMaple 17 years, 7 months ago
I'm playing around with lighting in OpenGL and it seems as though if I use the commands: gluPerspective and gluLookAt to specify the viewing volume and the camera details it make the lighting in my scene significantly less noticeable. I don't do anything fancy just:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(60.0f, aspect, 1.0f, 1000.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, 7.0f,
          0.0f, 0.0f, 0.0f,
	  0.0f, 1.0f, 0.0f);

Yet if I leave these calls out and use the defaults the lighting is much more apparent. Any ideas as to why? Please let me know if it would help to see more code, but all I do really is just use glutSolidSphere. Mats and lights have of course been defined prior to drawing. Also, I was playing around with ftgl as a tool to output text to the screen. When I compile and run the demo (in VC++), which uses GLUT, the text rendered to the screen looks very smooth. However, when I render the text in my app its pixelated. Does GLUT by default have some sort of routine to perform anti-aliasing? Thanks in advance for the help!
Advertisement
When and how do you specify light position? What kind of light do you use?
if (time() == $) { $ = 0; }
I specify light position before my main loop:
        ...	ge->addLight(GraphicsEngine::G_SPOTLIGHT, 				Vector(0.5f, 0.5f, 1.0f),				Vector(0.5f, 0.5f, 1.0f),				Vector(0.6f, 0.6f, 0.6f),				Vector(2.0f, 2.0f, 1.0f),				0.2f, 0.2f, 0.3f,				Vector(-1.0f, -1.0f, -1.0f, 1.0f), 45.0f, 0.4f);	while(true) {		if(eventHandler->peek() == EH_QUIT) {			Logger* LOG = Logger::getInstance();			LOG->info("Exiting application...");			break;		}		if (!ge->draw()){ 			break;		}		else {			SwapBuffers(g_hDC);		}	}

where ge->addLight simply does:
        ...	glLightfv(tag, GL_SPECULAR, specular.getRawData());	glLightfv(tag, GL_DIFFUSE, diffuse.getRawData());	glLightfv(tag, GL_AMBIENT, ambient.getRawData());	glLightfv(tag, GL_POSITION, pos.getRawData());	glLightf(tag, GL_CONSTANT_ATTENUATION, constantAttenuation);	glLightf(tag, GL_LINEAR_ATTENUATION, linearAttenuation);	glLightf(tag, GL_QUADRATIC_ATTENUATION, quadraticAttenuation);	glLightfv(tag, GL_SPOT_DIRECTION, direction.getRawData());	glLightf(tag, GL_SPOT_CUTOFF, l->getSpotCutoff());	glLightf(tag, GL_SPOT_EXPONENT, l->getSpotExponent());        ...

During the ge->draw (which is where I do the projection/modelview transformations listed previously) I just enable/disable lights when needed.
To show you the result:


In the second picture, which is where I use gluLookAt and gluPerspective, you can hardly see the lighting.
Not sure but i think it should be like this
drawScene(){    gluLookAt(cameraPos, LookatPos, UpDirection);    specify light position    drawing stuff}
what i mean is you should not specify light position before lookat
Hi !
If your camera is changing of position (the default one and the other than you specify), do you change attenuation values ? if no perhaps it can help you to have a better lighting.
hope it helps.
other idea : maybe the position of your camera is at a place which do that you partially behind the sphere, so perhaps you see it less lighted.
Light position should be set in eye space (after a call to gluLookAt()).
if (time() == $) { $ = 0; }
Thanks for the help guys. I specify lighting position after gluLookAt and it did the trick.

This topic is closed to new replies.

Advertisement