Trouble turning an SDL surface into an OpenGL texture

Nibbie
Posts: 1
Joined: 2010.11
Post: #1
I've got a function that used to work just fine turning SDL an sdl surface with a character drawn through SDL_ttf. However, when I switched my build type to Universal, I'm suddently not getting text any more. My charactor textures are blank. I'm pretty sure that the SDL surface is getting drawn properly. The printf results in a number of lines like so:

glyph A created with width and height of 14,24. OpenGL: 16,32

I think that somehow my texture is not being created properly, but I can't figure out what's wrong. The function in question:

Code:
void create_glyph(char ch,tchar *tc)
{
    SDL_Surface *initial;
    int w,h;
    /* Use SDL_TTF to render the text */
    color.r=255;
    color.g=255;
    color.b=255;
    char text[2];
    text[0]=ch;
    text[1]='\0';
    initial = TTF_RenderText_Blended(font, text, color);
    
    /* Convert the rendered text to a known format */
    w = nextpoweroftwo(initial->w);
    h = nextpoweroftwo(initial->h);
    
    printf("glyph %s created with width and height of %d,%d. OpenGL: %d,%d\n",text,initial->w, initial->h,w,h);
    
    tc->data = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
            #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
            0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
            #else
            0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
            #endif
            );

    SDL_BlitSurface(initial, 0, tc->data, 0);
    
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &tc->tex);
    glBindTexture(GL_TEXTURE_2D, tc->tex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tc->data->pixels );
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    

    SDL_FreeSurface(initial);
}
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
You seen to be using char, which means you are only dealing with 7 bit ASCII. You could save the trouble and bloat of using SDL_tff and freetype/whatever that entials with http://fax.twilightcoders.net/GlyphTool/ which will do do EASCII as well, if you like.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
Don't have a solution to your problem, but a possibly easier implementation. If you render the character using the shaded instead of blended mode, you would just get an 8bit greyscale bitmap. Considering that you are just setting the color to white anyway, you might as well do this. It would allow you to skip the conversion step.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
Using GL_UNSIGNED_INT_8_8_8_8_REV instead of GL_UNSIGNED_BYTE for little endian might work. Possibly in lieu of the #if above in SDL_CreateRGBSurface, but I don't know SDL well enough to say, really. (Mostly just making logical guesses)
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #5
unknown Wrote:You seen to be using char, which means you are only dealing with 7 bit ASCII. You could save the trouble and bloat of using SDL_tff and freetype/whatever that entials with http://fax.twilightcoders.net/GlyphTool/ which will do do EASCII as well, if you like.

Ah, at the time that I first implemented this, GlyphTool was in much earlier stages. Thanks for the update Smile I think I'll switch to it. That way I'll get the fast texture based fonts that I'm used to without the annoyance of another library.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Texture Masking airfire 6 13,764 Mar 17, 2014 07:07 PM
Last Post: baioses
  OpenGL ES Texture Compression ajrs84 9 3,242 May 7, 2013 03:36 PM
Last Post: ajrs84
  OpenGL ES Texture Masking dalasjoe sin 0 3,657 Apr 13, 2012 12:17 AM
Last Post: dalasjoe sin
  Texture in OpenGL ES 2 looks pixelated vunterslaush 18 21,486 Aug 30, 2011 09:44 PM
Last Post: Frogblast
  Is Dealing with Opengl ES 2 worth the trouble? Mattonaise 9 7,698 Aug 23, 2011 08:56 PM
Last Post: Mattonaise