gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Is there Z-testing when using glOrtho?

#111010 - simonjhall - Sun Dec 03, 2006 4:51 pm

I don't want to have any perspective correction or anything when rendering my graphics so I've been using
Code:
glOrtho(-6, 5, 3.5f, -4.5, 1.0f, 0x7fff);

to get my stuff on the screen. It's all fitting on the screen just fine but there's *nothing* that I can do to get Z-testing to work.

If I just draw two triangles and play with the z co-ords of the vertices the triangle which is drawn last is always drawn on top. This goes for any value of z-near and z-far. In fact if I change the z of the vertices to be behind the camera they'll still be drawn!

If I replace the ortho call with
Code:
gluPerspective(35, 256.0 / 192.0, 1.0f, 0x7fff);

everything looks perfectly fine and triangles come out in the proper depth order. The perspective projection makes stuff look slightly wrong though.

Am I missing something here?
_________________
Big thanks to everyone who donated for Quake2

#111013 - Sunray - Sun Dec 03, 2006 5:36 pm

Take a look at SWAP_BUFFERS here http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol
Then look at glFlush() in videoGL.inl (or something) and you will notice that libnds doesn't do what you want to do. GLX_FLUSH = 0; will probably work better.

#111045 - simonjhall - Sun Dec 03, 2006 8:32 pm

Right, I tried all sorts of things using that flush command (and the docs on the site) but whatever I tried still gave me the same whack results. In the end I'm using a perspective projection, but with a really small FOV in order to minimise the errors.

I'll eventually build my own orthographic matrix, but this'll do for now...
_________________
Big thanks to everyone who donated for Quake2

#111060 - Sunray - Sun Dec 03, 2006 9:36 pm

Strange. My platform game (with mixed 2D/3D kinda like NSMB) uses orthographic projection and it works perfectly.

#111078 - Goosey - Sun Dec 03, 2006 11:36 pm

I was able to get this working by replacing my glFlush with the GFX_FLUSH = 0;... but there was one tricky part. My glOrthof32 command uses a zNear of 0 and a zFar of -1000, but when constructing polygons I use 0 for near and 1000 for farthest. Not sure where the sign is getting flipped (perhaps I should set a camera?) but it works so I am forging ahead. :)

#111168 - silent_code - Mon Dec 04, 2006 5:11 pm

usually i wouldn't reccomend using 0 for near clipping, but 1, as well as a positive far clipping value. though i haven't tried ortho on the nds myself (only using perspective atm).

#111307 - Rajveer - Tue Dec 05, 2006 4:52 pm

EDIT: sorry I didnt read above. Using GFX_FLUSH = 0; worked for me too. For the far and near clip planes, using
Code:
glOrthof32(0, 256, 0, 192, 0.1, 1000);
works for me (without setting the camera position), after which I can draw a full screen quad with
Code:

   glVertex3v16(0, 0, -1);
   glVertex3v16(0, 192, -1);
   glVertex3v16(256, 192, -1);
   glVertex3v16(256, 0, -1);


Changing the z-coordinate changes its "layer", so drawing something with -2 will mean its drawn behind what I showed.

Sorry if you knew this/already tried it :)

#111314 - simonjhall - Tue Dec 05, 2006 5:30 pm

I'm gonna check this stuff out proper-like once my kits gets flashed again as there must have been something obvious that I missed out.
OR the lack of z-buffer was a hint than my DS was about to die :-)
_________________
Big thanks to everyone who donated for Quake2