Adding depth buffer to max2d stuff

BlitzMax Forums/BlitzMax Module Tweaks/Adding depth buffer to max2d stuff

Shagwana(Posted 2005) [#1]
Right, hears an idea;

Imagine if the max2d (opengl & directx) had access to the depth buffer (ie instead of just drawimage image,x,y placement, there would be drawimage image,x,y,[z])

One of the many effects this could be used for is to auto clip the images being drawn to the screen. For example; Instead of the need to draw everything in order (back of screen to the front of the screen) the programmer could decide what to draw and when - so it could be possible to place an image in between two already draw images.

As i know very little about the internal setup of direct x and opengl max2d mods, would this be a lot of work to pull off?.

For the opengl side of things, i figure i would have to;

1. Ensure that the depth buffer is enabled when the screen is created.

2. Convert image drawing calls to glTexCoord2f into glTexCoord3f (using a set z value)

3. Provide the user with some control over how the depth buffer is used. (for example, always draw, when z is equal or less, when z is less ... etc ...)

Now my question, as im not as clued up on OOP as i should be;

Now when it comes to doing this, would it be best to create a new mod for max, calling it "Max2.5d" or somehow extend the current set of commands to do it?.

Another thing, how on earth would i pull this off with directx!?.


Grisu(Posted 2005) [#2]
Depth buffer = Max3D? :)


Shagwana(Posted 2005) [#3]
Not for what i have planned.

Depth buffer (or as some call it the z-buffer) has existed for ages. All it does is store the depth (into the screen) of each pixel on the screen.

When a pixel is drawn to the screen, its checked against the depth buffer (for that pixels location). If the pixel is closer (on top) to the camera then whats already there, then its drawn to the screen and alters the depth buffer. If whats already on the screen is closer, then nothing gets drawn.

All i wish to be able to do is add a z option to all the draw commands - so i can set an image to the correct depth!


The main reason for me doing this, is because its <should> be faster on older hardware then using the stencil buffer.


Dreamora(Posted 2005) [#4]
ZBuffer is very old, but volume textures aren't ... don't think they are even supported in DX7 nor OpenGL 1.2 which is what Max2D is


skidracer(Posted 2005) [#5]
Pixels that fail the ztest may very well be faster but I would assume ztesting itself will have it's own penalty on older hardware.


Shagwana(Posted 2005) [#6]
ZBuffer is very old, but volume textures aren't ... don't think they are even supported in DX7 nor OpenGL 1.2 which is what Max2D is

Its not volume textures im thinking about, its more like textured quads in 3d space without perspective. Depth is not defined for each pixel, but for the whole quad texture (image).


AntonyWells(Posted 2005) [#7]
2. Convert image drawing calls to glTexCoord2f into glTexCoord3f (using a set z value)


That would only set the Texture W Coord to your z value.

You'd have to change glVertex2f X,Y to glVertex3f x,y,Z;

And use glClear( GL_DEPTH_BUFFER_BIT) tp clear it when cls'ing.

also, glEnable(GL_Depth_Buffer) to turn it on.

You may need to set the depth func, not sure if it's on by default. glDepthFunc GL_LEQUAL etc.


Shagwana(Posted 2005) [#8]
Yes, i was thinking some effects could be pulled off with the "glDepthFunc" command - like auto clipping, when on the same depth (GL_LESS). Now this would be of great use to me as im using the stencil to do the same sort of results at i imagine a slower speed.


DocFritz(Posted 2005) [#9]
I think "Max2.5d" would be a great Idea, and if it's possible it should be implemented. Of course optional, if you don't need the Depth-Buffer, it shouldn't be activated.


Shagwana(Posted 2005) [#10]
Right, done some testing on this and I have manage to 'hack' it into opengl max2d driver. Tests indicate that on my old hardware (tnt1 p3-500) that there is very little slow down in its use - compared to stencil bueffers!.

Now, anyone got any idea on how to do this sort of thing in direct-x?


DocFritz(Posted 2005) [#11]
Great, when will be the "release" of your Module-Tweak? ^^
Concerning DirectX... erm... no idea. Anyone?


Sonic(Posted 2005) [#12]
I just created a type called 'graphicscue' which contains a list of 'graphics' (type with x,y,image etc) then I over-rode Object.Compare() for the 'graphics' type so I could Sort according to the Y position. All images have thier handle set to the bottom so they will be drawn in order. Simple but works fine (for my point'n'click, Monkey Island style pseudo 3d). Don't know if that helps!


TartanTangerine (was Indiepath)(Posted 2005) [#13]
This is already in BMAX, you just need to change the modules that handle drawing to pass a z-coordinate. At the moment they pass z as 0.

Have a look at my module tweak for Textured Polys : http://www.blitzbasic.com/Community/posts.php?topic=51059

Here I pass an array xyuv[], just change it to pass xyzuv[], pass the relevant data and voila.