943,601 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4955
  • C++ RSS
Jun 8th, 2009
0

Displaying Text with SDL and OpenGL

Expand Post »
Hello Everyone!

I'm using C++ to write a small 2D app with SDL and OpenGL. I'm trying as much as possible to keep my code cross-platform. However, I've hit a bump. I can't find a good, easy way to display text on the screen. I am able to do it, but not the way I would like to.
I've tried using the built in bitmapped fonts OpenGL has, but that doesn't give me much control over fonts, sizes, and orientation.
Right now, I'm using SDL_ttf to create an SDL_Surface with my text. From there, I tried two things.
First, I tried creating an opengl texture with the text. This gives me lots of control over it, but the font rarely pixelizes exactly, and it becomes blurry and hard to read, and the font always has a background color. I can't just render ONLY the font.
Second, I tried calling glDrawPixels(...) on the SDL_Surface I got when generating my text. This approach pixelizes correctly, but it brings back the bitmapped font problem: no control over size and color. And for some reason, I can't render my fonts on top of opengl polygons. On background, the fonts are clear and visible, but the polygons seem to cover them up.
I know that OpenGL doesn't have a built in facility to render fonts. So could anyone recommend a good library for me to render True Type Fonts with OpenGL WITHOUT RENDERING THEM TO A SURFACE/TEXTURE?
And please don't suggest FTGL or its relatives. I tried it, and it failed to compile because of an error in the header.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Zcool31 is offline Offline
46 posts
since Mar 2009
Jun 8th, 2009
0

Re: Displaying Text with SDL and OpenGL

Did you try google? There seem to be a lot of hits relating to this. http://www.google.ca/search?q=sdl_ttf+opengl

You can use SDL_ttf's TTF_RenderText_Blended to get smoothed SDL text surfaces. I don't know how to convert them for use in OpenGL from there, unfortunately. I think you should be able to find this information online, though.

It's always annoyed me that SDL_ttf creates new SDL_Surfaces every time. I haven't found a good way to get TrueType text without using it, though. If you're okay with bitmap fonts, you can use SDL_gfx's font code or roll your own (as I did in sailseas). I think the SGE also has support for bitmap fonts, you'd have to check.
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005
Jun 8th, 2009
0

Re: Displaying Text with SDL and OpenGL

Thanks for the suggestion, but I'm trying to stay AWAY from bitmapped fonts. I know for certain that it is posible to render TTF fonts in OpenGL as polygons. I've seen it done. One library that has this capability is FTGL, but I can't get that particular library to work.
This is why I'm asking for alternatives.

Can anyone recommend a library that renders True Type Fonts as POLYGONS in OpenGL? Polygons meaning I can color it, scale and transform it to my will as I can with ANY OpenGL polygon? Something that doesn't require me to generate textures, blit surfaces, or prerender fonts! I want to work with SHAPES that look like the font I'm loading. NOT BITMAPS, NOT TEXTURES, NOT SURFACES. POLYGONS! GROUPS OF VERTEXES IN 3D SPACE!
Reputation Points: 10
Solved Threads: 1
Light Poster
Zcool31 is offline Offline
46 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Stanford cs249a Meterial (Object-Oriented Programming from a Modeling and Simulation)
Next Thread in C++ Forum Timeline: Stack overflow issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC