View Full Version : Problem with positioning of light.

03-29-2011, 12:04 AM
Hi, I am a beginner in OpenGL. I am trying to integrate code for water caustics (available online) with water wave dynamics code which I have written.

The problem is the caustics code uses lighting in order to get the effect and I haven't used lighting, when i integrated the code it got compiled but everything appears dark as if light is switched off. So I made some changes with positioning but they aren't effective.

Following is my glutReshapeFunc

void reshape(int w, int h)
glViewport (0, 0, (GLsizei) w, (GLsizei) h);

float aspectRatio = (float)w / h;

gluPerspective(60.0f, (float)(w)/h, 1.0f, 1000.0f);


and my lightning positioning code inside display is


/* Reposition the light source. */
lightPosition[0] = 12*cos(lightAngle);
lightPosition[1] = lightHeight;
lightPosition[2] = 12*sin(lightAngle);
if (directionalLight) {
lightPosition[3] = 0.0;
} else {
lightPosition[3] = 1.0;

glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

where lightangle is 0.0,
where lightHeight is 20.0,

My confusion is, in gluPerspective is the z near and far plane is 1.0 and 1000.0, where is my 3D water mesh drawn and then where do I position my light?

Many Thanks in advance..