![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
Problems with sprite transparency |
Skywhy
Member #9,243
November 2007
![]() |
I don't know where to put this question.. Having huge problems with anti-alised sprites. By default allegro uses magic pink(255,0,255) as transparent color. Ugh.. well, a picture explains more than thousand words: I tried reading the allegro manual about masked_blit and generally about transparency and patterned drawing but most of the manual stuff I didn't quite understand. So I'm kinda lookking for a good kick into the right direction and some hints and tips how to get this working. EDIT #1: So far I've always drawn my sprites on bitmap buffer with draw_sprite first then blitting it to the screen. Worked fine so far... But now, since I want SMOOTH and CLEAR sprites, I've got no clue how to make them work. Should I use some blender, draw_trans_sprite or what? So any help is welcome. Thank you. EDIT 2: Thanks everyone. |
Marco Radaelli
Member #3,028
December 2002
![]() |
Allegro transparency in 8 bit mode is "black or white", or "none or full". If you want to get more degrees of translucency you have to increase the bit depth. Call set_bit_depth() before set_gfx_mode() and before any gfx-related function, like load_bitmap() etc
|
gnolam
Member #2,030
March 2002
![]() |
Quote: Should I use some blender, draw_trans_sprite or what? Yes. For alpha transparency you need to 1) load bitmap files that actually have an alpha channel (vanilla Allegro only handles TGA, but most of us use PNG via loadpng) and 2) draw your sprites with draw_trans_sprite() after setting the alpha channel blender mode: set_alpha_blender() -- |
Skywhy
Member #9,243
November 2007
![]() |
Here is my code:
Okay, currently at work so I can't try it out. But basically *.BMP files don't have alpha channel? And ALL I need to do is start using the loadpng, make my gfx's in PNG format, and use the draw_trans_sprite to draw my sprites? Sounds bit.. well, now that I think about it sounds pretty simple. I don't know. Going to try it out later today. But anyway, thanks for the help already, I'll report back tomorrow or later today. |
Tobias Dammers
Member #2,604
August 2002
![]() |
Quote: Okay, currently at work so I can't try it out. But basically *.BMP files don't have alpha channel? No. They don't. BMP supports 8 bpp paletted images, and 24 bpp true-color. There's no room for alpha. Quote: And ALL I need to do is start using the loadpng, make my gfx's in PNG format, and use the draw_trans_sprite to draw my sprites?
Almost. Don't forget to set the alpha blender before drawing. Oh, and make sure you use a suitable color conversion mode when loading the PNGs, that is, one that doesn't convert 32 bpp to anything else (COLORCONV_NONE should work just fine). And, just to confuse you, there IS a way to do it in 8bpp, but it's hacky and requires a lot of tweaking and tuning. It works OK for some graphical styles, but not for others. --- |
X-G
Member #856
December 2000
![]() |
Quote: No. They don't. BMP supports 8 bpp paletted images, and 24 bpp true-color. There's no room for alpha. False. Later versions of the BMP format, beginning with the release of Windows XP, support 32-bit BMPs complete with alpha channel. Photoshop 7 and higher can save them, too. I don't know if Allegro can load them, though. -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
I don't suppose allegro's BMP loader has been re-written since the introduction of XP, so allegro probably can't load them. Last time I checked the source it couldn't, in any case. --- |
LordHolNapul
Member #3,619
June 2003
![]() |
I use TGA files in my videogame... TGA 32 bit exactly. |
Skywhy
Member #9,243
November 2007
![]() |
More or less interesting, this is what I thought might happen... I downloaded the libpng, loadpng and zlib and still can't get this to work. Now I'm struggling with the actual compiler. I'm getting all these neat linker errors, which basically means I've got the files pooply linked... Downloaded them through Dev-cpp's package downloader. Was the easiest way to find and install them I guess. Like I said, I have a new problem. Tried to run the example program from loadpng examples (which come with the zip file when you download it from http://tjaden.strangesoft.net/loadpng/ ) and I get linker errors: Compile log said:
Compiler: Default compiler loadpng.o(.text+0x70):loadpng.c: undefined reference to `png_get_io_ptr' loadpng.o(.text+0x191):loadpng.c: undefined reference to `png_set_packing' loadpng.o(.text+0x214):loadpng.c: undefined reference to `png_set_gray_to_rgb' loadpng.o(.text+0x253):loadpng.c: undefined reference to `png_get_sRGB' loadpng.o(.text+0x2e3):loadpng.c: undefined reference to `png_set_interlace_handling' loadpng.o(.text+0x7af):loadpng.c: undefined reference to `png_destroy_read_struct' loadpng.o(.text+0x8e1):loadpng.c: undefined reference to `png_create_info_struct' savepng.o(.text+0x12b):savepng.c: undefined reference to `png_write_row' Execution terminated ( EDIT #1: if it matters.. I'm trying to run the exalpha.c example, I added it to my project file along with loadpng.c, loadpng.h, regpng.c, savepng.c. ) gasp That's loads of errors. I'm throwing rocks at the project linking thingie, I guess I have to add more stuff into the project->project options->parameters part... But unfortunately I can't find the info needed to fix this from the readme files. |
X-G
Member #856
December 2000
![]() |
... what happened to libpng? (and libz?) -- |
Skywhy
Member #9,243
November 2007
![]() |
:3 ? Mika said: I downloaded the libpng, loadpng and zlib and still can't get this to work. I got them but ... errh... should I "somehow" link them to my project? Through the project->project options->parameters, I'm guessing but.. I'm really confused WHAT I should add there, there are like one gazillion(yeah, I admit it, I made this one up) files in the /lib folder. Tried peekking into other folders too... EDIT #1: Anyway, like I guessed, I was missing the certain libraries from my project. And now, it's solved. The library problem I mean. Tried out dozen of different libraries and finally found the right ones Added to project now: Project->Project Options->Parameters said:
-lalleg Let's see about this transparency thing now... I'll report back again when I'm done with this, did I succeed or not. And again, thanks for the patience and help. EDIT #2: Now when I leave the sprite background TRANSPARENT .. they really are transparent, so pretty. Hmm, so my question is, is this a problem? In my game the "anti-aliased graphics" are a must. I don't want to see my sprites with any jawtooth/jagged or what ever edges. I need them to be smooth. Is this the way to go? I suppose it doesn't matter if I draw the sprites with PINK background or just plain transparent? If transparent is now TRANSPARENT with these settings, I'm just going to use transparent backgrounds... and since I haven't started doing any serious spriting yet so I guess it doesn't matter, right? |
X-G
Member #856
December 2000
![]() |
Magic magenta is only used in modes that do not have alpha channels. -- |
Skywhy
Member #9,243
November 2007
![]() |
Ah ok, I'm some what confused with all the alpha channel and yada yada stuff. Need to dig the internet for more on this matter. I feel like I'm missing out something since I don't completely "get" it. But heyh, thanks everyone. Again, thank you. And further tips or such are always welcome if something happens to pop into mind. |
Tobias Dammers
Member #2,604
August 2002
![]() |
The value in the alpha channel tells you how transparent the pixel is. If the alpha value for a given pixel is at its max (255), the destination pixel is completely overwritten; if alpha is zero, the destination remains completely intact, just like with magic pink in masked blitting. Values between the two 'mix' the two colors channel-wise, i.e. the resulting red becomes src_red * alpha + dst_red * (1-alpha), and similar for green and blue. --- |
Skywhy
Member #9,243
November 2007
![]() |
Well now, facing with sprite rotating.. hmm... I'm kinda having problems with this. What's the best way to rotate those alpha channel sprites(PNG). I did a search and found this thread in the forum: http://www.allegro.cc/forums/thread/591315/670806#target Decent enough, but is there a better way? - Mika |
Evert
Member #794
November 2000
![]() |
Quote: I don't suppose allegro's BMP loader has been re-written since the introduction of XP, so allegro probably can't load them. I vaguely recall making a fix to the effect that it can some time ago. I don't know if that means it will correctly read the alpha channel, however. |
Ron Ofir
Member #2,357
May 2002
![]() |
Quote:
../../../lib/zlib.lib I think you should use -lz and -lpng instead of doing it this way, so even if you move your source files, it would still work. Try and see if it works, because I'm not sure I got the parameters right. Oh, and I think the correct order is -lalleg -lpng -lz. |
Elias
Member #358
May 2000
|
About sprite rotation, I think kazzmir proposed a function allowing that for 4.4 - not sure what became of it. An alternative would be using OpenGL rendering instead of the software primitives, with the added benefit of proper interpolation and anti-aliasing for your rotated sprites. -- |
Skywhy
Member #9,243
November 2007
![]() |
Well opengl is a bit over my head at the moment. I'm just trying to figure out how to rotate these darn things ... mrrh, BMP sprites I can rotate easily but these PNG sprites only show as black boxes after I've rotated the sprite and try to blit it to screen... Tried doing it the way it was mentioned in the other thread and having problems with that style too :/ I guess I'll have to figure out something. I think I need to rotate those darn sprites in graphics editor and then load them up or something Oh and thanks Ron Ofir, fixed that. |
Paul whoknows
Member #5,081
September 2004
![]() |
I "solved" the problem of rotating alpha sprites without OGL/D3D using pre-rendered sprites. See it. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Fladimir da Gorf
Member #1,565
October 2001
![]() |
You could always try OpenLayer (see link below) And nice to see more Finnish developers around! OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Skywhy
Member #9,243
November 2007
![]() |
Heh, thanks everyone for suggestions. Anyway, here is the code.
I didn't include the #include yada yada in the code. Like I said, it results in a black 'rotated' sprite.. I'm just trying to figure this one out. I don't want to start learning TOO MUCH for this project. The game is supposed to be pretty small anyway so... |
Ron Ofir
Member #2,357
May 2002
![]() |
Try setting the color depth to 32. And I think that clear(rot_image) statement is pretty useless, though I guess it's taken out of context or something? |
Northburns
Member #8,821
July 2007
![]() |
I tried the source you posted and made a few fixes to make it show the desired image.
And thanks Ron Ofir for pointing out the set_color_depth(), I totally missed that too. EDIT------ |
Skywhy
Member #9,243
November 2007
![]() |
What? No way! Anyway, thank you guys. It worked now. And finally.. Hahah, after a long journey, I've learned something new about simple things like linking the proper librares (how else are they supposed to work with your project.. d'uh.. it's not enough if they are in the /lib folder heh) and simple things to do with the code. I don't know what I'd do without you guys Oh yeah, and for further use, I'll paste the code in here once more so anyoe who might have wondered or is facing similiar problems might have some use for it... And the clear(); is optional? I always thought it was good thing to clear before use? I guess you'll overwrite the old stuff anyway when you write in the BITMAP *whatever... -- THANK YOU -- EDIT #1: added the whole code in one txt file to the post. if someone is having similiar problems, maybe peekking in there might help... I don't know. EDIT #2: did what I was told to ;) |
|
1
2
|