Sfont in SDL + GL

Started by
4 comments, last by schattenmaennlein 16 years, 6 months ago
Im able to use Sfont in a SDL application. However if I try to use Sfont with GL he compiles without errors but he draws no fonts. The source code I think to be relevant looks like this: // Font = SFont_InitFont(IMG_Load("24P_Copperplate_Blue.png")); - gameloop: SFont_Write (screen, Font, 0,0,"hello world!"); SDL_UpdateRect(screen, 0, 0, 0, 0); Any ideas where my problem could lie? (maybe updaterect isnt suited for my purposes?)
Advertisement
The problem, I believe, is that you can't use SDL and OpenGL rendering at the same time. Once you setup SDL to use OpenGL, you can no longer use SDL calls to render to the screen. You can however render to non-screen surfaces.

One way to get around this then would be to pass another surface to the SFont_Write, then turn that surface into an OpenGL texture.

HTH
thank you, I think that does compute. Still, it sounds kind of an ugly workaround, am I maybe better off if I use another font engine?
*think* or do I face always the same problem? Im not sure if I understand the solution correctly, let me check.

A) write to an SDL_Surface
B) convert the SDL_Surface into an Gltexture (eh btw how do i do that?)
C) Draw an untranslated Screensized quad
D) Texture it with the glTexture

Cant I write into an gltexture to begin with?
Quote:Original post by schattenmaennlein
thank you, I think that does compute. Still, it sounds kind of an ugly workaround, am I maybe better off if I use another font engine?
*think* or do I face always the same problem?

It's not an ugly workaround. It's how things are. SDL opens an OpenGL context which no longer allows 2d blit functions. Not even SDL_Flip works anymore. The way to do things is creating a texture and then rendering a textured quad with OpenGL.
Quote:Original post by schattenmaennlein
thank you, I think that does compute. Still, it sounds kind of an ugly workaround, am I maybe better off if I use another font engine?


If you have static text, the method I suggested is actually pretty simple. If you are going to have dynamic text, then you may run into performance problems when creating so many textures on the fly. I don't know of any font engines for OpenGL.


Quote:Original post by schattenmaennlein
A) write to an SDL_Surface
B) convert the SDL_Surface into an Gltexture (eh btw how do i do that?)
C) Draw an untranslated Screensized quad
D) Texture it with the glTexture

Cant I write into an gltexture to begin with?


That's the idea. To learn how to turn SDL_Surfaces into OpenGL textures, check out the Linux/SDL port of NeHe's texturing tutorial.
very little of my text is dynamic and I dont think i will run into performance problems. Eventhough just to be picky, there is always an extracopy of a texture this way, right?
Anyways, this will work fine and Ill have a look at the link right now.
Still I think I will switch over to devIL as an imageloadlibrary, since I believe it is a little bit more efficient, since I am not using SDLsurfaces at all.

thx guys

This topic is closed to new replies.

Advertisement