How to print a line above a 3D scene in OpenGL

I need help printing a line on top of an opengl 3d scene. I have some problems using modelview matrix and projection matrix. As far as I understand, the projection matrix is ​​used to adjust the scene, and the model viewing matrix is ​​used to draw and transform the object into a scene. So, in order to draw something over the 3D scene, I understand that the following procedure will be completed most of all:

  • projection matrix setup for 3d scene
  • setting up the model viewing matrix for a 3D scene
    • draw opengl material
  • projection matrix adjustment for 2d overlay
  • matrix representation of the model for 2d overlay
    • draw opengl material for hud

Is this the right procedure?

+4
source share
1 answer

For 2D rendering, you can think of the projection matrix as a canvas, and movelview as the position of your text. You want to adjust the orthogonal projection as follows:

glOrtho (0.0F, windowWidth, 0.0F, windowHeight, -1.0F, 1.0F);

With this projection, each unit means one pixel (glTranslate2f (120.0, 100.0) will position your text in the pixel (120, 100). This projection displays (0,0) in the lower left corner of the screen. You want to display it in the upper left corner, which you can do:

glOrtho (0.0F, windowWidth, windowHeight, 0.0F, -1.0F, 1.0F);

As rendering text by default does not support OpenGL, it means you need to create a font renderer library or use an existing one. Before doing this, you need to keep in mind your text rendering needs: Is it flat or 3D? It will be static or transformed (scaled, rotated), etc.

Here you can find an overview of opengl rendering methods with pros and cons and libs: http://www.opengl.org/archives/resources/features/fontsurvey/

I started using FTGL to render the TTF font, but lib destroyed my game. So I decided to implement my own font library and went with texture fonts that are no better than TTF, but that was good for my needs.

I used this program: http://www.angelcode.com/products/bmfont/ It takes a TTF font and exports a texture and file descriptor containing each position, size and indentation in each texture that you will use for rendering.

Hope this helps.

+3
source

Source: https://habr.com/ru/post/1415254/


All Articles