• Announcements

Archived

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

OpenGL Fonts using SDL/OpenGL

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 on other sites
Survey of OpenGL Font Technology

Looks like what you want is FTGL.

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 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,					OUT_TT_PRECIS,					CLIP_DEFAULT_PRECIS,			ANTIALIASED_QUALITY,			FF_DONTCARE|DEFAULT_PITCH,		"Courier New");						oldfont = (HFONT)SelectObject(hDC, font);             wglUseFontBitmaps(hDC, 32, 96, base);					SelectObject(hDC, oldfont);						DeleteObject(font);						}

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 on other sites
There are quite a few fonts tutorials on NeHe, some of them do not use windows specific functions.

Height Map Editor | Eternal Lands | Fast User Directory

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.

• Forum Statistics

• Total Topics
627694
• Total Posts
2978673
• Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 19
• 14
• 12
• 10
• 12