[SDL] SDL2 GL and RGBA PNG's

Jonathan Dearborn grimfang4 at gmail.com
Fri Mar 8 18:10:59 PST 2013


Maybe use 255 instead of 0 in SDL_SetSurfaceAlphaMod()?

Jonny D


On Fri, Mar 8, 2013 at 6:35 PM, image28 <image28 at slingshot.co.nz> wrote:

> **
> I'm porting my SDL 1.2 application to SDL 2.0 and have run into a problem
> with 32bit textures, 24bit textures load fine, but the 32bit ones don't
> display on the screen.... code bellow, thanks for any help in advance...
>
> int SDL_GL_LoadTexture(struct textures *list, GLuint *texture, GLuint
> *texcount, GLfloat *texcoord, int *w, int *h, int *w2, int *h2)
> {
> SDL_Surface *tempSurf[100];
> SDL_Surface *surface[100];
> int d=0;
> int x,y;
> int tempW[100];
> int tempH[100];
> SDL_Rect area;
> Uint32 saved_flags;
> Uint8 saved_alpha;
>
> // Load all surfaces in list
> for(d=0;d<*(texcount);d++)
> {
> tempSurf[d]=loadSurface(list[d].name);
> *(w+d)=0;
> *(h+d)=0;
> *(w+d) = tempSurf[d]->w;
> *(h+d) = tempSurf[d]->h;
> tempW[d]=0;
> tempH[d]=0;
> tempW[d]=pow2(*(w+d));
> tempH[d]=pow2(*(h+d));
>
> *(w2+d)=0;
> *(h2+d)=0;
> *(w2+d)=tempW[d];
> *(h2+d)=tempH[d];
> }
>
> for(d=0;d<*(texcount);d++)
> {
> if ( tempSurf[d]->format->BytesPerPixel == 3 )
> {
>
> surface[d] = SDL_CreateRGBSurface(
> SDL_SWSURFACE,
> tempW[d], tempH[d],
> 24,
> #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
> 0x000000FF,
> 0x0000FF00,
> 0x00FF0000,
> 0xFF000000
> #else
> 0xFF000000,
> 0x00FF0000,
> 0x0000FF00,
> 0x000000FF
> #endif
> );
> }else{
> surface[d] = SDL_CreateRGBSurface(
> SDL_SWSURFACE,
> tempW[d], tempH[d],
> 32,
> #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
> 0x000000FF,
> 0x0000FF00,
> 0x00FF0000,
> 0xFF000000
> #else
> 0xFF000000,
> 0x00FF0000,
> 0x0000FF00,
> 0x000000FF
> #endif
> );
>
> }
> /*
> // Save the alpha blending attributes
> saved_flags = tempSurf[d]->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
> saved_alpha = tempSurf[d]->format->alpha;
> if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
> {
> SDL_SetAlpha(tempSurf[d], 0, 0);
> }*/
>
> SDL_GetSurfaceAlphaMod(tempSurf[d],&saved_alpha);
> SDL_SetSurfaceAlphaMod(tempSurf[d],0);
> SDL_BlitSurface(tempSurf[d], NULL, surface[d], NULL);
> SDL_SetSurfaceAlphaMod(tempSurf[d],saved_alpha);
> /*
> // Restore the alpha blending attributes
> if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
> {
> SDL_SetAlpha(tempSurf[d], saved_flags, saved_alpha);
> }*/
>
> }
>
> // Genorate and bind textures in list
> glGenTextures(*(texcount), texture);
> for(d=0;d<*(texcount);d++)
> {
> glBindTexture(GL_TEXTURE_2D, *(texture+d));
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> if ( surface[d]->format->BytesPerPixel == 3 )
> {
>
> glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,tempW[d],tempH[d],0,GL_RGB,GL_UNSIGNED_BYTE,surface[d]->pixels);
> }else{
>
> glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,tempW[d],tempH[d],0,GL_RGBA,GL_UNSIGNED_BYTE,surface[d]->pixels);
> }
>
> }
>
> for(d=0;d<*(texcount);d++)
> {
> SDL_FreeSurface(tempSurf[d]);
> SDL_FreeSurface(surface[d]);
> }
> return(0);
> }
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130308/f9361494/attachment-0009.htm>


More information about the SDL mailing list