OpenGL opengl question

This topic is 4254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

when I use the gluPerspective for tarce a sphere and when i extract the image of depth (z buffer) ,i see a value is different of the reality when i trace the sphere,and when i use the glortho i extract the reel value why??? and here is the program in final the use of gluperspective doesn't return the real value of the Z coordinate when i extract the Z from the Z-Buffer void Display() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glColor3f(1.0,1.0,1.0); glLoadIdentity( ); gluLookAt(3,0,0,0.0,0.0,0,0,0,1); // activation of the depth test for eliminate the hidden surface glEnable(GL_DEPTH_TEST); glutWireSphere(1.0,50,25); glFlush(); IplImage *renderinggl=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,1); glReadPixels(0,0,640,480,GL_DEPTH_COMPONENT,GL_FLOAT,renderinggl->imageData); renderinggl->origin=IPL_ORIGIN_BL; double mind1,maxd1; CvPoint locmin; CvPoint locmax; cvMinMaxLoc(renderinggl,&mind1,&maxd1,&locmin,&locmax,0); fprintf(stderr,"Z min : %f,\t Z max : %f\n",mind1,maxd1); cvNamedWindow("depth",1); cvShowImage("depth",renderinggl); } void reshape(int w,int h) { glViewport(0,0,(GLsizei) w,(GLsizei) h); glMatrixMode(GL_PROJECTION ); glLoadIdentity(); //glFrustum(-1.0,1.0,-1.0,1.0,1.5,20.0); //gluPerspective(70,(GLdouble)640/480,1,3);// the of this give the coordinate Z //not the Real glOrtho(-3,3,-3*(GLdouble)480/640,3*(GLdouble)480/640,1,3); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); } int main(int argc ,char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640,480); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); glutDisplayFunc(Dessiner); glutReshapeFunc(reshape); glReadBuffer(GL_FRONT); glutMainLoop (); return 0; }

Share on other sites
once again

Quote:
 Original post by androunwhen I use the gluPerspective for tarce a sphere and when i extract the image of depth (z buffer) ,i see a value is different of the reality when i trace the sphere,and when i use the glortho i extract the reel value why???

i cant make out this sentence...
can you elaborate your question?

i see that you removed your comments, but still you have to write clearer english.
you have many spelling / grammar errors in your question wich makes it really hard to understand.

i really want to help you, but i dont understand what your problem is.

anyway, i will scan your code and see if i can find any errors

EDIT:
Nope, cant seem to find even what you want to do with that code

Share on other sites
when i use the projection "perspective" with gluperspective ,i can't read the real value of the Z-buffer , and when i use the projection "orthographics" with glOrtho
i read the real value of Z-buffer, the question is : why the use of gluperspective doesn't return the real value in the Z-Buffer.
thanks

Share on other sites
glReadPixels with GL_DEPTH_COMPONENT reads the value in the depth buffer, and the value you get IS the real value and it IS correct. You just don't know what the value means. The value in the depth buffer is not the distance from the near clip plane to the object (which I assume you think it is), although it's directly related to it.

In perspective projection, the mapping from distance in eye space to distance in the z-buffer is not linear. Meaning 0.5 is not located halfway between the clip planes. To get the viewpoint distance, do the inverse work of the projection matrix on the depth value.

You can calculate the distance d from the viewpoint as
v = (value in depth buffer)*2-1d = 2*f*n/(-v*f+v*n+f+n)

where n and f are the near and far clip plane values, respecrively.

Share on other sites
thank you very much

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633724
• Total Posts
3013554
×