Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: 2d text

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    1

    2d text

    Hello

    I try to code a text drawing routine and i have a problem with it. I made a class based on a Nehe tutorial, but unfortunately tezt is not displayed.
    Bug is in Print method, probably there's something wrong with matrices, but i don't know how to make this code work
    Can someone help me?
    Thanks.

    Code goes like this:

    class CFont
    {
    private:
    GLuint base;
    HFONT font;
    GLYPHMETRICSFLOAT gmf[256];
    public:
    CFont();
    ~CFont();
    void Init(char *name, int height, char *tex_filename);
    bool LoadGLTexture(char *filename);
    void Print(float coord_x, float coord_y, char *text);
    void CentreAt(float coord_x, float coord_y, char *text);
    };

    CFont::CFont()
    {
    font =0;
    base=0;
    memset(gmf,0,sizeof(GLYPHMETRICSFLOAT)*256);
    }

    CFont::~CFont()
    glDeleteLists(base, 256);

    void CFont::Print(float coord_x, float coord_y, char *text)
    {
    int vPort[4];

    // Enable2D();
    glGetIntegerv(GL_VIEWPORT, vPort);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, vPort[2], 0, vPort[3], -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    // move to desired position
    glRasterPos2f(coord_x, coord_y);

    glPushAttrib(GL_LIST_BIT);
    glListBase(base);

    // display text
    glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
    glPopAttrib();

    // Disable2D();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    }

    GLvoid CFont::Init(char *name, int font_height, char *filename)
    {
    base = glGenLists(256);

    font = CreateFont(font_height,
    0,
    0,
    0,
    FW_BOLD,
    FALSE,
    FALSE,
    FALSE,
    ANSI_CHARSET,
    OUT_TT_PRECIS,
    CLIP_DEFAULT_PRECIS,
    ANTIALIASED_QUALITY,
    FF_DONTCARE|DEFAULT_PITCH,
    name);

    SelectObject(hDC, font);
    wglUseFontOutlines( hDC, 0, 255, base, 0.0f, 0.0f, WGL_FONT_POLYGONS,gmf);
    }

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    626

    Re: 2d text

    I suggest to post this in NeHe's forums. Hopefully the people here is more experienced with those tutorials.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2004
    Location
    Vienna, Austria
    Posts
    4

    Re: 2d text

    Hi!

    in the CreateFont(), the second arg is for the width of a char; u have set NULL there, so the single chars will be displayed with that width...

    wish good success!
    Amando

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •