iDevGames Forums
Trouble turning an SDL surface into an OpenGL texture - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Trouble turning an SDL surface into an OpenGL texture (/thread-3276.html)



Trouble turning an SDL surface into an OpenGL texture - Joseph Duchesne - May 22, 2007 03:15 PM

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);
}



Trouble turning an SDL surface into an OpenGL texture - unknown - May 22, 2007 03:36 PM

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.


Trouble turning an SDL surface into an OpenGL texture - Skorche - May 22, 2007 03:40 PM

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.


Trouble turning an SDL surface into an OpenGL texture - ThemsAllTook - May 22, 2007 04:25 PM

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)


Trouble turning an SDL surface into an OpenGL texture - Joseph Duchesne - May 22, 2007 05:14 PM

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.