Need a Win32 bitmap transparency example
I need a code example on how to make a bitmap transparent for the bitmaped background behind it. I am using C++/Win32 only in this project. Thanks.
Isn't that one supposed to have some bug or something or only work on win 98 and higher ? I mean when using GDI I think you should really support win 95 unless you use .net
Quote:Original post by philvaira
I need a code example on how to make a bitmap transparent for the bitmaped background behind it. I am using C++/Win32 only in this project. Thanks.
Quote:
Animation Part3
Author: DigiBen
This tutorial shows how to create your own "transparency blit" function.
Functions Used: SelectObject(), ShowCursor(), CreateCompatibleBitmap(), CreateCompatibleDC(), GetDC(), GetClientRect(), CreateDIBSection(), BitBlt(), malloc(), free()
Download: .NET
Here you go. I hope it is what you asked and are looking for. If not let me know.
- Drew
Drew
Thanks for the link. The tutorial was very informative although confusing at some points(e.g. I think I woulda made this a little easier to understand:
int yPos = pSprite->currentFrame * pSprite->height + 1 + pSprite->currentFrame + ((pSprite->lastFrame + 1) * pSprite->state) +
(pSprite->state * ((pSprite->lastFrame + 1) * pSprite->height));
Made my head hurt trying to figure out how he did that. The one thing I wanted to ask was why the animation didn't wrap when you went off the left side of the screen. I think it is because of this line:
SetSpritePosition(pSprite, (pSprite->position.x - pSprite->speed.x) % WIDTH, pSprite->position.y);
I'm guessing that when you go offscreen the x values are negative and using modulus on a negative number isn't producing the desired effect.
Thanks for the link. The tutorial was very informative although confusing at some points(e.g. I think I woulda made this a little easier to understand:
int yPos = pSprite->currentFrame * pSprite->height + 1 + pSprite->currentFrame + ((pSprite->lastFrame + 1) * pSprite->state) +
(pSprite->state * ((pSprite->lastFrame + 1) * pSprite->height));
Made my head hurt trying to figure out how he did that. The one thing I wanted to ask was why the animation didn't wrap when you went off the left side of the screen. I think it is because of this line:
SetSpritePosition(pSprite, (pSprite->position.x - pSprite->speed.x) % WIDTH, pSprite->position.y);
I'm guessing that when you go offscreen the x values are negative and using modulus on a negative number isn't producing the desired effect.
Quote:Original post by HughG
Drew
Thanks for the link. The tutorial was very informative although confusing at some points(e.g. I think I woulda made this a little easier to understand:
int yPos = pSprite->currentFrame * pSprite->height + 1 + pSprite->currentFrame + ((pSprite->lastFrame + 1) * pSprite->state) +
(pSprite->state * ((pSprite->lastFrame + 1) * pSprite->height));
Made my head hurt trying to figure out how he did that. The one thing I wanted to ask was why the animation didn't wrap when you went off the left side of the screen. I think it is because of this line:
SetSpritePosition(pSprite, (pSprite->position.x - pSprite->speed.x) % WIDTH, pSprite->position.y);
I'm guessing that when you go offscreen the x values are negative and using modulus on a negative number isn't producing the desired effect.
No problem! Now I have to agree with you on the simplicity of this tutorial...but hey it works [smile].
The reason it does not loop to the other side of the screen is because there is no special code to make it. Right now it is setup in a standard way - if you start something one way it will continue moving that way until you make it change directions or it hit some obstacle. You would have to test if the
( img_position - img_width/2 ) > screen_wdith then set the position to
{ img_width/2 } or test
( img_pos == -img_width/2 ) then set position to { screen_width - img_width/2 }
This is all assuming the position is relitive to the center of the graphic - Im not sure how it is in the tutorial, but you should be able to get the idea.
Thanks, but nothing has worked so far besides linking errors with TransparentBlt(). Not sure why.
To be able to link to TransparentBlt i think you have to specify a compiler option: WINVER = 0x0410 since TransparentBlt is only available in Win98 up and Win2000 up.
Just to restate the info again: It won't work in NT/95 and it has a memory leak in 98. This shows an alternative method.
Just to restate the info again: It won't work in NT/95 and it has a memory leak in 98. This shows an alternative method.
Thanks. I looked at it earlier and it seemed too technical to me for a simple thing. However, Win32 is known for that.
// Paint Current Ball Position onto Back Buffer
SelectObject(obj_dc, bmpBall);
BitBlt(back_dc, ball_x, ball_y, ball_cx, ball_cy, obj_dc, 0, 0, SRCPAINT);
This works, but I can see through the bitmap and onto the background image. The whole image is transparent, but it takes away the black color around the ball image which is good. There's no way to make the ball image solid with this simple code?
// Paint Current Ball Position onto Back Buffer
SelectObject(obj_dc, bmpBall);
BitBlt(back_dc, ball_x, ball_y, ball_cx, ball_cy, obj_dc, 0, 0, SRCPAINT);
This works, but I can see through the bitmap and onto the background image. The whole image is transparent, but it takes away the black color around the ball image which is good. There's no way to make the ball image solid with this simple code?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement