Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Multiple matrix mode switches

This topic is 4883 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

Hi all! I've packed my text rendering classes into a static library (TEXTLIB) and my GUI classes into another (GUILIB). So, it's natural that GUILIB uses TEXTLIB to render text. Both TEXTLIB and GUILIB use orthogonal projection to do their drawing through the use of some functions I've implemented ("Enable2D()" before drawing and "Disable2D()" after drawing). The problem: Supposing some GUI window contains twenty text labels, the final drawing function should be something like this:
void CGUI::draw() {
    label1.draw();  // Calls "Enable2D()" and "Disable2D()"
    label2.draw();  // Calls "Enable2D()" and "Disable2D()"
    label20.draw(); // Calls "Enable2D()" and "Disable2D()"

All those calls to "Enable2D()" and "Disable2D()" makes the code inneficient (not to say idiot). How can I design my libraries so that TEXTLIB still works as a standalone library, yet removing the extra matrix mode switches overhead when using together with another library like GUILIB? Something that comes in mind is to add an extra function to the text classes for use in 2D mode only ("draw2D()"). Please, help me! Thanks in advance! Using: WindowsXP, Visual C++ 6.0, SDL, OpenGL

Share this post

Link to post
Share on other sites
Allow your draw functions to access the current 2d-enabled state: either by a global or a FLag passed to the draw function.

if ( bIs2dEnabled) etc.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!