I think I can answer this problem , I’ve done the same thing.
First of all, there is a very important thing I had to do (with SDL_TTF2
(freetype2)) before blitting. I had to set the src_alpha off, otherwise I
would
get nothing.
text = TTF_RenderText_Blended(font, string, white );
SDL_SetAlpha(text,0,0);
text is a 32bpp SDL surface or if you aren’t using the blended version, it’s
a 8bit colorkeyed surface in which you would use:
text = TTF_RenderText_Shaded(font, string, white, black );
SDL_SetColorKey(text,SDL_SRCCOLORKEY,0x00000000);
or
text = TTF_RenderText_Solid(font, string, white );
SDL_SetColorKey(text,SDL_SRCCOLORKEY,0x00000000);
Now I have a very complex SDL Surface to OpenGL setup which breaks up
oversized images into whatever the video cards maximum texturesize is.
OpenGL requires textures to be in powers of 2
(2,4,8,16,32,64,128,256,512,1024,2048, Voodoo 1,2,3 cards max out at 256,
most others max out at 1024)
So the simple way is to simply blit the surface to a 32bpp surface that is a
correct texture size. (The problem here is that if you want to align text
against the original size, you have to save the original width/height.)
So create the texture:
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, text->w, text->h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, text->pixels);
Then draw a quad with the this texture.
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(x,y);
glTexCoord2i(0, 1);
glVertex2i(x,y+h));
glTexCoord2i(1, 1);
glVertex2i(x+w,y+h);
glTexCoord2i(1, 0);
glVertex2i(x, y);
glEnd();
(This drawing order may be incorrect, My GL viewport is setup so 0,0 is the
UpperLeft corner of the screen, with the viewport being the size of the
screen.)
BTW, this is essentially what OpenGLBlit does anyways.> ----- Original Message -----
From: owner-sdl@lokigames.com [mailto:owner-sdl at lokigames.com]On Behalf
Of Loren Frank
Sent: May 28, 2001 7:49 AM
To: sdl at lokigames.com
Subject: [SDL] another SDL_ttf question
Now that I have SDL_ttf working, I’d like to use it to display fonts in an
SDL/Open GL program. I don’t understand the relationship between OpenGL and
SDL,
so I’m not quite sure what should work. I’ve tried modifying the showfont
program to open an Open GL window, but it fails with a seg fault.
I’ve also tried copying the essential parts of showfont into my GL program,
and
while it runs perfectly, I don’t get any text.
So … can someone tell me what I should do to display text in an Open GL
SDL
window?
thanks in advance,
Loren
Loren Frank
Postdoctoral Fellow
Neuroscience Statistics Research Laboratory
Harvard / M.I.T. Division of Health Sciences and Technology and
Department of Anesthesia and Critical Care, Massachusetts General Hospital
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com