0
votes

I need to draw 2D overlay over OpenGL scene. OpenGL is used for 2D animation and just draws textured 2D rectangle in orthogonal projection, this is drawing code:

// viewport is set to the whole window client area
// m_fRectX, m_fRectY are computed in OnSize and define 
// sub-rectangle for image drawing
// m_nImageWidth, m_nImageHeight are texture dimensions

glClear( GL_COLOR_BUFFER_BIT );
glEnable( GL_TEXTURE_RECTANGLE_ARB );
glBegin(GL_TRIANGLE_STRIP);

glTexCoord2d(0.0f, (float)m_nImageHeight);
glVertex2d(-m_fRectX, -m_fRectY);
glTexCoord2d((float)m_nImageWidth, (float)m_nImageHeight);
glVertex2d(+m_fRectX, -m_fRectY);
glTexCoord2d(0.0f, 0.0f);
glVertex2d(-m_fRectX, +m_fRectY);
glTexCoord2d((float)m_nImageWidth, 0.0f);
glVertex2d(+m_fRectX, +m_fRectY);

glEnd();
SwapBuffers(m_hDC);

My requirements:

  1. Performance is critical.

  2. Windows-specific API is allowed.

  3. Text and image overlay (icon-style) are required.

  4. The only factor which defines overlay position and size is window client area size (which is equal to OpenGL viewport in my case).

What technique is suitable for this case?

1
What has your research turned up and/or what have you tried so far?Ani
What do you mean by an "overlay"? Isn't that just drawing more stuff on top of your already drawn scene?Nicol Bolas
@Nicol Bolas - yes, this is what I mean.Alex F
@ananthonline - meanwhile I am trying different ways from this article: opengl.org/archives/resources/features/fontsurvey This question is asked to save my time - I don't want to try everything to make decision...Alex F

1 Answers

3
votes

The most performant way to draw text using OpenGL is by using Bitmap fonts. This uses little texture-mapped quads to render the text. It also has a few drawbacks though. This sort of rendering makes it hard (but not impossible) to scale up from the resolution the font texture is baked at. I like and use AngelCode's Bitmap Font generator, but there are many tools like this one. You can choose one that fits your needs.

Another option is to use Outline fonts. This can be sized up or down with no loss of quality, but uses wglUseFontOutlines.

The third and hardest (but the one with best quality) would be to render the text yourself. This paper by Microsoft Research has some very cool techniques to render vector art right on the GPU. This GPU Gems article shows us how.

There are many tradeoffs between performance, complexity and quality. It is important you understand the pros and cons of each before making a decision to use one or the other.