Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


OpenGL Fonts using SDL/OpenGL

This topic is 5619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I''ve been looking through the net for a few hours now but couldn''t find anything realted to what I''m looking for. I want to write text to the screen i.e. using fonts. I''ve found lots of examples, but they all use the Windows API. However, in my application I''m using SDL to allow portability. Also on NeHe''s site there is a port to SDL, but it still contains some Linux specific stuff. So during my search I found a small library called BFont++. It uses SDL and works nice IF I don''t use any openGL. They provide a sample source, but as I said, it doesn''t use OpenGL. Pure SDL here. However, I want to be able to draw some text to my OpenGL Surface. Now I have no clue about how I could do this. I though maybe I could use 2 SDL_Surfaces and somehow render the game to one and the font to the other and then combine them. However, I have no clue about how this could be done. So if anyone knows a place where I could find information about using fonts with SDL/OpenGL in Win32 that''s be nice. Or of you have any suggestion or idea or whatever, please post it. Thanks in advance

Share this post

Link to post
Share on other sites
Porting a simple Windows OGL application to SDL is TRIVIAL.
Just look on the SDL samples, on OGL, and you will have no problems adapting the NEHE tutorials to SDL (as long as they don''t use windows functions to do the fonts stuff, so try the BMP font routines).
But what you should do is to write your very own fonts function.
Just load the fonts from a texture, and draw small rectangles, with the letters. It took me only like 2 hours to do a printstring() function, that does that.

Height Map Editor | Eternal Lands | Fast User Directory

Share this post

Link to post
Share on other sites
@Jeff K: Thanks for the link. Though FTGL seems a little bit of an overkill for what I''m trying to do. I just need some simple text to display the score of the player. Nothing fancy needed.

@Raduprv: I can port the Windows Code from NeHe to OpenGL. However the point is that he does use windows specific function to Build the Font. He uses CreateFont(...) and then a wgl function

  GLvoid BuildFont(GLvoid)					
HFONT font;
HFONT oldfont;
base = glGenLists(96);
font = CreateFont(-24, 0, 0, 0, FW_BOLD, FALSE, FALSE,FALSE, ANSI_CHARSET,
"Courier New");

oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC, 32, 96, base);
SelectObject(hDC, oldfont);

So that''s what NeHe uses for Building the DisplayLists. I pretty much understand what is going on, but I don''t know how I would go about implementing my own version of that using SDL.

Everything else in his code is perfectly clear and I know how to port it. Just not this one.

Share this post

Link to post
Share on other sites
Why not use SDL_ttf ( http://www.libsdl.org/projects/SDL_ttf/ ) it works on Windows and Linux and allows you to use True Type fonts and is built to work with SDL. I have used it myself in the JEDI-SDL ( Delphi/Kylix headers @ http://www.sf.net/projects/jedi-sdl )

Alternatively, have a look at tutorial Nehe''s Tutorial 21 ( http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=21 ) which uses Bitmap fonts texture in a simple Ortho game. The SDL port can be downloaded from http://nehe.gamedev.net/data/lessons/linuxsdl/lesson21.tar.gz.

Either way you should be up an running in no time.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!