Z-index 2D bitmaps? (C/C++/allegro)

Started by
2 comments, last by Albrektson 18 years, 4 months ago
Ok, fairly simple question with a complex answer i fear... In Flash/Director/DHTML for instance, one can sort the Z-placement of bitmaps (which one's on top of the other) by a simple number. In C/C++/Allegro however this is done, but handled in a different manor - simply which object is drawn first and so on (right?)... - What would be the simples solution (and I do mean simple as in newbie, preferably a dummy sourcecode) to assign images with a Z-index (or a just a variable called Z-index) to have the draw-sequence checked and corrected every frame? For instance, I want to be able to load a series of bitmaps - let's say a car-game. All bitmaps are pre-rendered .bmp/.jpg/.png files: a groundplane, separated shadows, cars, birds, etc. Now let's say we're seeing this from a top/isometric-view, you might see where I'm going with this. How do I tell the "system" that shadows are supposed to be displayed (drawn) under the car using simple Z-index values for each object or bitmap I draw. - Note that these values have to be variables and update frame by frame in case two layers need to swap z-order. Any means necessary & I intend to draw loads of stuff, so hardware-acceleration would clearly be beneficial if possible! Thanks!
Advertisement
have you thought about including shadows as part of the car images? ;-)
Steven ToveySPUify | Twitter
Hi

you can use the Z-Buffer for this purpose. Simply assign a Z-value to every of your images (I think you draw them as a texture on a quad) and use this Z-value when drawing the quad. Would be very simple with OpenGL and a orthographic projection. The only problem you will see are half-transparent object which you have to draw from back to front with T-Test disabled.

mod42
Well, yeah, I did plan to include the shadows in the car-image, but came to the conclusion that separate shadows would be more space efficient and offer simpler solutions in the end due to the fact that one should be able to "fly off track" - let's say from a highway or an elevated level, where as the shadow should not be visible, and so on. So separate shadows is at least prefered.

Anyways, back to the subject at hand:
Z-buffer you say? Taking this means I would have to give the whole thing a basic 3D-engine approach: using an orthographic camera (looking straight down without any perspecive for instance at quads (basically rectangular planes at different altitude on the Z-axis), textured with the pre-rendered images.

This would indeed give the same visual effect I'm looking for and would most likely be the simplest way of doing it. However, since I have no basic knowledge in how to work with 3D in allegro using Open GL or DirectX, I might need some pointers: a book or at least some tutorials to get me started.

The requirements I have are basically just to position an orthographic camera and how do place and transform (position/move) quads in X, Y and Z. Also I need to be able to get the quads to automatically adjust to the size/proportions of the images being used as textures.
Do note that these images (or textures from now on I guess) are in a PNG-format with a full alpha-channel included to provide transparency - for instance around the car in a texture.

So, where do I start? (tutorials? sample-code I can analyze? any books?)

This topic is closed to new replies.

Advertisement