Displaying Text with SDL and OpenGL

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2009
Posts: 33
Reputation: Zcool31 is an unknown quantity at this point 
Solved Threads: 1
Zcool31 Zcool31 is offline Offline
Light Poster

Displaying Text with SDL and OpenGL

 
0
  #1
Jun 8th, 2009
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.
class NoClass {
	~NoClass () { delete this; }
};
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Displaying Text with SDL and OpenGL

 
0
  #2
Jun 8th, 2009
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.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 33
Reputation: Zcool31 is an unknown quantity at this point 
Solved Threads: 1
Zcool31 Zcool31 is offline Offline
Light Poster

Re: Displaying Text with SDL and OpenGL

 
0
  #3
Jun 8th, 2009
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!
class NoClass {
	~NoClass () { delete this; }
};
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC