Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: TextOut()

  1. #1


    I need to render GDI text using TextOut() to a OpenGL double-buffer window.
    How can I do this?

    I need to use TextOut() because not only does it give me anti-aliased fonts,
    I also need to use the exact screen coordinate positioning it provides.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2003

    Re: TextOut()

    If memory serves well, you wouldn't need much more than an HDC. Of course this means that you
    a) build your application using the win32 framework
    b) you somehow get the HDC of the current window (I don't know how, but I think it's possible).

    I think though that when I used it I had flickering problems. I'd suggest, do a search on google for OpenGL Game Programming, go to errata and download the source code for the chapter regarding text (look at the book contents to see which one is it). They have a pretty good coverage of doing fonts. As for the screen coordinates, it might be a bit of work, but it should be trivial.

  3. #3

    Re: TextOut()

    The problem is OpenGL doesn't allow GDI to directly render to the backbuffer.

    So, how can I get fonts created by TextOut on the backbuffer?

  4. #4

    Re: TextOut()

    Q131024 - Drawing Three-Dimensional Text in OpenGL Appliations

    GDI operations, such as TextOut, can be performed on an OpenGL window only if the window
    is single-buffered. The Windows NT implementation of OpenGL does not support GDI graphics
    in a double-buffered window...
    I was hoping I could use glDrawPixels() to do it, but that function only draws
    directly to the frame buffer. Using it on a double-buffer window doesn't work.
    I can't draw directly to the frame buffer, because as you know it will flicker.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Jan 2004

    Re: TextOut()

    Can't you render the text to a buffer in memory?
    That way you could store it as a texture, render it as a quad, and only re-upload it when it has changed.

  6. #6

    Re: TextOut()

    Since there are other elements on the backbuffer that need to be layered, how exactly would
    I preserve the transparency of the text, when copying it from the offscreen surface to the backbuffer?
    The text can be any color, including black.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Sep 2001
    Eastern USA

    Re: TextOut()

    Ugh "surface!"

    But I know what you mean.

    Here's an easy way: Create a next_power_of_2(number of chars you need)*char_width width, char_height image and type out the chars you need in order in a fixed width font (width of char_width)

    Type them out in the order they are presented here:

    Just start with the one you want; I usually use all the punctuation, letters and digits and forget about the extended chars (not on that page) and the control chars (no use for them anyway, in this case)

    Then upload your texture; at render time for a string, the easiest way to do it would be:

    Code :
    void draw_a_string(const char *dstring)
         glFloat left, right, top, bottom;
         float length=0.0f;
         glBindTexture(GL_TEXTURE_2D, font_texture_name);
         for(1; *dstring; ++dstring)
              glTexCoord2f(left, top);  glVertex2f(length, 0.0f);
              glTexCoord2f(left, bottom);  glVertex2f(length, height);
              glTexCoord2f(right, bottom);  glVertex2f(length+1, height);
              glTexCoord2f(right, top);  glVertex2f(length+1, 0.0f);
    (Your function will then have to use the ASCII character set so if that's a problem then... uh, I dunno)

    Might be errors in there, I'm typing this quickly at work where I never get to use OpenGL except when I'm driving home .

  8. #8

    Re: TextOut()

    Thanks, but I don't believe that addresses my problem. I'm not creating text offline.

    I'm creating text while the program is running, and I have no idea what kind
    of text it will be until it is created, like a text editor.

  9. #9
    Senior Member Regular Contributor
    Join Date
    Jan 2004

    Re: TextOut()

    Then I'm not sure that TextOut will work for you at all.

    Unless TextOut can also write an alpha channel, you'll lose all transparency information.

    Maybe you could try FTGL?
    (try )

  10. #10

    Re: TextOut()

    I require TextOut() for its screen coordinate text placement.

    I haven't been able to re-produce exactly how TextOut() places text using outlined fonts
    or a texture with text on it. Any other method of text creation, using FTGL or other
    library, must duplicate TextOut() exactly, including where it places text.

Page 1 of 2 12 LastLast

Similar Threads

  1. TextOut on the buffer OpenGL
    By Obiwan74 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 11-21-2008, 02:42 AM
  2. Replace GDI TextOut with OpenGL
    By Jeff1000 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-20-2007, 03:30 AM
  3. Using TextOut in OpenGL Window
    By kobebryant in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-17-2006, 10:59 PM
  4. wglUseFontOutlines and TextOut
    By gator in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 06-15-2005, 10:11 AM
  5. Textout and Numeric display using OpenGL win 32 Application
    By kashif saeed in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-14-2003, 09:13 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