How do I do 2D opengl? I need to be able to put stuff up on the screen so that it is not rendered in three dimensions, and I need the 3d stuff to still be 3d behind it.

Recommended Answers

All 8 Replies

Ok, I like the idea of just drawing stuff with minimal z order. Thanks!

within the main display loop you can simply change the projection to orthographic. A tidy way is to input a class that has the code neccessary code to generate the 2D projection matrix and neccessary screen co-ordinates. you can then write the commands to draw the objects in this class. In the main loop you then just call this function (it should only take a few lines in the main display keeping it tidy).

The projection can swap from a 2D to 3D projection mode without any noticable artifacts or problems. This works well for interfaces, buttons, heads up displays etc.

But when I swap wont I lose all of my 3D stuff?

Actually, you should just render it as though it's 3D, just keep the z plane constant.

In OpenGL, there really is no difference between 2D and 3D, all the mathematics are the same :)

If you're attempting to render the UI, there are two ways, one is to switch the context as mentioned above and the other is to use render textures on the status z plane in 3D mode.

you dont lose your 3D by changing projection type just make sure you do it before the frame switchs (it just goes next to your 3D code). You can also just texture or draw flat in 3D as other people have said. I personally just prefer to change to 2D to help keep everything seperate and prevent errors or problems when drawing multiple 3D objects and avoiding potential issues such as hidden surface removal. Realistically i don't think these problems arise much so just so which one you feel most comfortable with to start with and once happy try the other method.

In the interests of performance, also make sure you only do context changes *once* per frame.

Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.