I’ve done a number of google searches and read the documentation about
SDL_BlitSurface(), SDL_SetAlpha(), SDL_CreateRGBSurface(), SDL_GetRGBA() and
SDL_MapRGBA. So far I haven’t come up with any clear answers and have gone
through dozens of pages of text, some not even C/C++ code.
Here’s the problem I’m having.
I have one surface that I load up using IMG_Load() – no problems there. Per-
Pixel alpha turns up normally as expected. Whoopdeedoo – never had a problem
with that.
Now, I want to break up that image into smaller pieces so I can arrange them
however I want. So, I use SDL_Surface *surface = SDL_CreateRGBSurface(…) to
create a surface of the correct size. I then blit the area from the larger
image that I need into the smaller image. No problems with that either.
But, it’s clear that the surface I’m creating gets initialized to all black
with no per-pixel alpha values.
How can I copy the per-pixel alpha values from the source image to the
destination image?
My first thought was to use SDL_SetAlpha – but naturally that doesn’t work
properly. That’s when I looked around and found that this is apparently a very
common question but there seem to be no clear answers.
Is there a simple way to do this or will I have to come up with a function to
read per-pixel alpha values from the source and write them to the destination?
Am I just making this far more difficult than it really needs to be?
Thanks for taking the time to read over this message.
If you’re looking to copy the alpha channel, you have to disable
alpha-blending using SDL_SetAlpha(surface, 0, surface->format->alpha), blit
it, then re-enable it SDL_SetAlpha(newSurface, SDL_SRCALPHA,
newSurface->format->alpha).
Jonny DOn Mon, Dec 22, 2008 at 1:33 AM, Leeor D. <leeor.net at gmail.com> wrote:
I’ve done a number of google searches and read the documentation about
SDL_BlitSurface(), SDL_SetAlpha(), SDL_CreateRGBSurface(), SDL_GetRGBA()
and
SDL_MapRGBA. So far I haven’t come up with any clear answers and have gone
through dozens of pages of text, some not even C/C++ code.
Here’s the problem I’m having.
I have one surface that I load up using IMG_Load() – no problems there.
Per-
Pixel alpha turns up normally as expected. Whoopdeedoo – never had a
problem
with that.
Now, I want to break up that image into smaller pieces so I can arrange
them
however I want. So, I use SDL_Surface *surface = SDL_CreateRGBSurface(…)
to
create a surface of the correct size. I then blit the area from the larger
image that I need into the smaller image. No problems with that either.
But, it’s clear that the surface I’m creating gets initialized to all black
with no per-pixel alpha values.
How can I copy the per-pixel alpha values from the source image to the
destination image?
My first thought was to use SDL_SetAlpha – but naturally that doesn’t work
properly. That’s when I looked around and found that this is apparently a
very
common question but there seem to be no clear answers.
Is there a simple way to do this or will I have to come up with a function
to
read per-pixel alpha values from the source and write them to the
destination?
Am I just making this far more difficult than it really needs to be?
Thanks for taking the time to read over this message.
There is some code in SDL_gfx - SDL_gfxBlitFunc.c: custom blitters -
which may help you.
–Andreas
Leeor D. wrote:
I’ve done a number of google searches and read the documentation about
SDL_BlitSurface(), SDL_SetAlpha(), SDL_CreateRGBSurface(), SDL_GetRGBA() and
SDL_MapRGBA. So far I haven’t come up with any clear answers and have gone
through dozens of pages of text, some not even C/C++ code.
Here’s the problem I’m having.
I have one surface that I load up using IMG_Load() – no problems there. Per-
Pixel alpha turns up normally as expected. Whoopdeedoo – never had a problem
with that.
Now, I want to break up that image into smaller pieces so I can arrange them
however I want. So, I use SDL_Surface *surface = SDL_CreateRGBSurface(…) to
create a surface of the correct size. I then blit the area from the larger
image that I need into the smaller image. No problems with that either.
But, it’s clear that the surface I’m creating gets initialized to all black
with no per-pixel alpha values.
How can I copy the per-pixel alpha values from the source image to the
destination image?
My first thought was to use SDL_SetAlpha – but naturally that doesn’t work
properly. That’s when I looked around and found that this is apparently a very
common question but there seem to be no clear answers.
Is there a simple way to do this or will I have to come up with a function to
read per-pixel alpha values from the source and write them to the destination?
Am I just making this far more difficult than it really needs to be?
Thanks for taking the time to read over this message.