PDA

View Full Version : SDL_Image, Opengl Textures & Alpha



technomage
22-01-2005, 05:44 PM
Hi

Ive; written some code to load a tga file using SDL_Image and then produce a opengl texture from that. The problem I'm getting this that the alpha channel doens't seem to be coming through. the I render with the Blend functions off the texture renders OK , but with blending all I get is a black screen. :?

Here is the code



Surface:= nil;
TempSurface := IMG_Load(PChar(Filename));
if TempSurface <> nil then
begin
SDL_FlipRectV&#40;TempSurface, nil&#41;; // so the texture isn't upside down
Surface &#58;= SDL_CreateRGBSurface&#40;SDL_SWSURFACE, Width, Height, TempSurface.format.BitsPerPixel,
TempSurface.format.RMask,TempSurface.format.GMask, TempSurface.format.BMask,TempSurface.format.AMask&#41; ;
SDL_BlitSurface&#40;TempSurface, nil, Surface, nil&#41;;
SDL_FreeSurface&#40;TempSurface&#41;;
glEnable&#40;GL_TEXTURE_2D&#41;;
glGenTextures&#40;1, @FTextureID&#41;;
glBindTexture&#40;GL_TEXTURE_2D, FTextureID&#41;;
glTexParameteri&#40;GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST&#41;;
glTexParameteri&#40;GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST&#41;;
glTexImage2D&#40;GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Surface.pixels&#41;;
end;


I keep the surface around becuase I will probably update is everynow and then and refresh the texture.

Can any one see any obvious problems?

Dean

{MSX}
22-01-2005, 09:31 PM
Can any one see any obvious problems?


No, but i suggest you to use PNG instead of TGA.

technomage
23-01-2005, 09:20 PM
PNG seems to be working, I've given up on tga

Cheers :)