PDA

View Full Version : lighting not working



Sergiu
01-30-2009, 02:43 PM
Hello.Please tell me why doestn't lighting work when depth test is enabled.Or, if it is working , why doesn't my program show my illuminated sphere until i delete the enable depth test command.Thank you for your help.

dletozeun
01-30-2009, 04:51 PM
How can you imagine that we could help you with such a poor information?! Please, learn how to ask question and expose your problem. As Satan (not related to the evil) once suggest, check this (http://catb.org/~esr/faqs/smart-questions.html) out.

Sergiu
01-31-2009, 04:19 AM
Ok.here the code from my application:

#include <GL/gl.h>
#include <GL/glut.h>
#include <math.h>
#include <GL/glu.h>
static GLfloat unghi=0.0,x=1.0f,z=0.0f;
void RenderScene(void)
{

glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(255,0,0);
glPushMatrix();
glutWireCube(1.6);
gluLookAt(x,0.0,z,0.0,0.0,0.0,0.0,1.0,0.0);
glutSolidCube(1.6);
glPopMatrix();
glutSwapBuffers();

}


void SetupRC()
{
GLfloat ambiantLight[]={1.0f,0.0f,1.0f,1.0f};

//Enable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);

glEnable(GL_LIGHTING);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambiantLight );

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
glClearColor(0.0f,0.0f,0.0f,1.0f);
}

void ChangeSize(GLsizei w,GLsizei h)
{
if (h==0)
h=1;

glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glFrustum(-1.0,1.0,-1.0,1.0,1.5,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void Timp(int value)
{
x=4*sin(unghi);
z=4*cos(unghi);
unghi+=0.1f;
glutPostRedisplay();
glutTimerFunc(20,Timp,1);
}
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("Simplu");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutTimerFunc(20,Timp,1);
SetupRC();

glutMainLoop();

return 0;
}

if I run the above code, the application works perfectly,but if I turn on depth testing it doesn't show anything.What is the reason?

ZbuffeR
01-31-2009, 01:14 PM
try replacing glClear(GL_COLOR_BUFFER_BIT) with glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);