drawing in 2d & 3d

Can anyone explain how you draw in 2d and 3d in the same scene (eg for the hud). I understand the Ortho2D feature but this is in my resize function and not in my code. Would I call 2d in resize as well as before I draw the hud and then change to 3d to draw the scene?


If you’re not changing viewing projection mid-frame, keeping the projection code in the resize function is all you need.

If you want to change your projection multiple times while drawing, just place the relevant code in your display function, something like:


[code to draw 3D scene]

[code to draw HUD]

There’s nothing magical about the code in your resize function as opposed to your display function, it just gets called in different situations.

I’m not really sure why you would want to switch back and forth like that every frame like that. Why not just draw your 2D stuff flat in front of the 3D stuff. And really, for HUD you might want a flat object that sits within the 3D environment. It just seems like it wouldn’t be worth much to switch projection modes every frame, but what do I know?

Well, it’s debatable. My usual advice is to implement the simplest system first, and tighten things up later if there are performance problems.

I expect CharlieBob will find it a lot easier just to switch projections rather than calculate a screen-filling, camera-oriented plane to draw the HUD to. But if it turns out that the projection switching has a detrimental effect on his code, your solution is definitely the way to go!