开发者

What is the proper way of drawing label in OpenGL Viewport?

I have a multiviewport OpenGL modeler application. It has three different viewports : perspective, front and top. Now I want to paint a label for each viewport and not succeeding in doing it.

What is the best way to print a label for each different perspective? EDITED : The result Here is the result of my attempt:

What is the proper way of drawing label in OpenGL Viewport?

I don't understand why the perspective viewport label got scrambled like that. And, Actually I want to draw it in the upper left corner. How do I accomplished this, because I think it want 3D coordinate... is that right? Here is my code of drawing the label

glColor3f(1,0,0);

        glDisable(GL_DEPTH_TEST);
        glDepthM开发者_开发技巧ask(GL_FALSE);

        glRasterPos2f(0,0);
        glPushAttrib(GL_LIST_BIT);                          // Pushes The Display List Bits
glListBase(base - 32);                              // Sets The Base Character to 32    
    glCallLists(strlen("Perspective"), GL_UNSIGNED_BYTE, "Perspective");    // Draws The Display List Textstrlen(label)
glPopAttrib();

I use the code from here http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13

thanks


For each viewport switch into a projection that allows you to supply "viewport space" coordinates, disable depth testing (glDisable(GL_DEPTH_TEST)) and depth writes (glDepthMask(GL_FALSE)) and draw the text using one of the methods used to draw text in OpenGL (texture mapped fonts, rendering the full text into a texture drawing that one, draw glyphs as actual geometry).


Along with @datenwolf's excellent answer, I'd add just one bit of advice: rather than drawing the label in the viewport, it's usually easier (and often looks better) to draw the label just outside the viewport. This avoids the label covering anything in the viewport, and makes it easy to get nice, cleanly anti-aliased text (which you can normally do in OpenGL as well, but it's more difficult).

If you decide you need to draw the text inside the viewport anyway, I'll add just one minor detail to what @datenwolf said: since you generally do want your text anti-aliased (even if the rest of the picture isn't) you generally want to draw the label after all the other geometry of the picture itself. If you haven't turned on anti-aliasing otherwise, you generally will want to turn it on for drawing the text.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜