Jump to content
  • Advertisement
Sign in to follow this  
Scarfy

OpenGL Avoiding Z Fighting on tile maps

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

My new projects going well, but I've got a small problem (this is more theory than code). I have a large OpenGL tile map built from quads. This all works fine, but I also wish to place another quad on the scene to show the position of mouse. All the quads are drawn at a Z depth of 0. Right now I have the additional "targetter" quad being drawn at 0.1 (so, just above the main land). What I want to know is what is the best way of doing this. Whilst putting the "targetter" quad just above the others solves the issue I don't believe it's the best approach. Maybe it's something trivial that I've just not though of. Any ideas? Thanks, Steve

Share this post


Link to post
Share on other sites
Advertisement
You have different solutions.
If you are sure that your new quad is the 'topmost' you can disable DEPTH_TEST and draw without any Z-fighting.

Share this post


Link to post
Share on other sites
Hmmm, I gave that a go once. The results were a little unexpected but I'll keep playing around with it and see what happens.

Ta

Share this post


Link to post
Share on other sites
Quote:
Original post by Scarfy
Hmmm, I gave that a go once. The results were a little unexpected but I'll keep playing around with it and see what happens.

Ta


Probably I've misunderstood your problem but It sounds like a 2D ortho view with tiles mapped onto the screen, right?
In this situation you have no need of Z-buffer because you can sort your quads before rendering and simply glDisable(GL_DEPTH_TEST).
Note that the 'manual' z-sorting is needed in 3D too for example when you have to draw transparent polygon.

Share this post


Link to post
Share on other sites
Quote:
Original post by MichaelT
Try having a look at this:

Clicky


Hmmmm, looks like a DirectX solution. I'm using OpenGL and SDL for portability so I'm not sure it's any use to me. Thanks for the pointer though.

Share this post


Link to post
Share on other sites
Quote:
Original post by blizzard999
Quote:
Original post by Scarfy
Hmmm, I gave that a go once. The results were a little unexpected but I'll keep playing around with it and see what happens.

Ta


Probably I've misunderstood your problem but It sounds like a 2D ortho view with tiles mapped onto the screen, right?
In this situation you have no need of Z-buffer because you can sort your quads before rendering and simply glDisable(GL_DEPTH_TEST).
Note that the 'manual' z-sorting is needed in 3D too for example when you have to draw transparent polygon.


Nah... it's a 3D isometric game. Think UFO (X-COM) with squares that units stand in and a target square that you can move along the land using the mouse.

Share this post


Link to post
Share on other sites
Quote:
Original post by Scarfy
Hmmmm, looks like a DirectX solution. I'm using OpenGL and SDL for portability so I'm not sure it's any use to me. Thanks for the pointer though.


Yeah I know, but I don't have a OGL solution at hand. I belive something similar should be possible in OGL, so I hope it is of some help anyway.

Share this post


Link to post
Share on other sites
If you just turn off the zbuffer, you can draw that quad last, and no matter what, it will be in view. For this type of game, I assume the mouse pointer will always be in view right?? As in, nothing will block it ever. Do This.

//Draw_Everything_Else();
glDisable(GL_DEPTH_TEST);
//Draw_MousePointerQuad();
glEnable(GL_DEPTH_TEST);

Since you turn off the depth test, OpenGL assumes you have drawn in the correct order, back to front, so the last thing you draw will always be in front. So if you make that last thing the quad for your mouse pointer, you will always see it.

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!