Results 1 to 8 of 8

Thread: Rendering text in OpenGL

  1. #1
    Junior Member Newbie
    Join Date
    May 2007
    Location
    México City, México, D.F.
    Posts
    2

    Rendering text in OpenGL

    I'm using SDL and OpenGL to do a 3d game.
    I saw SDL_TTF and tried to use it, which involves rendering text to a surface and blitting that surface to the "screen" surface.

    Unfortunately this does not seem to work if the screen is an OpenGL surface, because I never see the font being rendered unless I deactivate the OpenGL
    setting in the video mode (SDL_OPENGL) and comment all OpenGL instructions (i.e. deactivate OpenGL completely) on my app.

    Is there any way I can do blitting (without using the SDL_OPENGL_Blitting or so hack (which I have found to be called the ultimate evil)), or any simple way to do font rendering ?

    Or am I going to have to render font to a texture and use that texture in a polygon.. ?

    In case I have to use the texture-polygon approach, can I do it in a way I only see the rendered text but not the entire polygon?

    Thanks in advance!

  2. #2
    Junior Member Newbie
    Join Date
    May 2007
    Location
    México City, México, D.F.
    Posts
    2

    Re: Rendering text in OpenGL

    Although in the end the texture-polygon approach does seem tempting to use for later in-game effects [what? no evil devil graemlin?? boo!]

  3. #3
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: Rendering text in OpenGL

    In case I have to use the texture-polygon approach, can I do it in a way I only see the rendered text but not the entire polygon?
    Usually, you put the text in an alpha texture. So you can uses the alpha test to discard the rest of the polygon, and you can use blending to smooth the edges of the font.

  4. #4
    V-man
    Guest

    Re: Rendering text in OpenGL

    There are 2 options to the polygon and texture approach. Have one big poly that contains what you want displayed like "please type your name" or if your text will be dynamic, render each character, polygon after polygon.

    It's also possible to do a render to texture approach for the dynamic text situation.
    You need to decide if it is worth your time.

    I would not trust SDL or FTGL. Perhaps they use those damn wgl functions.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: Rendering text in OpenGL

    FTGL uses Freetype 2 for font rendering, so it's propably safe to use on all platforms.

    SDL_TTF does not use OpenGL at all. It's only for the 2D graphics part of SDL, it won't work directly with OpenGL.

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Rendering text in OpenGL

    NeHe lesson 17
    I think this is all you need for now, there are better ways of doing this, but this works better then most methods just because you have complete control over the fonts and you can make them look any way you like (including evil devil graemlins).

  7. #7
    Member Newbie
    Join Date
    Jun 2006
    Posts
    31

    Re: Rendering text in OpenGL

    If you want a quality product, I would recommend defining the fonts as a list of lines and Bezier Curves. Then just render the outline and Tessellate the interior. This will give you a scalable font vs. one that is a set size.

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: Rendering text in OpenGL

    If you want a quality product, I would recommend defining the fonts as a list of lines and Bezier Curves.
    If you're going to do that, you may as well just download Font Creator and the FreeType library, and use their conversion program to generate glyph textures that you can use to render with.

    No point in writing all of that code yourself. And FreeType has a very good license on it.

Similar Threads

  1. Rendering Text on OpenGL Canvas
    By philm0 in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 05-06-2017, 10:31 PM
  2. Text rendering class does not draw text
    By th0masr0ss in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-23-2015, 09:10 PM
  3. OpenGL text rendering
    By sdivya in forum OpenGL ES
    Replies: 1
    Last Post: 06-17-2012, 11:37 PM
  4. Rendering text in OpenGL
    By Vadim in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-18-2011, 04:55 AM
  5. OpenGL and text rendering
    By Qu0ll in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-22-2009, 09:35 AM

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