Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Object behind another object


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 QIZI94   Members   -  Reputation: 116

Like
0Likes
Like

Posted 16 February 2013 - 08:51 AM

Hello,
I am creating a OpenGL scene and i have problem when two 3d object are on one X, Y position and have different Z positions, because the display order are not controling by the Z position, but the display order in script.
 
I am using C++ and Windows WINAPI.
 
On google i find some solution for glut or linux devices using glEnable(GL_DEPTH_TEST) and glDepthFunc(GL_LEQUAL), but that is not good solution for WINAPI becouse screen start blinking and objects was damaged.
 
Can someone help me ?


Sponsor:

#2 akciom   Members   -  Reputation: 109

Like
0Likes
Like

Posted 16 February 2013 - 09:44 AM

Your objects, while defined in a 3D space, are still being drawn on a 2D display. So what happens is OpenGL draws the first object it comes across (first in your script) and then draws the second object it comes across (second in your script). I believe GL_DEPTH_TEST is supposed to check where in the 3D world the object is so when it renders the object, it knows what order to do it in. You could do this yourself by simply testing which object is further from the camera and render it first, find the next closest object and render that next, and so on until they're all rendered. I wouldn't recommend it though because as your scene gets more complicated, you'll just run into more issues. But that's what OpenGL is for.

 

Your problem is likely you haven't enabled a depth buffer for your rendering context. Something like this (from http://nehe.gamedev.net/tutorial/creating_an_opengl_window_%28win32%29/13001/):

 

glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

 

If you're having any more issues, posting your code will help.


Edited by akciom, 16 February 2013 - 09:45 AM.


#3 QIZI94   Members   -  Reputation: 116

Like
0Likes
Like

Posted 16 February 2013 - 12:16 PM

Yes I know, I wrote that I tryed glEnable (GL_DEPTH_TEST) and glDepthFunc (GL_LEQUAL) (and I uses glClearDepth(1.0f) and glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)). 
 
I cannot post my code, because is more complex and is always in classes, structures and unions. I can only better explain my problem and post all glEnables and some stuff from my scripts.
 
Ok, where I can  begin..... I have scene/game, who is about Solar System, I am using primitive object sphere and i have 3 object Universe(rotating background), Sun and one planet.
Camera is look on sun and planet is behind sun, but what i see with camera is this(without Depht test): 
 

8Cmdv.jpg

 

 

And when I enable:

glClearDepth(1.0f)

glEnable(GL_DEPTH_TEST)

glDepthFunc(GL_LEQUAL)

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

 

and in loop i have: glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

I see this:
 

tMV86.jpg


Edited by QIZI94, 16 February 2013 - 12:17 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS