| | |
Displaying Text with SDL and OpenGL
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 33
Reputation:
Solved Threads: 1
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.
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; }
}; 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.
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
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
•
•
Join Date: Mar 2009
Posts: 33
Reputation:
Solved Threads: 1
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!
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; }
};![]() |
Similar Threads
- Text and SDL (C++)
- Displaying text in a window (C++)
- displaying text name in text box (JavaScript / DHTML / AJAX)
- how to display numeric values in glut (Game Development)
- Help needed for displaying extended charactors in Tk() (Python)
- Help with displaying text through GUI interface (Java)
Other Threads in the C++ Forum
- Previous Thread: Stanford cs249a Meterial (Object-Oriented Programming from a Modeling and Simulation)
- Next Thread: Stack overflow issue
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





