Sign in to follow this  

SDL Alpha Help

This topic is 3851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I decided this would best be placed in a separate thread. Can anyone give me some quick example code and an image that I can load using SDL_Image showing how to use the alpha in a png image. Thanks.

Share this post


Link to post
Share on other sites
I believe that you set the alpha value IN the png, and using a lib like SDL_Image it should just automatically use the transparent value...


Basically PNGs have alpha channels, and it is my belief that if you use SDL_Image it should automatically load and use the alpha channel accordingly... test it out :)

So for whatever program you are using to create your pngs, look up how-to save alpha channels.

Share this post


Link to post
Share on other sites
Uh, they aren't too tough to make. I suggest using Paint.NET for it. Just make a new PNG, select it's background, press delete then draw a line or something on it. Save, then load the file in your program. Viola! It'll be a line on a transparent background.

Share this post


Link to post
Share on other sites
Guys, I'm desperate. I'm using ubuntu feisty to compile. I think it might be a bug in sdl_image or libpng12. The alpha values on the png's won't load! I'm sure the image's alpha work (the transparencies show up in gimp and a number of other programs).

Is there anyone that can confirm that sdl_image doesn't load the transparencies under ubuntu?

thanks



Share this post


Link to post
Share on other sites
Quote:
Original post by kev000
Guys, I'm desperate. I'm using ubuntu feisty to compile. I think it might be a bug in sdl_image or libpng12. The alpha values on the png's won't load! I'm sure the image's alpha work (the transparencies show up in gimp and a number of other programs).

Is there anyone that can confirm that sdl_image doesn't load the transparencies under ubuntu?

thanks


I don't have any experience with ubuntu, but I don't see why it wouldn't work.

It might be an idea to show us some code. Are you checking that the image has actually loaded? What do you do with the image after loading to blit it to the screen?

(And just a guess without seeing any code, but what happens if you use SDL_SetAlpha(surface,0,0); where surface is the SDL_Surface * that you loaded, before you blit it.)

Share this post


Link to post
Share on other sites
The SDL_SetAlpha(tempsurf,0,0); does nothing. What is that function supposed to do anyway?

Here is some relevant code:

From the buttonclass::create():

SDL_Surface* loadedImage = NULL, *tempsurf = NULL;
loadedImage = IMG_Load( srcfile.c_str() );
if( loadedImage != NULL )
{
tempsurf=SDL_DisplayFormat( loadedImage );
SDL_FreeSurface( loadedImage );
}
else
{
sdlnerror::errorCreatingButton( srcfile.c_str() );
return -1;
}

Then tempsurf is passed into surfaceClass:

mysurface.init(tempsurf,area,0);
void surfaceClass::init(SDL_Surface *s, SDL_Rect a, int nalpha)
{
myarea = a;
if(s==NULL)
{
//sdlnerror::errorLoading( "Error loading surface, blitting disabled." );
visibility=0;
mysurface=NULL;
}
else
{
mysurface = s;
myarea.w = mysurface->w;
myarea.h = mysurface->h;
}
alpha=nalpha;
visibility=1;
}

The display function from surfaceClass::displayMe():

int surfaceClass::displayMe( SDL_Surface *target)
{
if(visibility)
{
if(mysurface != NULL)
SDL_BlitSurface(mysurface,NULL,target,&myarea);
//else nerror::out("surface is null cannot blit");
}
//ndebug::out("surface is not visible. not displaying",3);
//mysurface is the image surface, and target is the screen.
}

Am I doing anything that would make the png's alpha values nullified?

Share this post


Link to post
Share on other sites

This topic is 3851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this