Jump to content
  • Advertisement
Sign in to follow this  
tobinare

OpenGL working with two glOrtho projections

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

Hello, I am using OpenGL to write a charting application. I am using multiple viewports, one to display the charting and others to display the axis etc. The viewports are updated each time the window is resized. I apply two separate projection to each viewport using glOrtho to... 1.) Render the objects. 2.) Apply some labeling with my texture fonts. Now I have written some code which works fine but I was wondering if there is a more efficient way of doing what I want that someone could recommend. The number of calls to glOrtho has me concerned. I played around with glPushMatrix and glPopMatrix but could not get things to work. Any help would be appreciated
///////////////////////////////////////////////////////////////
// original this function was all I needed with one projection
void CChart::SetOrtho()
{
   int cx = m_Rect.right - m_Rect.left;
   int cy = m_Rect.bottom - m_Rect.top;

   if ( 0 >= cx || 0 >= cy )
      return;

   ////////////////////////////////////////////////////////////////	
   glViewport( VIEWPORTY[0],VIEWPORTY[1],VIEWPORTY[2],VIEWPORTY[3]);
   ////////////////////////////////////////////////////////////////
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(xMin, xMax, yMin, yMax, -1, 1);
   glMatrixMode( GL_MODELVIEW );
   glLoadIdentity();
   /////////////////////////////////////////////////////////////////
}

      // in main body - function to label objects
      pt = CPoint3D(0.0, 0.0, 0.0);
      pt.Translate(12.0, 165.0, 0.0);   // A point we want labeled

      // set projection 1
      SetOrtho();
      // Get window coords(pt1) from world coords(pt) of point we wish to label
      CPoint3D pt1 = CoordinateProject(&pt);

      // set projection 2
      glViewport( VIEWPORTY[0],VIEWPORTY[1],VIEWPORTY[2],VIEWPORT[3]);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, 100, 0, 100, -1, 1); // scaled to size fonts

      // Get label coord(pt2) from window coords(pt1) of point we wish to label
      CPoint3D pt2 = CoordinateUnProject(&pt1);

      // Draw the text for labelling 
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      font.DrawString(str, pt2.x, pt2.y);
      glDisable(GL_BLEND);
      glDisable(GL_TEXTURE_2D);


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!