PDA

View Full Version : Overlaying



danbaron
10-05-2010, 07:49
[font=courier new]I didn't even know what TBGL meant until very recently. Suddenly, a light bulb turned on.

I just looked at it tonight.

I have a question about the following script, made by Mike Hart -

c:\thinbasic\samplescripts\tbgl\basic\tbgl_2d_primitives.tbasic.

Why does the bouncing blue ball go in front of the square of points, but behind the lines?

From the code, it looks like during each rendering, the ball is drawn after both the points and the lines.

Intuitively, it seems to me, that the last thing drawn should appear on top.

Dan :x :oops: :P

Petr Schreiber
10-05-2010, 08:16
Good question!,

well, the reason why it is drawn below the rest consists in fact the depth testing is enabled by default, with setting GL_LESS, which means "New fragment(pixel) passes if the incoming depth value is less than the stored depth value.".

Here we are drawing anything in one plane, so the incoming pixels of the circle are at the same level like the rest, so they do not overwrite it.
This setting might sound illogical, but when doing 3D renderings, it reduces negative effect called "Z-fighting", which occurs thanks to some numerical inprecision.

Ok, enough about the behind the curtains, we want it just to work as expected in 2D, allright?
Then there is nothing more simple, than disable depth testing, when we draw 2D images in the way painter would do it.

To do so, just intuitively add the following after "TBGL_ShowWindow":


tbgl_UseDepth(%FALSE)


With this setting, fragment(pixel) writes won't be affected by any depth equations, and will work as expected.


Petr

danbaron
10-05-2010, 08:26
[font=courier new]Thanks Petr.

I was thinking about, for instance, a chess board.

When someone moves a piece, most likely they would prefer if they can see it, and don't need to look underneath.

(Now, I tried what you said, and, believe it or not, it worked!)

:oops:
Dan :x :P

Petr Schreiber
10-05-2010, 08:31
Hehe,

of course, it will be perfectly possible to draw it right with depth disabled.
On the other side, rendering pieces below the board could be good memory practice...


Petr