Jump to content
  • Advertisement
Sign in to follow this  
azurianarcher

Drawing 2D over 3D

This topic is 4588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!