Skip to main content
GameDev.net gamedev.net
🔒 Locked

2d with 3d?

Started by Slug Nov 15, 2004 at 1:15 PM 8 replies 600+ views
Original Post
Slug
Slug
How can i mix 2d image with 3d, for example, drawing a backgroung, using font, and drawing my 3d scene at the same time? I'm able to do only one of the two...
Slug
Slug
did i have to play with ortho and projction mode?
Tim Cowley
Tim Cowley
Draw your 3d stuff, then switch to ortho and draw your 2d stuff [grin]
INVERSED
INVERSED
That's what I do, I set a perspective matrix as the projection, and then, during my 2D draw step, I push a matrix, load identity, then set ortho matrix, draw your sprites on textured quads, pop projection matrix.
Write more poetry.http://www.Me-Zine.org
Slug
Slug
Any sample code, pleeeeeeeeeease...
INVERSED
INVERSED
You're going to have to double check this cuz it's off the top of my hed

Set Projection:

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( ... );
glMatrixMode( GL_MODELVIEW );


... Draw 3D


glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
gluOrtho2D( ... );
glMatrixMode( GL_MODELVIEW );


... Draw 2D

glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
Write more poetry.http://www.Me-Zine.org
Solias
Solias
You are probably also going to want to trun of lighting. And you'll need to be careful about the depth buffer. You may want to clear it or turn it off when drawing the 2d stuff in front of the 3d, or just make sure your 2d stuff has z values that are not in the range of your 3d stuff.
Schematic
Schematic
I haven't done any speed tests, but what kind of load does switching produce? I'd rather have a check at the start of any 2d routine to switch into ortho as needed, and something similar for 3d/perspective. This would give me the freedom to let it switch at will (and not require streamlining until I'm working on something that needs it).

I've been doing something similar, but trying damned hard not to switch modes more than I have to (typically, draw 3d, then switch to ortho and save all 2d for the end). It's not that incredible a hassle, but so far I haven't noticed a difference between keeping it streamlined and switching it out 100 times a frame.

zedzeek
zedzeek
>>I haven't done any speed tests, but what kind of load does switching produce? <<

very little (1000x a frame shouldnt really matter that much, though it does sort of seem like bad design if youre doing it that way), though of course its just like anything else, try to minimize it as much as possible
Slug
Slug
God bless you INVERTED !!! you solve all my problem
and all this sh*t is clear in my head now.(and alse thanx to the other...)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.