Drawing 2D over 3D

Started by
9 comments, last by azurianarcher 18 years, 4 months ago
Iv been struggling with this for a while, and its really frustrating. All i need to do is draw a two dimensional bitmap over a 3D scene ov already rendered. this is not a texture, im actually trying to make a custom mouse head for my application. Maybe im going about this wrong, if anyone has a better suggestion id love to hear it. thanks, Max
Advertisement
OpenGL has an Orthographic projection mode that's easy to use, I'd bet money that DirectX has one as well. Anything else should be fine as well.
I figured someone would say this. The only problem with ortho is that i need to draw it over a 3D scene. In theory i could do all my rendering in perspective and then switch to ortho and texture map a quad with the bitmap i want, but in practice its not working out so well
Yeah, thats what you would have to do, switch over to the orthographic matrix mode, and just make a textured quad. If your having troubles, maybe post some code and a description of the problem.
Im going to try that again, but i im wondering, wont there be problems with the bitmap being hidden behind other objects which are infront of it, even if i draw in ortho mode
In OpenGL, you would call glDisable(GL_DEPTH_TEST). This turns off both writing to the depth buffer, and depth testing itself. Direct3D definitly has an equivelant.
So to review everything, my algorithm should look like this

draw 3D scene
swtich to orthorgraphic mode
disable the depth test
draw bitmap on a textured quad
switch back to perspective
Alternatively, if you don't have any transparent 2d elements you could draw the 2D part last and just clear the z-buffer before that. Prevents all the overdraw if you want many big and overlapping windows or stuff.
f@dzhttp://festini.device-zero.de
Another real dodgy way of doing it that doesnt involve switching projection modes is to find the up and right vectors from your cameras matrix.
This can be done like this
float mat[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mat);

// get the right and up vectors
cVector right(mat[0], mat[4], mat[8]);
cVector up(mat[1], mat[5], mat[9]);

This is openGL, you can do the same with direct 3d, but the location of the vector info in the matrix might be different.
Don't forget to re-enable the depth buffer before you start drawing the scene again.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement