سؤال

Text rendering is one of the hard topic to be understood for most new comers. and right now, i got stuck here. well i'd like to ask wheter my way is good idea to render text.. OpenGL does not have built-in functionality to render text to the screen, thats make me confused. after searching, that the text render is using bitmap.

Load and bind bitmap font texture -> Parse text and generate and bind vertices array, mapping texture with uv array,... -> Render it to screen

ok this may can solve how to render text, but i still stuck. (for example) what if i make timer based Text that change every millisecond (since i draw text just like : Minute:Second:Mili Second) this is not good idea right? since i must repeat that algorithm while i want to change the text. i guess if we keep using bitmap the machine would get slower.

well, seeing bitmap text rendering is so slow, i make some way to render text without bitmap perhaps it would be get better? that's why i ask here

here is how i draw character model with 3d Vertex + GLOrtho just take look at my vector font code (example) How to draw "L" character with Vector

    const float MAX_HEIGHT = 18.0f; //set maximum height of character
    const float MAX_WIDTH = 20.0f;  //set maximum width of character

void drawL(GLfloat x,GLfloat y){
           glPushMatrix();
        //i've set before glOrtho(0, Window.width, Window.height, 0, 0, 1);
        glTranslatef(x,y,0.0f);
        glBegin(GL_QUADS);
        glVertex3f(0.0f,0.0f,0.0f);       //draw vertical quad
        glVertex3f(3.0f,0.0f,0.0f);
        glVertex3f(3.0f,MAX_HEIGHT,0.0f);
        glVertex3f(0.0f,MAX_HEIGHT,0.0f);

        glNormal3f(0.0f,MAX_HEIGHT,0.0f);  //draw horizontal quad
        glVertex3f(2.0f,MAX_HEIGHT,0.0f);
        glVertex3f(MAX_WIDTH - 10.0f,MAX_HEIGHT,0.0f);
        glVertex3f(MAX_WIDTH - 10.0f,MAX_HEIGHT - 3.0f,0.0f);
        glVertex3f(2.0f,MAX_HEIGHT - 3.0f,0.0f);
        glEnd();
        glPopMatrix();
    }

there are some advantages if we draw character with vector/GL_QUAD vertex if you would like to resize the font will not getting blur.

the question now will this getting slower if i make timer based text that change every Milisecond? with this way, repeat the algorithm is unnecessary if i'm gonna change the text. they are not even consume much resource because it's not bitmap, it just vector rendering.

هل كانت مفيدة؟

المحلول

that change every millisecond

First of all, that would require a display update frequency of 1000Hz to be even representable. No display in the world is that fast. The fastest displays around manage some 200Hz. So don't even think about updating your timer display at that rate.

An important rule about displays is: Don't display more digits than you can actually accurately measure. The accuracy of display updates is in the order of 1/10s of a second, so you should display only that much.

If you want to store a screenshot of a game, then the game update tick interval determines the accuracy. Usually no more than 100Hz, i.e. 1/100 of a second.

Now since you don't want to upload a new string texture every frame, the common way to go about this are glyph texture atlases, i.e. a texture with every glyph you want to render in it, from which you then draw quads addresses the respective characters by their texture coordinate. To save on texture memory you can use some method like Distance Fields (implemented for example in libGDX).

Also I recommend reading this SO answer on OpenGL text rendering methods

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top