SDL Forum Index
SDL
Simple DirectMedia Layer Forums
Reply to topic
Copying Source Per-Pixel Alpha to new Surface created with S
Leeor D.
Guest

Reply with quote
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.
Copying Source Per-Pixel Alpha to new Surface created with S
Jonathan Dearborn
Guest

Reply with quote
Has your Googling led you here?
http://pubpages.unh.edu/~jmb97/tutorials/blending.html

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 D


On Mon, Dec 22, 2008 at 1:33 AM, Leeor D. <leeor.net at gmail.com> wrote:

Quote:
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.

_______________________________________________
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/20081222/cb9f8b21/attachment-0001.htm>
Copying Source Per-Pixel Alpha to new Surface created with S
Andreas Schiffler
Guest

Reply with quote
There is some code in SDL_gfx - SDL_gfxBlitFunc.c: custom blitters -
which may help you.
--Andreas

Leeor D. wrote:
Quote:
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.

_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



-------------- next part --------------
A non-text attachment was scrubbed...
Name: aschiffler.vcf
Type: text/x-vcard
Size: 135 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20081222/d22a676d/attachment-0001.vcf>
Copying Source Per-Pixel Alpha to new Surface created with S
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic