Before you post that god damn link in my face again, let me tell you that I don't understand what the hell its all about. So refrain from posting that little link that has absolutely no help, and EXPLAIN IN LAMENS TERMS HOW TO REPLACE TRANSPARENT COLORS USING BITBLT. Im using magenta and i want to replace it with the background tile. its an image over an image.
I have no clue how to do this. When you try making a mask, it doesnt work. Right?
The reason is that the mask will only work if the white pixels in the mask are black pixels on the sprite. So that means that the transparent colour must be black in addition to having a mask. This stuck me for about half a year, it was very confusing.
I hope you learned from my mistakes.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
This is crazy. I need to know how to do transparencies. I KNOW its possible. I've seen it done. I just cant extract the subs from the source because its too complicated and webs throughout the entire project.
Here's a very simple example of how to do transparency. In the original picture, if the background is white, in the mask the background must be black, and all other stuff must be white...
what do you mean without the squareness around it? take the border off of the 3rd picture box, and you won't be able to tell it's square.
There is no need for obscenities you ****ing ****, we were all just trying to help you. Maybe we would serve you better if we could understand your moronic interpretation of the english language.
AND DON'T TYPE IN ALL CAPS, IT IS REALLY ANNOYING!
First you say you want to replace transparent colors using BitBlt, then you say you need to know how to "do" transparencies, whatever the **** that means. Then you say you need the "squareness" removed from an image... Every time you post, you request something different, and expect us to cater to your every whim?
Would you please type, and think slower so we can understand what you are trying to say?
If you would've just fooled around with my project, a little bit, you would have found it did just that.... enlarge the 3rd picture box and color the background blue.. run the program, and you get a red blob inside a blue Picture Box....
No offense, but insulting people is not the way to get them to help you. You're d@mn lucky that people are responding to you at all anymore.
You want an explaination? Fine, here, but you better start being more civil.
If your mask has white in the "transparent" parts and your picture has black in the "transparent" parts:
1. Bitblt the mask onto the image using the "vbSrcAnd" RasterOp. This will turn a section of your background totally black. These solid black pixels will be the ones to which the image will be painted.
2. Bitblt the picture onto the image using the "vbSrcPaint" RasterOp. All non-black pixels will combined into the image... black pixels will stay black ;-)
If your mask AND picture both have white in the "transparent Parts", you must change the RasterOps slightly:
1. Bitblt the mask using "vbMergePaint". This will turn part of the background totally white.
2. Bitblt the mask using "vbSrcAnd". This will paint the picture into the white area of the background.
Getting angry with the people who are trying to help you is not an effective means of getting what you want. :-(
As for using magenta as your "transparent" color, I would suggest that you create the mask based on that color, remove the transparent color, and then use one of the abovementioned methods.
To create the mask/remove the color, use something like this:
Dim x As Long, y As Long
For y = 0 To nHeight
For x = 0 To nWidth
SetPixel maskDC, x, y, IIf(GetPixel(hSrcDC, x, y) = lTransColor, vbWhite, vbBlack)
Next x
Next y
Where SetPixel() and GetPixel() are declared as
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
-Hand out
Last edited by The Hand; Jul 2nd, 2001 at 09:15 AM.
Visit EliteVB for slimy subclassing tricks and GDI32 goodness.
Well ive seen the stuff to this other matrix game, and its got images with just magenta backgrounds- nothing else. How do they do this? I still dont fully understand.
Probably because progeix taught me BitBlt and he's only 14 years old :P
Well then try different combinations instead of AND and PAINT. Try PAINT and then AND. Try INVERT and then AND. Try INVERT and then PAINT. Try PAINT and then MERGEPAINT. Try INVERT and then MERGEPAINT...
Just tell us what works for future refrence.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
I just re-discovered something I saw previously but totally forgot:
There is a TransparentBlt function for Windows98/2000. Its contained in a DLL called "msimg32.dll". If you have this on your PC, you should be able to use the function. Included in this dll are also methods for AlphaBlending & Gradient Filling!!!!
the TransparentBlt function is declared as:
Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
If you want a good example, go to www.allapi.com and download their API guide. It also has an example for the "AlphaBlend" function.
While this DLL supposedly only comes with Win98/2000, I have written small test programs and copied/installed that DLL to the test machine; it worked just fine under NT and 95 as well.
-Hand out
Last edited by The Hand; Jul 3rd, 2001 at 01:56 PM.
Visit EliteVB for slimy subclassing tricks and GDI32 goodness.
Originally posted by denniswrenn It supposedly 'causes bad memory leaks
EEEEEEEEEEEEeeeeeeeeeeeeeeeek! <Runs screaming>
Not that I didn't believe you, but I confirmed the memory leak. Just did the example prog that comes for TransparentBlt with the AllApi guide, and just called TransparentBlt every 100 milliseconds. Within 5 seconds my resources were critically low. I was just blting from one Picturebox hDC to another, so I know it has nothing to do with cleaning up handles/resources.
That's no good. How about the AlphaBlend function? Any problems with that? I haven't used either one >>EVER<< but I did think about using AlphaBlend in my next project...
Thanks!
-Hand out
Last edited by The Hand; Jul 3rd, 2001 at 02:35 PM.
Visit EliteVB for slimy subclassing tricks and GDI32 goodness.
In about 2 years it will be okay to use. It's because Win95 doesn't support it. You can get around this with DDraw/D3D. But if you want Win95 users to miss out be my guest.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Originally posted by Sastraxi In about 2 years it will be okay to use. It's because Win95 doesn't support it. You can get around this with DDraw/D3D. But if you want Win95 users to miss out be my guest.
They won't miss out if I distribute msimg32.dll with my apps... but I don't think I wanna include a DLL w/ a known memory leak
-Hand out
Visit EliteVB for slimy subclassing tricks and GDI32 goodness.
In lack of decent API's why don't you code them yourself?
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
well transparency is one of the slowest possible 2D things... Even on my Voodoo5 5500 it slows down to critical framerate in 3D games if there's many transparent polygons on screen
Well if you can use HAL (even windowed) it's fast enough, and rotations of course too... as long as you aren't in ASM that's the best you can do.
As for the AlphaBlend function, I know how to do it on a pixelwise basis, but that takes REALLY REALLY long for large pics.
You could get reasonable framerate if you alphablend in small scale, most games that have 2d alphablending don't alphablend more than 5% of the screen at a time.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
With Directdraw, you can get some DMA with an array as a pointer... Not really a pointer but it kind of is. You can change the colour bits pretty fast although it's slow compared to the Win98/2k alphablend function.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Well, what I really need is a way to multiply an array of integers by the same number quickly.
I'm not talking about a "For i = 1 to Ubound: Next i" type thing... I'm talking about a CopyMemory type thing.
If I could multiply every number in an array by something with one or two (Or even 10) API steps and avoid looping thru the pixels, I could easily code my own alphablend function.
Oh well.
-Hand out
Visit EliteVB for slimy subclassing tricks and GDI32 goodness.
Originally posted by The Hand Well, what I really need is a way to multiply an array of integers by the same number quickly.
I'm not talking about a "For i = 1 to Ubound: Next i" type thing... I'm talking about a CopyMemory type thing.
If I could multiply every number in an array by something with one or two (Or even 10) API steps and avoid looping thru the pixels, I could easily code my own alphablend function.
Oh well.
-Hand out
You do know what CopyMemory does do you? It loops from the first to the last byte and assigns it to another range. It's no kind of "magic" behind CopyMemory or Bitblt as lot's of people out here think. It's correct that it is easy to do, but you won't accomplish speedy alpha blend without C++ or even preferable ASM.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Originally posted by kedaman It's no kind of "magic" behind CopyMemory or Bitblt as lot's of people out here think.
There's no such thing as magic, just an incredible desire to do the impossible which makes it realization...
Yeah, I know how CopyMemory and Bitblt work, however they are standard API routines which were written in C++ or ASM... and therefore available to all machines. I don't want to have to write my own DLL because that's just one more thing to distribute with my code... I could just as easily distribute that red-headed stepchild msimg32.dll
I was hoping there was a standard API call to multiply everything in an array by a scalar... maybe something in Kernel32 or User32, but if not... guess I'll just have to forget about it. Being a standard API call, it would already be on all my users' machines and would be (hopefully) already optimized for speed.
I should have taken the opportunity to learn ASM years ago, but I'm too old now to learn... old dog/new tricks, ya know
Later,
-Hand out
Visit EliteVB for slimy subclassing tricks and GDI32 goodness.
Originally posted by The Hand
I was hoping there was a standard API call to multiply everything in an array by a scalar... maybe something in Kernel32 or User32, but if not... guess I'll just have to forget about it. Being a standard API call, it would already be on all my users' machines and would be (hopefully) already optimized for speed.
Standard api calls for paranoid vb-programmers. I don't think so I'm extreemly paranoid programmer myself so I know what you are feeling but also know what you should do to it by now.
"One more thing to distribute with my executable" i've heard this so many times i'm sick of it. If your files are part of your application, not any public api's, then they won't be in the way of the user, besides c++ dll's aren't entered into registry unlike activeX ones.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
What you could do is like Sentience does, it automatically generates the masks when you run the "RunMeFirstToInstall.exe" or whatever
Anyway, if you're still interested in alpha blend... look in my signature <cough cough>
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
masks? that automatically doubles the amount of memory allocated for sprites + doubles the amount of time by performing 2 blit's And hehe, in case you use jotaf's alphablend, it automatically quadrouples both memory and time j/k i haven't checked it out, but with most certainity it is
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.