|
-
Jul 15th, 2006, 03:34 AM
#1
Thread Starter
Lively Member
[RESOLVED] Problems with Specular light and Spotlight in OpenGL
Hi,
I am using OpenGL to draw a rotating cube where light is shone on it. I used a positional light and a spotlight. The problem is that these 2 light components don't seem to show up properly.
The cube is located at (1,1,-10) and the positional light is located at (1,1,-5). I've added ambient,diffuse and specular light components. In addition, I used glMaterials() to make the material of the cube shiny.
The code snippet for the positional light is shown below:
GLfloat lightDir[] = {1.0,1.0,-5.0,1.0}; // Light Direction
glLightfv(GL_LIGHT0,GL_POSITION,lightDir);
GLfloat white[] = {1.0,1.0,1.0,1.0}; // Light colours
GLfloat blue[] = {0.0,0.0,1.0,1.0};
glLightfv(GL_LIGHT0,GL_AMBIENT,blue);
glLightfv(GL_LIGHT0,GL_DIFFUSE,blue);
glLightfv(GL_LIGHT0,GL_SPECULAR,white);
glMaterialf(GL_FRONT,GL_SHININESS,128); // Use a shiny material
The ambient and diffuse components show up properly but the specular component didnt appear. The lighting appeared to be the same regardless of whether I enabled specular lighting or not.
As for the spotlight, it didnt show up at all. The effect I wanted is for the spotlight to show up as a round area of light on the cube's surface. I customized the spotlight's direction, cutoff and exponent. The code snippet for the spotlight is shown below:
GLfloat spotLightColour[] = {0.0,1.0,0.0}; //spot light colour
GLfloat spotlightDirection[] = {1.0,1.0,-6.0}; // spot light direction
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,5.0f); // spot light cut-off
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spotlightDirection);
glLightfv(GL_LIGHT1,GL_SPECULAR,spotLightColour);
glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,70.0f); // spot light exponent
For the cube, its length on the x axis starts from -1 to 1. The same goes for the width and height on the y and z axis.
What could be the problem regarding the specular component of the positional light (there was no shiny area on the cube) and the spotlight (it didnt appear at all) ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|