Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Quesiton about masked_blit

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Quesiton about masked_blit
ReiKo90
Member #11,139
July 2009

Hello,

I was just wondering if anyone can explain me how in fact masked_blit works?

As we already know, masked_blit eliminates background that could be in various colors and displays sprite we want to blit to the screen.

Well, I would like to show you some example as I did experiment quite a bit with this command and I cant understand how and when it "removes" background and what are the cases needed to be satasfied in order it to do so?

1st example:

When I use masked_blit on this picture: http://img27.imageshack.us/i/doggle.png/

It sucssesfuly removes pink background and shows "doggy" in black screen background. Perfect!

2nd example:

But here I got Linux "Tux" mascot, that also has pink background. When I use masked_blit with it then it dosen't remove pink background - but in fact it displays it! :( :o

Why is that so? What needs to be done with picture in order to masked_blit only show sprite itself? Another color in bitmap's background?

I did set pixel_depth(32) also but problem with "Tux" still remains.

BUT - I did solve this in a specific way:

I used "Eyedroppe tool" from Photoshop and used "specific pink" from "doggy" picture and used it on "Tux" picture as background color.

After that - masked_blit with "Tux" picture worked PERFECT!.

So my questions is in fact:

Why does masked_blit only removes specific color of background and how to manipulate it better? Should I always color my pictures with that "specific pink" in order to masked_blit remove it afterwards? How it works is right question :)

Thanks! :)

Tomoso
Member #3,128
January 2003
avatar

The pink colour must be exactly that shade of pink for masked_blit to know it shouldn't draw it. It only treats one colour (the pink) this way because it is a lot simpliar to remember one colour you cant use when drawing sprites (unless you want it to be transparent of course).

The rgb value for that pink is (255,0,255) and I think its that pink because the colour isn't used often? Not sure though, I might have made that up.

Anyway I wouldn't worry why it works, just worry that it works with that pink only :P

Lazy Noob - Blog

ReiKo90
Member #11,139
July 2009

Tomoso said:

The pink colour must be exactly that shade of pink for masked_blit to know it shouldn't draw it. It only treats one colour (the pink) this way because it is a lot simpliar to remember one colour you cant use when drawing sprites (unless you want it to be transparent of course).

The rgb value for that pink is (255,0,255) and I think its that pink because the colour isn't used often? Not sure though, I might have made that up.

Anyway I wouldn't worry why it works, just worry that it works with that pink only :P

Thanks,

Anyway, could anyone be more technical about this?

Also, when I did put "shade of pink" on background of "Tux", in my program masked_blit did remove background, but lines of "tux" bitmap did left pink colored.

Like this:
http://img132.imageshack.us/i/87703854.jpg/

What technique should I use to make most of my bitmap's background "pink shaded" so it works perfectly with masked_blit or even with draw_bitmap?

Arthur Kalliokoski
Second in Command
February 2005
avatar

Maybe this thread will help

http://www.allegro.cc/forums/thread/600895

They all watch too much MSNBC... they get ideas.

ReiKo90
Member #11,139
July 2009

That topic did help me a lot, thanks.

Anyway, I just wanted to ask - no need to open another topic:

Is there easy way to me load .PNG files with Allegro? Some stabile and easy to use library with tutorials?

I am using Microsoft Visual Studio 2008 Express edition SP1.

Thanks.

Arthur Kalliokoski
Second in Command
February 2005
avatar

They all watch too much MSNBC... they get ideas.

ReiKo90
Member #11,139
July 2009

Thanks, but can I use this library without installing libpng and zlib? Atleast basic functions like loading .PNG file and displaying it on screen?

Arthur Kalliokoski
Second in Command
February 2005
avatar

I don't see how you expect to use a "library" without something that has "lib" in the name, for example, liballeg.a or allegro.lib. And I assume zlib provides compression. It's not that hard to use them, really!

They all watch too much MSNBC... they get ideas.

ReiKo90
Member #11,139
July 2009

Well in fact it is, because I don't get .lib files with it but need to get trough process of compiling them or whatnot and to things be better - it's so on Linux side of things and there is no tutorial how to implement this on VS 2008 Express SP1 IDE.

I think I will need to learn more about libraryes and process of their implementation before I can use these things. Any tutorials that are worth studying?

Schyfis
Member #9,752
May 2008
avatar

I'm not sure what the problem is. Have you tried the libpng binaries on this page? They have them for multiple platforms if that's what you're asking.

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

ReiKo90
Member #11,139
July 2009

OK, I did try to use these libraryes and here is my test code :

#SelectExpand
1#include <allegro.h> 2#include <loadpng.h> 3#include <png.h> 4#include <zlib.h> 5 6 7 8int main() { 9 10 11 allegro_init(); 12 13 set_gfx_mode(GFX_AUTODETECT,640,480,0,0); 14 set_color_depth(32); 15 16 BITMAP*alpha; 17 18 alpha = load_png("alpha.png",0); 19 20 blit(alpha,screen,0,0,200,200,256,256); 21 22 return 0; 23 24} 25END_OF_MAIN();

I get this error:

1>Compiling...
1>Main.cpp
1>Linking...
1>LINK : C:\Users\ReiKo\Documents\Visual Studio 2008\Projects\Test3\Debug\Test3.exe not found or not built by the last incremental link; performing full link
1>Main.obj : error LNK2019: unresolved external symbol _load_png referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main@@YAHXZ)
1>C:\Users\ReiKo\Documents\Visual Studio 2008\Projects\Test3\Debug\Test3.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\ReiKo\Documents\Visual Studio 2008\Projects\Test3\Debug\BuildLog.htm"

I did link these libraryes:

alld.lib lpngce.lib zlibce.lib

Anything that I'm missing here? Maybe I should link loadpng .lib but I don't have any .lib files from that library. How to get them?

Sorry if questions are a bit stupid but I'm trying my best to learn.

Arthur Kalliokoski
Second in Command
February 2005
avatar

As far as I can see, libraries with XXXXce.lib in their name are for Windows CE, running in pocket PC's and pda devices.

They all watch too much MSNBC... they get ideas.

ReiKo90
Member #11,139
July 2009

Oh...I see, because I couldn't find libraryes for my platform as "Schyfis" said, there is only:

HP-UX
Linux
Solaris

I don't see any of them for Windows... maybe I should get Linux one and try it out? Or compile Linux one? It seems that getting this thing to work on Windows platfrom is not so easy or am I wrong?

Thanks.

Schyfis
Member #9,752
May 2008
avatar

It looks like nobody has compiled the latest version for Windows and put it online. You can either try compiling it or get the previous version (1.2.37) for Windows. I'm not sure what the changes are between the versions, the site doesn't seem to have a changelog.

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

Arthur Kalliokoski
Second in Command
February 2005
avatar

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

Arhur, your link is broken.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Arthur Kalliokoski
Second in Command
February 2005
avatar

Works for me ???

The stuff in the Google search box is
libpng msvc 8

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

Doesn't work here at all.

this however is the correct link: http://www.google.com/search?hl=en&q=libpng+msvc+8&aq=f&oq=&aqi=&fp=VEE02fthf5k

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

ReiKo90
Member #11,139
July 2009

Thanks on the link, currently I'm trying to compile dll's from "loadpng" library, I did include like it said "zdll.dll" and "libpng.dll" libraryes but I get this error:

1>LINK : fatal error LNK1561: entry point must be defined

I also did linked adll.lib from Allegro library.

I sense I'm close but some part of puzzle is missing ??? :)

Arthur Kalliokoski
Second in Command
February 2005
avatar

Your link gives me a blank white screen...

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

you need to somehow tell MSVC that you're creating a library when you're building zlib and libpng.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Leverton
Supreme Loser
January 1999
avatar

Both of those libraries come with MSVC project files that work.

Thomas Fjellstrom
Member #476
June 2000
avatar

Both of those libraries come with MSVC project files that work.

Not well enough it seems ;)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Arthur Kalliokoski
Second in Command
February 2005
avatar

I've seen a thing in MSVC 8 that claims to convert MSVC 6 project files (which are listed in the libpng page), but I've never tried it.

They all watch too much MSNBC... they get ideas.

ReiKo90
Member #11,139
July 2009

you need to somehow tell MSVC that you're creating a library when you're building zlib and libpng.

Great hint, now I'm on right track, I did sucsessfuly(altough with 5 warnings) compiled loadpng library.

 1   2 


Go to: