I have a set of png images that have a transparency/alpha channel. i want to
concatenated
these images into an SDL surface then use that surface in my program. I have
already written a small program that does indeed load the png files into
individual surfaces
then adds those surfaces to a final strip surface. The problem im having is
the transparency
channel is not working correctly.
the following code loads the png files:
std::ostringstream os;
int width, height;
width = 128;
height = 128*18;
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
strip = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,rmask, gmask,
bmask, amask);
if(strip == NULL)
{
assert("ERROR: Creating a surface failed");
return false;
}
for(int i = 0; i < 11 ; i++)
{
os << "./assets/strip" << i+1 << ".png";
strips[i] = IMG_Load(os.str().c_str());
if (!strips[i])
{
assert("Surface loading failed!");
assert(IMG_GetError());
return false;
}
os.str("");
}
SDL_Rect dest,src;
src.x = 0;
src.y = 0;
src.h = 128;
src.w = 128;
dest.x = 0;
dest.h = 128;
dest.w = 128;
SDL_Surface *post;
for(int i = 0; i < 11 ; i++)
{
post = SDL_DisplayFormatAlpha(strips[i]);
dest.y = i*128;
SDL_BlitSurface(post,&src,strip, &dest);
SDL_FreeSurface(post);
}
the following displays the strip image:
void game::DrawIMG(SDL_Surface *img, int sx, int sy, int dx, int dy, int w,
int h)
{
SDL_Rect dest;
dest.x = dx;
dest.y = dy;
SDL_Rect src;
src.x = sx;
src.y = sy;
src.w = w;
src.h = h;
SDL_BlitSurface(img, &src, screen, &dest);
}
void game::DrawScroll_Vertical(float scroll)
{
int screen_w = 128;
int screen_h = 128*3;
int image_w = 128;
int image_h = 11*128;
//printf("%f %d\n",scroll,image_h-screen_h);
if(scroll>image_h-screen_h)
{
DrawIMG(strip,0,(int)(scroll), 120,60, 128,(int)((image_h)-scroll));
DrawIMG(strip,0,0, 120,(int)(((image_h)-scroll)+60),
128,(int)(screen_h-((image_h)-scroll)));
}
else
{
DrawIMG(strip,0,(int)(scroll), 120,60, screen_w,screen_h);
}
}
// Draw the scene
void game::DrawScene()
{
Uint32 white = SDL_MapRGB(screen->format, 255, 255, 255);
SDL_FillRect(screen,0,white);
DrawScroll_Vertical(scroll);
SDL_Flip(screen);
}
If i have left any detail out or I need to provide more detailed explanation
of what I am
attempting please let me know.
Thanks
Black_13_________________________________________________________________
The MSN Entertainment Guide to Golden Globes is here. Get all the scoop.
http://tv.msn.com/tv/globes2007/?icid=nctagline2