PDA

View Full Version : Z-buffer, glOrtho, clipping, left-handed and right-handed. Question.



Teeth
01-21-2005, 05:06 AM
Hello everybody,

I've been having a little trouble here. I'm writing an isometric tile engine such that I can write out complete depth information for world geometry from the data before I render out the graphics. In order to do this, I'm storing mask polygons that I draw to the depth buffer as a first pass. Spent days thinking abot it and it's definitely the way I want to proceed.

I'm setting up the display using glOrtho, and this is where the problems begin. Well... to be more accurate, perhaps the problems begin with the way I'm rendering my polygons. When the time comes to render my data, I calculate the screen coordinates of the tile mask tris by hand, including the Z coordinate, which I organise to comply with my near and far planes (set at 0.1f and 1000.0f respectively, though any value for the far plane yields the below results).

The problem I'm having is that whatever I'm drawing gets clipped outside my near and far values (i.e. doesn't appear) unless I set the near and far planes in glOrtho to be negative. Took me a while to figure that one out.

I was reading some OpenGL docs and it said that OpenGL likes to be in a left-handed coordinate system before perspective calculations and right-handed after. This means, apparently, that it calculates Z and W values with a negative in the equation. Thing is, let's say I want to draw something over the mask - I might offset it slightly towards the camera. Since I'm sending all my data over to the display with 0.1 smaller than z smaller than 1000.0, I reasoned that I could just subtract a set value from the calculated Z value, and I'd be fine. If I do that, though, whatever I do gets rendered behind the mask regardless of the depth test function I use. I figure that's pretty strange; surely if you've got stuff appearing behind something and you reverse the depth function they should appear?

Anyway the main thing I suppose is that I really need the z buffer to match the z data I'm sending out or my life will be uncomfortable from here on in. Any tips? (like "Use matrices you plonker, even for ortho it's the best thing to do")