Well it seems the information that I gave was not enough, but since I really need help ASAP, I’m gonna ask for help again. And this time with more information:
GLuint PixelFormat;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 16;
Format[i] = ChoosePixelFormat(hdc[i], &pfd);
SetPixelFormat(hdc[i], Format[i], &pfd);
hrc[i] = wglCreateContext(hdc[i]);
wglMakeCurrent(hdc[i], hrc[i] );
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
GLfloat mat_ambient[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat mat_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glEnable(GL_COLOR_MATERIAL);
glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse );
glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient );
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_SPECULAR,specref);
glMateriali(GL_FRONT, GL_SHININESS, 128);
glFrontFace(GL_CCW);
glEnable(GL_POLYGON_SMOOTH);
glEnable( GL_LIGHTING );
glDepthFunc( GL_LESS );
glDepthRange( -1000, 1000 );
glEnable( GL_DEPTH_TEST );
glShadeModel(GL_SMOOTH);
GLfloat diffuse_light0[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat position_light0[] = { 0.5f, -0.5f, 0.5f, 0.0f };
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse_light0 );
glLightfv( GL_LIGHT0, GL_POSITION, position_light0 );
glEnable(GL_LIGHT0);
GLfloat diffuse_light1[] = { 0.25f, 0.25f, 0.25f, 1.0f };
GLfloat position_light1[] = { 1.3f, -0.5f, 0.2f, 0.0f };
glLightfv( GL_LIGHT1, GL_DIFFUSE, diffuse_light1 );
glLightfv( GL_LIGHT1, GL_POSITION, position_light1 );
glEnable(GL_LIGHT1);
GLfloat ambient_lightModel[] = { 0.75f, 0.75f, 0.75f, 1.0f };
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient_lightModel );
GLfloat spotDir[] = { 0.0f, 0.0f, -1.0f };
GLfloat lightPos[] = { 0.0f, 0.0f, -75.0f, 1.0f };
GLfloat angle = 60.0;
glLightfv(GL_LIGHT4, GL_POSITION, lightPos);
glLightfv(GL_LIGHT4, GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT4, GL_SPOT_EXPONENT, angle);
glLightf(GL_LIGHT4, GL_SPOT_CUTOFF, 60.0);
glPushAttrib(GL_LIGHTING_BIT );
I’ve used array as for some of the variables, since I have a couple of child windows. And I’m using win32API programming, not MFC ot GLUT windows.
The problem is that the Depth Buffer is not working and I can see the objects behind the others!!
For god’s sake, tell me what’s my problem
Thanks alot,
Mehran