PDA

View Full Version : Light Enabled, object gets invisible



iris_raj
08-09-2006, 05:44 AM
Dear All,

Below is a simple program for displaying sphere and Plane. When I enable light sphere/plane is not visible. But when comment ligth Features, everything get displayed.What might be problem


static int year = 0;
static int day = 0;

GLfloat pos[] = {2.0f,2.0f,2,0.0f,1.0f};

void init()
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glLightfv(GL_LIGHT0,GL_POSITION,pos);


}

void reshape(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f,(int)w/(int)h,0.0f,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void keyboardFunc(unsigned char key, int x, int y)
{
switch(key)
{
case 'd':
day = (day + 10) % 360;
glutPostRedisplay();
break;
}

}

void drawFloor()
{

glBegin(GL_QUADS);
glVertex3f(-1.0f,0.0f,1.0f);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,0.0f,-1.0f);
glVertex3f(-1.0f,0.0f,-1.0f);
glEnd();
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
gluLookAt(0.0,0.0f,5.0,0.0f,0.0f,0.0f,0.0,1.0f,0.0 f);
//glColor3f(1.0f,1.0f,0.0f);
glPushMatrix();
glTranslatef(0.0f,-2.0f,0.0f);
drawFloor();
glPopMatrix();
glPushMatrix();
glutSolidSphere(0.2,20,16);
glRotatef(year,0.0,1.0,0.0);
glTranslatef(2.0,0.0f,0.0);
glPopMatrix();


glutSwapBuffers();
}

int main(int argc, char *argv[])
{

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPT H);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Laptop Opengl");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboardFunc);
glutMainLoop();
return 0;

}

RigidBody
08-09-2006, 06:09 AM
try again with glClearColor(1.0f,1.0f,1.0f,0.0f);

k_szczech
08-09-2006, 01:08 PM
If you use lighting you should specify material properties and normal vectors.