Hallo.
It’s probably mine misunderstanding of docs, but I have troubles with
creating surface with some alpha pixels and bliting it to screen.
I’ll reduce chit-chat to source code, if you don’t mind. Strip down to it
basis, code looks like this:
/* CODE */
// Set mode
pScreen = SDL_SetVideoMode(1024,768,32, SDL_HWSURFACE | SDL_HWPALETTE |
SDL_DOUBLEBUF);
// Load one big png with all game sprites
pSprites = IMG_Load(“MyAllSpriteImageWithTrasparentChannel.png”);
// Create single sprite surface
// I want to use alpha channel when bliting from this surface
(SDL_SRCALPHA).
// pSprites->format->Amask != 0
pSprite = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, SPR_WIDTH,
SPR_HEIGHT, pSprites->format->BitsPerPixel, pSprites->format->Rmask,
pSprites->format->Gmask, pSprites->format->Bmask, pSprites->format->Amask);
// Select region from all_game_sprites surface and blit it to single sprite
SDL_Rect clipRect;
clipRect = …;
SDL_BlitSurface(pSprites,&clipRect,pSprite,NULL);
// HERE I PLAN TO APPLY SOME TRANSFORMATIONS
// … rotate sprite, create stains (sprites are pieces of wood)
// … but for now its nop
// Blit to screen
SDL_BlitSurface(pSprite,NULL,pScreen);
/* EDOC */
… problem is that nothing is blit. I wanted to draw to screen as written
in SDL docs SDL_BlitSurface:
“
if (source surface has SDL_SRCALPHA set)
if (source surface has alpha channel (that is, format->Amask != 0))
blit using per-pixel alpha, ignoring any color key
”
When I set Amask to 0 image sprite is blited correctly but w/o alpha channel
I can’t use color keys, because sprite image have more than 1 bit alpha
channel and I want to keep it (frame rate is not crucial for me).
Imho this note from SDL docs SDL_SetAlpha applies to my case. But hell… I
don’t understand it;-(
"
Note that RGBA->RGBA blits (with SDL_SRCALPHA set) keep the alpha of the
destination surface. This means that you cannot compose two arbitrary RGBA
surfaces this way and get the result you would expect from “overlaying"
them; the destination alpha will work as a mask.
”
Thank you very much for advice.
Best regards
Adam
PS: if this message comes twice sry, i m just noob :-(–
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.2.1/279 - Release Date: 10. 3. 2006