Design Question: How to handle rendering order?

I’m still getting my bearings in OpenGL, I’ve played around a lot with rendering using display lists, vertex arrays, and VBOs. I ran into a design problem adding 2D text labels to my app, because I realized constantly calling glOrtho2D for every string of text to render every frame was inefficient. So I implemented a queue, where everytime I wanted to render some text, it’d get added to the queue, and then in my main render loop it would render all the 3D stuff, do one glOrtho2D, then render all the 2D stuff like text.

Now I’m having trouble because I’m wondering if I should be doing extra design work to make it so that say, all objects drawn with VBOs should be bunched together because they use a lot of the same client states. Or if I should try to draw all textured objects together to avoid redundant glEnable(GL_TEXTURE_2D) calls, etc.

How do opengl coders usually organize the main rendering loop?

texture/shader changes generally hit the hardest, followed by various render state, but it always depends on the myriad details, therefore there are no hard a fast rules, only guidelines. the ihv websites have ample documentation in this area (it’s not a secret or anything).

btw, you might want to have a gander at ARB_window_pos