Jump to content
  • Advertisement
Sign in to follow this  
androun

OpenGL opengl question

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
once again

Quote:
Original post by androun
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???


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 this post


Link to post
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 this post


Link to post
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-1
d = 2*f*n/(-v*f+v*n+f+n)

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!