Draw text with OpenGL/SDL SDL_TTF

hello,
i have a big problem. how can i draw text in opengl with SDL_TTF?

At 18:04 8/9/2003 +0200, you wrote:

hello,
i have a big problem. how can i draw text in opengl with SDL_TTF?

     I don't think you can, as SDL_TTF is designed to use an 

SDL_Surface and blits, which are not available in Open GL. I’m using
bitmapped fonts for that task.

     Paulo
    I don't think you can, as SDL_TTF is designed to use an

SDL_Surface and blits, which are not available in Open GL. I’m using
bitmapped fonts for that task.

How are you using those bitmap fonts? You load them as SDL surfaces
and upload them as textures, I guess.

There’s no difference in making a surface with SDL_ttf and uploading
that. Well, there is, with bitmap fonts you usually handle one letter
at a time, with SDL_ttf you handle whole words or sentences etc.

In a nutshell, to use SDL_ttf with OpenGL, make the surface and upload
it as a texture. A good tool for that is the function
SDL_GL_LoadTexture, found in tests/testgl.c in SDL source package.–
Petri Latvala

How are you using those bitmap fonts? You load them as SDL surfaces
and upload them as textures, I guess.

Sure (drawing them on a pixel by pixel basis seems a very bad idea :P). I use my sprite engine for that, later I found another SDL library (BFont, I guess) that does the same, but as my sprite engine is already on Open GL, it wouldn’t make sense to modify this one to do the same (and drawing bitmaped texts are kind of a simple thing),

There’s no difference in making a surface with SDL_ttf and uploading
that. Well, there is, with bitmap fonts you usually handle one letter
at a time, with SDL_ttf you handle whole words or sentences etc.

In a nutshell, to use SDL_ttf with OpenGL, make the surface and upload
it as a texture. A good tool for that is the function
SDL_GL_LoadTexture, found in tests/testgl.c in SDL source package

Well, the whole point on the original message I replied was to use SDL_ttf directly, at most you can do what you said. One problem is that textures must be at power 2 sizes (64, 128, 256 and so on), so there will be some work around to create textures the right size and drawing them properly on the screen. Not to mention that I don’t know how performance will be affected by creating a new texture, binding, drawing and them freeing it every time a text is being drawed on the screen. Anyone has some advice on this matter, BTW?

Paulo

I’ve found the fastest way to do this is to render the whole glyph set
at some arbitrary size (selectable, usually 24pt works well for me) into
a texture once and keep it, rather than freeing the texture.

What it actually does is create a new SDL RGBA Surface, and copy (not
blit) one glyph at a time, rendering them from SDL_TTF onto that single
RGBA surface while keeping track of the position and size of each glyph.

After they’ve all been placed on the surface, turn that surface into a
texture, and map all the locations and sizes of the glyphs into texture
coordinates. Then when you want to render a sentence, you can just bind
the texture once, and draw a quad for each glyph using the texture
coordinates calculated earlier.

By putting the whole set into a single texture this way, you canOn Fri, 2003-09-12 at 11:29, pvwr at sympatico.ca wrote:

How are you using those bitmap fonts? You load them as SDL surfaces
and upload them as textures, I guess.

Sure (drawing them on a pixel by pixel basis seems a very bad idea :P). I use my sprite engine for that, later I found another SDL library (BFont, I guess) that does the same, but as my sprite engine is already on Open GL, it wouldn’t make sense to modify this one to do the same (and drawing bitmaped texts are kind of a simple thing),

There’s no difference in making a surface with SDL_ttf and uploading
that. Well, there is, with bitmap fonts you usually handle one letter
at a time, with SDL_ttf you handle whole words or sentences etc.

In a nutshell, to use SDL_ttf with OpenGL, make the surface and upload
it as a texture. A good tool for that is the function
SDL_GL_LoadTexture, found in tests/testgl.c in SDL source package

Well, the whole point on the original message I replied was to use SDL_ttf directly, at most you can do what you said. One problem is that textures must be at power 2 sizes (64, 128, 256 and so on), so there will be some work around to create textures the right size and drawing them properly on the screen. Not to mention that I don’t know how performance will be affected by creating a new texture, binding, drawing and them freeing it every time a text is being drawed on the screen. Anyone has some advice on this matter, BTW?

Paulo


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Jimmy <@Jimmy>
Jimmy’s World.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030912/2ef87e4f/attachment.pgp

After they’ve all been placed on the surface, turn that surface into a
texture, and map all the locations and sizes of the glyphs into texture
coordinates. Then when you want to render a sentence, you can just bind
the texture once, and draw a quad for each glyph using the texture
coordinates calculated earlier.

Quite interesting way to have a bitmapped font, you’re doing something similar to
SFont/BFont Builder, which uses SDL_ttf output to render BFont bitmapped fonts, but on “real
time”. The point is that your technique take in consideration the size for each glyph, which I
think should help the rendered text to look better, as “thin” letters (such as i, l, j and others)
won’t waste space on the screen.

Paulo

pvwr at sympatico.ca wrote:

Well, the whole point on the original message I replied was to use
SDL_ttf directly, at most you can do what you said. One problem is
that textures must be at power 2 sizes (64, 128, 256 and so on), so
there will be some work around to create textures the right size and
drawing them properly on the screen. Not to mention that I don’t know
how performance will be affected by creating a new texture, binding,
drawing and them freeing it every time a text is being drawed on the
screen. Anyone has some advice on this matter, BTW?

Render all glyphs to textures. Paste them together to form text.

BTW, you can get more control over your text and less overhead by using
FreeType directly instead of going through SDL_TTF, although I admit that
FreeType is a bitch to use.–
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com