Remobing Hidden Surfaces

I m using glEnable(GL_DEPTH_TEST) to remove hidden faces and it doesnt work…
If I put it before my glBegin it removes completely some pixels and if I put it after it doesnt remove the right facets…
I tried it with a single triangle and it still bugs !!
Can anyone help me with it?(I can send my code if someone is patient enough);

Are you clearing the depth buffer?

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Usually I enable GL_DEPTH_TEST right after initializing the display.

I don’t quite understand what you mean when you say you tried it with a single triangle and it “still bugs.” Depth test simply ensures that if you draw a triangle that is behind another, it won’t get drawn. You won’t get that with a single triangle.

Perhaps you’re confused about exactly what GL_DEPTH_TEST is supposed to do?

If you can’t get a single triangle to appear on the screen, maybe it is being culled (did you enable GL_CULL_FACE and call glCull…?) or maybe it’s not inside the view volume.

Also, remember to clear your depth buffer when redrawing, so lingering values don’t queer your results.

Perhaps you’re using an incorrect depth function. glDepthFunc(GL_LEQUAL) or glDepthFunc(GL_LESS) are what you’re probably going to want.

Originally posted by Deiussum:
[b]Are you clearing the depth buffer?

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Usually I enable GL_DEPTH_TEST right after initializing the display.

I don’t quite understand what you mean when you say you tried it with a single triangle and it “still bugs.” Depth test simply ensures that if you draw a triangle that is behind another, it won’t get drawn. You won’t get that with a single triangle.

Perhaps you’re confused about exactly what GL_DEPTH_TEST is supposed to do?[/b]

No, when I display a single triangle with GL_DEPTH_TEST Instead of the triangle it displays “a stairs”. And if I display a volume, it displays holes that are discontinuous when I move my object.

I ask again… are you clearing the depth buffer? That’s the only reason I can think of for a triangle to be displayed as “stairs” when depth test is enabled. Is it just when depth test is enabled that it displays like that?

Lets see some code…
And a screenshot of the “stairs”.

Here you are =)I passed through the table creation.

	{
	CPaintDC dc(this); // device context for painting

	// TODO: Add your message handler code here
	HDC hdc = ::GetDC(m_hWnd);
	HGLRC hglrc;


	// TODO: Add your message handler code here
	//glClearColor(0,0,0,0);
	//glColor3f(1, 1, 1);

	if (hglrc = wglCreateContext(hdc))
	{ 
    // try to make it the thread's current rendering context 
		if(wglMakeCurrent(hdc, hglrc))
		{
			initOpengl();
			//glClearColor(0,0,0,0);
			//glColor3f(1, 1, 1);

									if(NombreFacette==3)
		{

		}//switch

				}//for(k=0;k<100;k++)
			}//for(i=0,j=0;i<u;i++)
		if(Mode==0)	glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
		if(Mode==1) 
		{
			glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
		}
		//if(Mode==2) glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
		if(Mode==2) glPolygonMode(GL_FRONT,GL_FILL);
		glColor3d(CouleurIniR,CouleurIniV,CouleurIniB);

		//glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
		//glBegin(GL_TRIANGLES);				

			for(i=0;i<u;i++)
			{//	glBegin(GL_POLYGON);
				glBegin(GL_TRIANGLES);
				if(Couleur==2) 
				{
					if(i==0| |i==1) glColor3f(1,1,0);
					if(i==2| |i==3) glColor3f(0,0,1);
					if(i==4| |i==5) glColor3f(1,0,0);
					if(i==6| |i==7) glColor3f(0,1,0);
				}
				if (Couleur==1)
				{	
					if (atof(s3[atoi(s4[i])-1])<((s3max+2*s3min)/3)) 
					glColor3d(0,(3/(s3max-s3min))*atof(s3[atoi(s4[i])-1])-3*s3min/(s3max-s3min),1);
					if (atof(s3[atoi(s4[i])-1])>((2*s3max+s3min)/3))
					glColor3d(1,(3/(s3min-s3max))*atof(s3[atoi(s4[i])-1])+3*s3max/(s3max-s3min),0);
					else glColor3d((3/(s3min-s3max))*atof(s3[atoi(s4[i])-1])+(2*s3min+s3max)/(s3min-s3max),1,(3/(s3min-s3max))*atof(s3[atoi(s4[i])-1])+(2*s3max-s3min)/(s3max-s3min));
				}
				
				glVertex3d(atof(s1[atoi(s4[i])-1]),atof(s2[atoi(s4[i])-1]),atof(s3[atoi(s4[i])-1]));


				if (Couleur==1)
				{
					if (atof(s3[atoi(s5[i])-1])<((s3max+2*s3min)/3)) 
					glColor3d(0,(3/(s3max-s3min))*atof(s3[atoi(s5[i])-1])-3*s3min/(s3max-s3min),1);
					if (atof(s3[atoi(s5[i])-1])>((2*s3max+s3min)/3))
					glColor3d(1,(3/(s3min-s3max))*atof(s3[atoi(s5[i])-1])+3*s3max/(s3max-s3min),0);
					else glColor3d((3/(s3min-s3max))*atof(s3[atoi(s5[i])-1])+(2*s3min+s3max)/(s3min-s3max),1,(3/(s3min-s3max))*atof(s3[atoi(s5[i])-1])+(2*s3max-s3min)/(s3max-s3min));
				}
				glVertex3d(atof(s1[atoi(s5[i])-1]),atof(s2[atoi(s5[i])-1]),atof(s3[atoi(s5[i])-1]));


				if (Couleur==1)
				{
					if (atof(s3[atoi(s6[i])-1])<((s3max+2*s3min)/3)) 
					glColor3d(0,(3/(s3max-s3min))*atof(s3[atoi(s6[i])-1])-3*s3min/(s3max-s3min),1);
					if (atof(s3[atoi(s6[i])-1])>((2*s3max+s3min)/3))
					glColor3d(1,(3/(s3min-s3max))*atof(s3[atoi(s6[i])-1])+3*s3max/(s3max-s3min),0);
					else glColor3d((3/(s3min-s3max))*atof(s3[atoi(s6[i])-1])+(2*s3min+s3max)/(s3min-s3max),1,(3/(s3min-s3max))*atof(s3[atoi(s6[i])-1])+(2*s3max-s3min)/(s3max-s3min));
				}
				glVertex3d(atof(s1[atoi(s6[i])-1]),atof(s2[atoi(s6[i])-1]),atof(s3[atoi(s6[i])-1]));
				glEnd();
			}




	glDepthFunc(GL_LESS);

		SwapBuffers(hdc);
 
	}//if(NombreFacette==3)

}	

}

wglMakeCurrent(NULL, NULL) ; 
::ReleaseDC (m_hWnd, hdc) ; 
wglDeleteContext(hglrc); 



}
void COpenGL::initOpengl()

{ glClearDepth(1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(anglepersp,1,0.00000001,1000);
gluLookAt(axex,axey,axez,objx,objy,objz,0,1,0);
//glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluPerspective(anglepersp,1,0.00000001,1000);

Here’s your problem. With that near:far ratio, you are more or less making the depth buffer useless.

The near:far ratio is calculated as far/near, where near and far are the last two values in the call to gluPerspective. For good depth buffer precision, the ratio should not exceed 10000 for 24-bit depth buffer, and 1000 for 16 bit ones. Your ratio is WAY too large.

Set the near clip plane to 1 or 0.1 instead.

It worked=)
Thank you very much