开发者

Displaying not moving text not in 3D (eg. displaying HUD or frame rate)

I want to make something to display text on the screen. But I want something like FPS displayer - wherever you are text is in the same place (eg. in开发者_C百科 corner) and have the same height. Something like drawing HUD.

I'd like to see code.


That kind of thing is usually done in the a way like this:

void render_frame()
{   
    glViewport(0, 0, win_width, win_height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    set_perspective_projection(); // glFrustum, gluPerspective, etc.
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    render_scene();

    glViewport(0, 0, lower_left_HUD_width, lower_left_HUD_height);
    glEnable(GL_SCISSOR_TEST);
    glScissor(0, 0, lower_left_HUD_width, lower_left_HUD_height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1, 0, 1, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_DEPTH_BUFFER_BIT);
    render_lower_left_HUD();

    glViewport(win_width - upper_right_HUD_width, win_height - upper_right_HUD_height, upper_right_HUD_width, upper_right_HUD_height);
    glEnable(GL_SCISSOR_TEST);
    glScissor(win_width - upper_right_HUD_width, win_height - upper_right_HUD_height, upper_right_HUD_width, upper_right_HUD_height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1, 0, 1, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_DEPTH_BUFFER_BIT);
    render_upper_right_HUD();

    SwapBuffers();
}

Just to give you the general idea. You can expand this concept as far as you want, placing mini-views instead of HUDs or similar.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜