PDA

View Full Version : 3D Objects Washed Out....Lighting Issues



Tweener
12-07-2002, 11:58 AM
Hey all,
In my 3D scene I have a glutsolid torus, but when I render the scene my object is completely white, it has to be my lighting source. But Im not sure what I'm doing wrong.
Can someone please help, its driving me nuts here's my display function. Thanks guys

void Display(void)
{
// Material ambience is the light that is reflected
// from the material from the light sources in every
// direction to the rest of the scene.

GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f};

//Color of object to be
GLfloat mat_diffuse[] = { .6f, 0.6f, 0.6f, 1.0f};

//Specular allows you to control the effect the material
//or object has on the highlights
GLfloat mat_specular[] = {1.0f,1.0f,1.0f,1.0f};

//light that is being produced by the object
GLfloat mat_shininess[] = {80.0f};

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); //set initial ambience
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); //set intial diffusion color
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); //set initial specular settings
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); //set initial shininess for objects

GLfloat lightIntenisity[] = { 0.9f, 0.9f, 0.9f, 1.0f};

GLfloat light_position[] = {29.0f, 0.0f, 0.0f, 0.0f};

glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntenisity );

glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
Camera.Render();
glTranslatef(0.0,0.8,0.0);

glScalef(3.0,1.0,3.0);



//PURPLE DONUT OBJECT
glPushMatrix();
glRotated(-90, 1, 0, 0.0);
glScaled(0.08, 0.08, 0.08);
GLfloat donut_diffuse[] = { 0.6f, 0.0f, 1.0f, 1.0f};
glMaterialfv(GL_FRONT, GL_DIFFUSE, donut_diffuse);
glutSolidTorus(.5,2,90,90);
glPopMatrix();

glFlush();
glutSwapBuffers();

}

cbwan
12-08-2002, 04:16 AM
try to add glEnable(GL_LIGHT0); after you set light parameters.

have fun http://www.opengl.org/discussion_boards/ubb/wink.gif
cb

cbwan
12-08-2002, 04:25 AM
oh and glEnable(GL_LIGHTING); too =))

have fun!
cb