Better fonts

Fonts under OpenGL, well, suck.
Can’t even render fonts to the backbuffer.

http://support.microsoft.com/kb/q131024/

Fonts don’t belong in OpenGL anyway. That is the job of higher level libs.

Take your pick:
http://www.opengl.org/resources/features/fontsurvey/

http://www.cs.unc.edu/~rademach/glui/

http://www.cegui.org.uk/

Plus some others you can find with a bit of googling…

Well, ok, to be fair, those alternatives are no better either. :slight_smile:

Another option for 3d fonts is to make them yourself in a modeling program. This would make it portable as well, seeing that for example in win32, you use the wgl* functions to get 3d fonts for OpenGL display lists. If you don’t like them, you can make better and higher detailed fonts yourself. Like said above, fonts are for a higher level library in mty opinion as well.

2D fonts produced by Windows GDI function TextOut() are excellent, and having the flexibility
to render them at any size and maintain the same quality is what I desire.

The only problem is they don’t get drawn to backbuffer. The root of all my problems.
Using any other function or method to create 2D fonts is not desirable.

to me FTGL looks good and versatile :
http://homepages.paradise.net.nz/henryj/code/index.html#FTGL

Does FTGL have an function equivalent to TextOut() that matches its 2D output exactly?
Does it place 2D text in exactly the same position on screen as TextOut()? Does it create
text the exactly same size on screen as TextOut? It must match this function in every
aspect, not just quality.

What you want is not possible.

You can’t mix OpenGL and GDI functions and expect to get exactly the same result, pixel per pixel. OpenGL is a 3D API. The nature of how a 3D rendering pipeline works makes it impossible to produce exactly the same thing as the standard GDI text rendering functions. Proper text rendering is extremely complex, it must be done on the CPU.

The only possibility to get exactly the same result would be to pre-render the text with the exact same size to a texture and render this texture to the screen without scaling and filtering. But that’s not acceptable from a performance point of view because you’d have to upload a new texture every time some text changes.

If you really need that high quality of text rendering that a truetype renderer produces, you shouldn’t use OpenGL.

I simply use as a basis, NehE’s bitmap font rendering for speed, with pre-computed x axis (I’m in ortho mode here) offsets by manually examining each char image’s width, creating a display list which offsets each char by it’s width and a bit more and rendering using linear filtering… as long as the text scale == 1.0f, the text is as perfect as any crummy GDI thing, with the added bonus that it’s fast and looks perfect.
Here’s a cutdown version of the class (It won’t compile as is, but the bulk of it is there)
http://www.binarystudio.co.uk/externallyLinked/font2d.zip

I prefer this to any DirectX DXFont object, as it’s faster and more customizable.
It uses www.lmpco.com 's bitmap font creator, much like NeHe’s http://nehe.gamedev.net 's font tutorials do.

Text rendering does not suck in OpenGL, you’ve gotta work at it.

althogh i’ve being here all of two seconds and know new to nothig about opengl. I would have to agree becasue neally all graphical programs will have text in them.

i think that… using advantages that a GPU DOES have… you COULD achieve a similar effect to how windows or macs rasterize fonts. There could be a space in video memory which would contain all the glyphs of the font… and when its time to draw a font to the screen, scaled or whatever, use a shader to filter it. when uploading a font to memory, you could use software to get just the outlines or whatever of the glyphs, to allow the gpu to have a lot of control over them. im no expert on opentype and truetype if you cant tell already :stuck_out_tongue: but… i think the gpu could do SOMETHING to natively process fonts… maybe not the same way a complicated software rasterizer would do it, or maybe a combination of both.

Originally posted by uranium_junkie:
althogh i’ve being here all of two seconds and know new to nothig about opengl. I would have to agree becasue neally all graphical programs will have text in them.
OpenGL is not an SDK with 3D graphics built in, it’s a hardware abstraction layer. If text rendering is not a hardware service, then OpenGL doesn’t, and shouldn’t, have a text rendering service. It really is as simple as that - no amount of argument will change that. Something that uses OpenGL should provide the text rendering.

Might I suggest Freetype . It’s an easy to use API that you can use to generate bitmaps on the fly from strings. You then use OpenGL to get the bitmap to the screen.

Supported font formats:

  • TrueType fonts (and collections)
  • Type 1 fonts
  • CID-keyed Type 1 fonts
  • CFF fonts
  • OpenType fonts (both TrueType and CFF variants)
  • SFNT-based bitmap fonts
  • X11 PCF fonts
  • Windows FNT fonts
  • BDF fonts (including anti-aliased ones)
  • PFR fonts
  • Type 42 fonts (limited support)

There’s a great deal more information at the link above.

-Raystonn

The reason why I posted this thread was to find an equivalent version of TextOut() for OpenGL.
Creating 2D text alone is not the issue. This OpenGL version must match TextOut() and all its
parameters (text placement on screen, etc…), as if they were the same function.

This OpenGL version must match TextOut() and all its
parameters (text placement on screen, etc…), as if they were the same function.
Download a library that has similar functionality, or write one yourself. OpenGL will not have font rendering functionality built into it, nor will it import Win32 functions into itself. End of story.

Originally posted by tibit:
The reason why I posted this thread was to find an equivalent version of TextOut() for OpenGL.
Creating 2D text alone is not the issue. This OpenGL version must match TextOut() and all its
parameters (text placement on screen, etc…), as if they were the same function.

The only possible solution to import externally rendered GDI bit is to use GDI functions to render to a bitmap, then copy those pixels to the OpenGL buffer. I think that is essentially how it is done with GDI+DirectX, and GDI will never play nice enough with OpenGL to draw or copy the pixels to OpenGL for you.