Thread: OpenGL Text

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    648

    OpenGL Text

    How would you go about printing text in OpenGL? I would like to use real fonts instead of bitmap fonts. And is there any way I can render it to a texture so I can place it on a quad?

    Any links or libraries would be appreciated. Thanks.

  2. #2

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If using windows then there's wglUseFontOutlines. As far as I know there's no corresponding X-server function so you're probably stuck with bitmap fonts.

    I think nehe's site will probably have an example on the use of wglUseFontOutlines.

    edit: beaten by jverkoey
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    If you feel like being creative you can create your own bitmap based fonts with a little work. Basicly create a bitmap file that has your characters in them (use a graphic program's text tool).

    The step goes a little like this:
    Code:
    // psuedo
    for every character in a string {
         select the bitmap texture file
         get a texture rectangle to the character you want to display
         display a quad offset x pos by current char * char width 
    }
    Say your font bitmap file has 10 characters per line and 4 lines
    a b c d e f g h i j
    k l m n o p q r s t
    u v w x y z - - - -
    - - - - - - - - - -

    in order to get the correct texture rectangle you take the character you want to display
    subtract 67 from it. This will get you the nth character in your bitmap . Convert the 1d character number (1-40) into a 2d position (row column). Then multiply 0.10 times row and col position to find out the x, y tex coordinate.

    I've given very vague - but workible example. I hope it can help you out.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  5. #5
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    wglUseFontBitmaps will generate a bitmapped font from a font file. You have to use drawl lists to draw the text, but it's not that complicated.
    Last edited by skorman00; 06-24-2004 at 12:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. OpenGL - text output
    By gavra in forum C Programming
    Replies: 3
    Last Post: 08-06-2008, 01:22 AM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM