|
Unwanted pixels showing up using masked_blit() |
Matthew Dalrymple
Member #7,922
October 2006
|
I am using masked_blit() to draw tiles to the screen. When I draw a transparent tile to the screen it leaves some unwanted pixels as you can see in the image below. There is only 9 tiles being draw from the coord (0,0). Each tile is 64x64 pixels. =-----===-----===-----= |
Ron Ofir
Member #2,357
May 2002
|
Can you show some minimal code? Something like the function that draws a tile and the loop that draws them (or whatever you used in this particular example). It seems like either draw too much, or clear your buffer twice or something. |
Matthew Dalrymple
Member #7,922
October 2006
|
Yeah here are some bits of my code
Here is the DrawToBuffer and Swap methods... ... protected: BITMAP* BackBuffer ... BOOL cScreen::DrawToBuffer(BITMAP* backbuf, int xpos, int ypos, int xdes = 0, int ydes = 0) { masked_blit(backbuf, BackBuffer, xpos, ypos, xdes, ydes, backbuf->w, backbuf->h); return TRUE; }
BOOL cScreen::Swap() { masked_blit(BackBuffer, screen, 0, 0, 0, 0, BackBuffer->w, BackBuffer->h); ClearBuffer(); return TRUE; } BOOL cScreen::ClearBuffer() { clear_to_color(BackBuffer, bitmap_mask_color(BackBuffer)); return TRUE; } If this may be helpful to you... here is some information from my tile class:
=-----===-----===-----= |
miran
Member #2,407
June 2002
|
You must not use masked_blit() when you copy the back buffer to the screen. What do you want to achieve by this anyway? Also it doesn't make sense to call vsync() after drawing the back buffer to the screen. -- |
Matthew Dalrymple
Member #7,922
October 2006
|
Well what should I use instead of masked blit? And I'm new to Allegro so I was playing with the vsync(), I didn't notice I copied that too. =-----===-----===-----= |
miran
Member #2,407
June 2002
|
Quote: Well what should I use instead of masked blit? blit() -- |
Matthew Dalrymple
Member #7,922
October 2006
|
Alright, well that was changed but had no effect on what is being seen on the screen. I heard there might be problems with making my graphics in MS Paint (Which that tile set was made in) What is another program I could use? Link? :-D =-----===-----===-----= |
miran
Member #2,407
June 2002
|
Quote: I heard there might be problems with making my graphics in MS Paint Depends on which version you have, what format you save to and how you setup the gfx mode in Allegro and load the bitmap. Quote: What is another program I could use? GIMP. Quote: Link? -- |
Matthew Dalrymple
Member #7,922
October 2006
|
Recreating the graphic in another editor didn't help. I'm still seeing red dots. =-----===-----===-----= |
miran
Member #2,407
June 2002
|
Then post a simple but complete and compilable 20 line program that shows the error and we'll tell you what you're doing wrong. -- |
James Stanley
Member #7,275
May 2006
|
Is it saved in a true bitmap format? If it is a JPEG then even though you draw magic pink from one pixel to the next, you end up with nearly magic pink. Trust me. I've done this myself. |
Kris Asick
Member #1,424
July 2001
|
Matthew, I want you to take a very close look at the screenshot you've provided by using any graphics editor and filling the black area with white. You're going to notice that not only are the leftover colours not the same as your tile, you're also going to notice FOUR different colours being left over. Each bright pixel has another one beside them. The ones beside the green pixels are a dark blue and the ones beside the red ones are very slightly green. Those colours are NOT coming from your bitmaps. So where are they coming from? First, you really need to change your naming conventions. Naming a global object "tile", another global object "Tile" and a local object in CTile "tile" is extremely confusing. Secondly, you've got a memory leak. You're calling: So that's definitely something you need to fix, but it's NOT the cause of the pixels you're seeing. Your problem has to do with how you're grabbing your tiles. Miran said you should be using blit() instead of masked_blit(). I agree, but not just for the back buffer, EVERYWHERE, except cScreen :: DrawToBuffer(), you want to leave that one as masked_blit(), or even draw_sprite() to simplify things. Think about this: When you allocate some memory nothing's in it, except possibly remnants from other things previously in memory. That's where those coloured pixels are coming from. So why aren't they disappearing when you grab your tile with CTile::GetTile()? Because you're grabbing your tile with masked_blit()! Because the tile you're trying to grab is completely transparent, masked_blit() doesn't paste anything onto your bitmap, thus it STILL has memory remnants in it! blit() ignores transparent pixels, blitting them exactly as they are. So, you have three changes you need to make: And you really should have a unique name for absolutely everything global to minimize confusion. That should solve your problems. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Richard Phipps
Member #1,632
November 2001
|
Excellent analysis Kris. |
Matthew Dalrymple
Member #7,922
October 2006
|
Yeah I fixed this problem yesterday by changing all my masked_blit()'s to regular blit()'s except for the one in my DrawToBuffer() method. This solved the problem. I will work on my naming method, I normally just call them whatever I want when I'm trying to test them out, sorry about the confusion. I need to rename my whole screen class because I've already created and fixed an error where I did this: That tried to blit to my cScreen object instead of the screen >.< dope Oh and to this: Richard Phipps said: Excellent analysis Kris. It was an "Excellent analysis" very indepth and more people should think like that. =-----===-----===-----= |
|