nahid
2005.04.12, 10:06 PM
Hey,
Im trying to make a lighting that is like Daytime, and so i have a code set up to turn on lighting and enable it but my lighting isnt showing anywhere, i set teh ambient to red and diffuse to blue to actually test it if it works or not, so here is my code:
//Lighting
GLfloat lightpos[]={0.0, 100.0, 0.0, 0.0};
GLfloat lightColor[4] = {1, 0, 0, 1};
GLfloat ambientColor[4] = {0, 0, 1, 1};
GLvoid InitGL(GLvoid)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //background
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); // Enables Depth Testing
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
glLightfv(GL_LIGHT0, GL_POSITION,lightpos);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset The Projection Matrix
gluPerspective(45.0f,(GLfloat)kWindowWidth/(GLfloat)kWindowHeight,10.0,10000.0);
glMatrixMode(GL_MODELVIEW);
}
// DrawGLScene
GLvoid DrawGLScene(GLvoid)
{
// LIGHT SET UP
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
glutSwapBuffers();
}
So there is my code for lighting, and the lighting stuff are in INITGL and DRAWGLSCENE, so please help me and let me know whats wrong.
Thanks,
Im trying to make a lighting that is like Daytime, and so i have a code set up to turn on lighting and enable it but my lighting isnt showing anywhere, i set teh ambient to red and diffuse to blue to actually test it if it works or not, so here is my code:
//Lighting
GLfloat lightpos[]={0.0, 100.0, 0.0, 0.0};
GLfloat lightColor[4] = {1, 0, 0, 1};
GLfloat ambientColor[4] = {0, 0, 1, 1};
GLvoid InitGL(GLvoid)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //background
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); // Enables Depth Testing
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
glLightfv(GL_LIGHT0, GL_POSITION,lightpos);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset The Projection Matrix
gluPerspective(45.0f,(GLfloat)kWindowWidth/(GLfloat)kWindowHeight,10.0,10000.0);
glMatrixMode(GL_MODELVIEW);
}
// DrawGLScene
GLvoid DrawGLScene(GLvoid)
{
// LIGHT SET UP
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
glutSwapBuffers();
}
So there is my code for lighting, and the lighting stuff are in INITGL and DRAWGLSCENE, so please help me and let me know whats wrong.
Thanks,