Avoiding Z Fighting on tile maps

Started by
8 comments, last by kburkhart84 18 years, 8 months ago
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
Parallel RealitiesProject: Starfighter
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.
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
Parallel RealitiesProject: Starfighter
Try having a look at this:

Clicky
No no no no! :)
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.
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.
Parallel RealitiesProject: Starfighter
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.
Parallel RealitiesProject: Starfighter
3D isometric == 2D :) Also in this case zbuffer is not necessary.

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.
No no no no! :)
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.


This topic is closed to new replies.

Advertisement