Jump to content
  • Advertisement
Sign in to follow this  
timgradwell

"Local" depth testing

This topic is 4467 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

Hello, I'm trying to write a 3d editor (as an exercise as much as for the use it will be to me). I'm curently rendering a grid in the world. I'd like the gridlines to get progressively lighter as they become more spaced apart (ala unrealed). I've achieved this by drawing the grid as dark grey at unit 1 width, lighter at unit width 2, lighter at unit width 4 and white at unit width 8, with the following code:
float step = 1.0f;
float color = 0.2f;

for (int i = 0; i < 4; i++)
{
   render(step, color);
   step*=2f;
   color+=0.2f;
}


This only works if I switch off depth testing. (If depth testing is on, only the darkest grid lines are visible).
glPushAttrib(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
   renderGrid();
glPopAttrib();


But, when I draw, say, a triangle in the world, even if depth testing is on when I draw the triangle, the depth testing doesn't work between the triangle and the grid. I just get whichever was drawn last on top. Is there a way of drawing the grid so that it doesn't depth test against itself (each progressive layer of the grid) but still depth tests against the rest of the world. Cheers, Tim

Share this post


Link to post
Share on other sites
Advertisement
Thanks Faron.

This works, as long as I render the triangle first, then the grid. Which is doable. I'm now just wondering why they need to be rendered in that order...

Tim

Share this post


Link to post
Share on other sites
Quote:
Original post by timgradwell
Thanks Faron.

This works, as long as I render the triangle first, then the grid. Which is doable. I'm now just wondering why they need to be rendered in that order...

Tim


I knew something was bugging me about rendering in a specific order...

I have 3 "flat" views (top, front and side) and 1 "free" view (typical of 3d editors).

In the 3 flat views, I want to draw everything on top of the grid.

Which means no depth testing, draw grid first, then draw rest of world objects.

But to enable the depth testing (with the depth mask set to false) for the free view grid, the grid has to be drawn second.

Which means I end up with ugly code that says

"if flat view, draw grid, then world, else draw world, then grid".

Tim

[Edited by - timgradwell on July 29, 2006 10:48:16 AM]

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!