开发者

opengl text string on cube

开发者 https://www.devze.com 2023-03-10 11:28 出处:网络
im making a cube in opengl, and i want some text on the sides of the cube. i got the code of the cube below, but how can i make a text string display on it?

im making a cube in opengl, and i want some text on the sides of the cube. i got the code of the cube below, but how can i make a text string display on it?

    void drawBox()
{
    glBegin(GL_QUADS);

    glColor3f(1.0f, 0.0f, 0.0f);
    // FRONT
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glVertex3f( 0.5f, -0.5f, 0.5f);
    glVertex3f( 0.5f, 0.5f, 0.5f);
    glVertex3f(-0.5f, 0.5f, 0.5f);
    // BACK
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f(-0.5f, 0.5f, -0.5f);
    glVertex3f( 0.5f, 0.5f, -0.5f);
    glVertex3f( 0.5f, -0.5f, -0.5f);

    glColor3f(开发者_开发百科0.0f, 1.0f, 0.0f);
    // LEFT
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glVertex3f(-0.5f, 0.5f, 0.5f);
    glVertex3f(-0.5f, 0.5f, -0.5f);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    // RIGHT
    glVertex3f( 0.5f, -0.5f, -0.5f);
    glVertex3f( 0.5f, 0.5f, -0.5f);
    glVertex3f( 0.5f, 0.5f, 0.5f);
    glVertex3f( 0.5f, -0.5f, 0.5f);

    glColor3f(0.0f, 0.0f, 1.0f);
    // TOP
    glVertex3f(-0.5f, 0.5f, 0.5f);
    glVertex3f( 0.5f, 0.5f, 0.5f);
    glVertex3f( 0.5f, 0.5f, -0.5f);
    glVertex3f(-0.5f, 0.5f, -0.5f);
    // BOTTOM
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f( 0.5f, -0.5f, -0.5f);
    glVertex3f( 0.5f, -0.5f, 0.5f);
    glEnd();
}


Different approaches depending on how you want it to look:

  • Draw your text in a texture and use that texture on a cube face
  • Render the text as 3D model using GLut functions
  • Simply draw 2D text at the right position using non-openGL functions (project on of the cube vertices to screen space and use that position as starting point for your text)

(Google OpenGL texturing tutorial and OpenGL text tutorial before asking such questions, lots of info there ...)


Use bitmaps fonts as nehe tutorial.

Check that link.

http://nehe.gamedev.net/lesson.asp?index=03

0

精彩评论

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

关注公众号