Results 1 to 2 of 2

Thread: Problems rendering fonts with freetype and opengl

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2002
    Posts
    1

    Problems rendering fonts with freetype and opengl

    I'm trying to render some text and I figured I could do it pretty easily with freetype2. My plan was basically to render a character with freetype and cache it in a display list. I put together the following code based on the freetype tutorial and an example in the red book. Unfortunately I
    haven't had any luck getting it to work.

    What I would like to know is:
    1.) Is this a valid plan? In other words will it work?

    2.) Have I missed some steps in freetype or is it something I messed up in opengl?

    Really any help would be appreciated as I'm feeling like banging my head against the desk here.

    Thanks,
    -John

    Some notes about the code:
    * I am error checking I just didn't include it here.
    * I'm using SDL so that's where the Uint16 data type is coming from. If I didn't miss understand what I read about unicode I believe it should give me a unicode value from ascii.
    * I realize that I'm not taking into account a glyph's origin. Right now I don't care. I just wanted to see some text on the screen.
    * I wasn't sure if I needed a call to glPixelStorei(). I suspect I do.

    void InitFont() {
    FT_UInt index;
    Uint16 i;

    FT_New_Face(library, "fonts/times.ttf", 0, &face);

    FT_Set_Char_Size(face, 0, 22*64, 0, 0);

    fontOffset = glGenLists(12;

    for (i = 'A'; i < 'A' + 4; i++) {
    index = FT_Get_Char_Index(face, i);

    FT_Load_Glyph(face, index, FT_LOAD_DEFAULT);
    FT_Render_Glyph(face->glyph, ft_render_mode_normal);

    glNewList(fontOffset + i, GL_COMPILE);
    glBitmap(face->glyph->bitmap.width,
    face->glyph->bitmap.rows,
    0.0, 0.0,
    (float) (face->glyph->bitmap.width + 2), 0.0,
    face->glyph->bitmap.buffer);

    glEndList();
    }

    }

    void printGL(char *string) {

    glPushAttrib(GL_LIST_BIT);
    glListBase(fontOffset);
    glCallLists(strlen(string), (GL_UNSIGNED_BYTE,)
    (GLubyte *) string);

    glPopAttrib();

    }

    void DrawScene() {
    .... Other opengl stuff ....

    glColor3ubv(red);
    glRasterPos2i(20, 100);
    printGL("ABC");

    .... Swap the video buffer ....
    }

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    18
    In your InitFont() you might want to add an int which holds error value for FT_New_Face call. this can give you some info. Good luck!

Similar Threads

  1. Problems rendering text with freetype
    By princip in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-28-2018, 12:44 AM
  2. Rendering Text with FreeType doesn't work
    By Michael25 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-17-2016, 05:47 AM
  3. Rendering text on a quad with Freetype + GLFW
    By ZeroSum in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-12-2015, 05:31 PM
  4. Nehe lesson 43 questions (freetype fonts)
    By wwuster in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 12-30-2009, 07:48 AM
  5. freetype fonts are twisted.
    By LinGreg in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-12-2007, 10:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean