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 > Disable depth testing

#114668 - Vich - Tue Jan 09, 2007 11:33 pm

After searching the forum, I can't seem to find a way to disable depth testing on the DS.
I expected something like glEnable(GL_DEPTH_TEST), but GL_DEPTH_TEST isn't defined.

The idea is to be able to draw multiple quads over each other. Each new quad that gets drawn should be visibly put over the previously drawn one. My program now randomly sorts them and I think this is because depth testing is on and they are all drawing at a Z value of 0.
I'm not planning to create separate Z values for each quad though, since that would be a dirty hack :P

#114673 - simonjhall - Wed Jan 10, 2007 12:01 am

The docs on nocash seem to imply that you can't disable depth testing. You can change depth testing function from 'less' to 'equal' but it doesn't look like there's an 'always' option.

Maybe you can clear the depth buffer mid-frame, then render what you like.

Alternatively, you could just use a really close Z for the 'on top' stuff!
I'd also like an answer to this problem, to ensure that my menus are always drawn on top. Let me know if you find a good way of doing it :-)
_________________
Big thanks to everyone who donated for Quake2

#114686 - Vich - Wed Jan 10, 2007 1:51 am

simonjhall wrote:
The docs on nocash seem to imply that you can't disable depth testing. You can change depth testing function from 'less' to 'equal' but it doesn't look like there's an 'always' option.

That's what I understood too... but I hope there's still a way.

Quote:
Maybe you can clear the depth buffer mid-frame, then render what you like.

Alternatively, you could just use a really close Z for the 'on top' stuff!
I'd also like an answer to this problem, to ensure that my menus are always drawn on top. Let me know if you find a good way of doing it :-)


The problem isn't the sorting from the 2D overlay with the 3D stuff behind, but the problem is the sorting of the 2D objects themselves. If I move them around(it's a GUI, so I can drag and drop windows and their child surfaces) then the surfaces seem to have a random order. That's what I'm trying to fix. I would like them drawn in the order that I'm creating the polygons.

#114688 - Lick - Wed Jan 10, 2007 2:15 am

(Worst case scenario:) Could you not create a function like:

Code:

static fixedpoint depth = fixedpoint.fromfloat(-1.0f);


static inline void glVertex2f(fixedpoint x, fixedpoint y)
{
  glVertex3f(x, y, depth);

  depth++; // increase fixedpoint
}


static inline void glFlushOrtho()
{
  depth = fixedpoint.fromfloat(-1.0f);
}


This will automatically build up from behind.
_________________
http://licklick.wordpress.com

#114713 - Vich - Wed Jan 10, 2007 10:27 am

Lick wrote:
(Worst case scenario:) Could you not create a function like:

Code:

static fixedpoint depth = fixedpoint.fromfloat(-1.0f);


static inline void glVertex2f(fixedpoint x, fixedpoint y)
{
  glVertex3f(x, y, depth);

  depth++; // increase fixedpoint
}


static inline void glFlushOrtho()
{
  depth = fixedpoint.fromfloat(-1.0f);
}


This will automatically build up from behind.


That's what I had in mind more or less, but I think it's kind of a hack that I'd rather avoid(I try to avoid any kind of hacking... which is a challenge with homebrewn software :P).
But I'll definitely keep it in mind as I'm confident that this can fix the problem.

#114868 - crossraleigh - Thu Jan 11, 2007 5:19 am

Draw walls. Set Bit 14. Draw lightmaps. Clear Bit 14. AFAIK, you have to tessellate the walls down to the size of the lightmaps to get this technique to work.

#115680 - Lick - Thu Jan 18, 2007 11:25 am

Going back through the topics, I saw dovoto post that it isn't that the hardware is surely lacking this feature (perhaps it is), but he hasn't found the register+bit to enable/disable depth testing.

I think it should be this feature, according to gbatek:
Quote:
-- Depth Test (aka DepthFunc in OpenGL) --
The Depth Test compares the depth of the pixels of the polygon with the depth of previously rendered polygons (or of the rear plane if there have been none rendered yet). The new pixels are drawn if the new depth is Less (closer to the camera), or if it is Equal, as selected by POLYGON_ATTR.Bit14. The latter comparision mode draws pixels only on exact matches, so the results may be unpredictable due to rounding errors; one situation that does work stable is if both polygons use the same vertices, eg. it can be used to put a grafitti texture (consisting of solid and transparent pixels) onto a wall.


So try keeping the Z the same and enable Bit14, it just might work!
- Lick

[edit] Err.. Like crossraleigh said.
_________________
http://licklick.wordpress.com

#115693 - silent_code - Thu Jan 18, 2007 12:51 pm

i didn't read the whole thread, so someone else might have written that before: some old id software engine (i think it's quake) used alternating depth functions to work around depth buffer clearing. i don't know if this method is only present in the opengl port. well, the use of alternating depth values makes sure the whole depth buffer content is "overwritable", that means all new values will pass the test against old values. i think the whole trick also needs two different view frustrums, but i'm not sure.

now, that the nds hasn't a full depth buffer, but sort of a line buffer, it might not be applicable. but it could be used to create sort of two differnet layers with anything drawn to the front layer being allways infront of the back layer.

btw, the depth function doesn't enable or disable depth testing. it just says "a pixel passes the test if its depth value is less/greater/equal to the value allready in the depth buffer".

hope that helps.

#116736 - Vich - Mon Jan 29, 2007 12:24 am

The above suggestions didn't work.
I tried to:
- clear bit14
- draw with increasing the Z value every drawn quad

I found this somewhere else on the forum:
"The higher (Y axis) of two polygons gets drawn on top, instead of the proper Z axis. "
And that's exactly the behavior I get ._.
It probably has to do with the linebuffer in the DS?
Any more suggestions? I'm losing my hope to fix this.
_________________
[project website] [personal website]