Hi There,
I’m trying to create an OpenGL texture using SDL_ttf, and am having some
troubles. I can manage to get SDL_ttf to create a surface with the
proper text, and can convert it to a corresponding surface with even
pixel widths and heights. I know that the text is rendering properly,
because I can do a SDL_SaveBMP on the surface. How should I run the
surface through SDL_ConvertSurface to make it OpenGL compatible, and
what corresponding glTexImage2D parameters should I use for the pixel data?
Here’s a snippit of what I’m trying to do. (yeah, the code’s ugly …)
SDL_Color black = { 0x00, 0x00, 0x00, 0 };
SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
TTF_Font *font;
SDL_Surface *text, *temp;
font = TTF_OpenFont(FONT_FILE, DEFAULT_PTSIZE);
TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
text = TTF_RenderText_Blended(font, DEFAULT_TEXT, white);
if (!text) exit(255);
TTF_CloseFont(font);
int newwidth, newheight;
if (text->w%2!=0)
newwidth = text->w-1;
else
newwidth = text->w;
if (text->h%2!=0)
newheight = text->h-1;
else
newwidth = text->h;
temp =
SDL_CreateRGBSurfaceFrom(text->pixels,newwidth,newheight,text->format->BitsPerPixel,text->pitch,text->format->Rmask,text->format->Gmask,text->format->Bmask,text->format->Amask);
SDL_PixelFormat *fmt;
fmt = temp->format;
fmt->BitsPerPixel=32;
fmt->BytesPerPixel=4;
text = SDL_ConvertSurface(temp,fmt,0);
if (!text)
exit(254);
SDL_FreeSurface(temp);
SDL_SaveBMP( text, "test.bmp");
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, text->w, text->h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, text->pixels);
<<<<<<<<<<<
Help!
Thanks,
Stephen Hassard