|
Drawing Lines on different backgrounds |
fatboy2
Member #8,239
January 2007
|
I am making a line using the following algorithm while(!key[KEY_ESC]) draw_sprite(buffer, bmp, 0, 0); destroy_bitmap(buffer); The problem I have is that all lines get erased every time I draw a new one. I also want to be able to draw this line on various backgrounds. Any help would be greatly appreciated. |
Kris Asick
Member #1,424
July 2001
|
The simplest way to achieve the effect you're aiming for is to use two buffers: 1. A buffer which holds what you want to show on the screen. You are effectively doing that now, but your method relies on erasing the screen every time you update the line, so naturally, when you start a new one the old one disappears because it's using the same buffer to update the new line, and erasing it on every update. So what you could do is draw the line to one buffer, draw the background buffer to the screen, then masked-blit the line buffer overtop. When you release the mouse button, you then masked-blit the line buffer onto the background buffer to make the line permanent. You can go one step further and use three buffers to eliminate any shearing which may occur as a result. Thus what you would have is: 1. A buffer which holds what you've drawn so far. If you're attempting to make a drawing program as I currently am, you're going to quickly gain an appreciation for how difficult they really are... --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
fatboy2
Member #8,239
January 2007
|
I got rid of some of the things that were unnecessary EDIT |
Lucid Nightmare
Member #5,982
July 2005
|
use 2 buffers... bitmap to scrren--> draw_sprite(screen,your buffername,0,0); Two Golden Rules of life- Firstly, I'm always right and secondly, if you think otherwise, slap your face and read rule number one again! |
Indeterminatus
Member #737
November 2000
|
Please, use the code tags, they make your posts much easier to read. You can see how by clicking on "Help" where you write the post. _______________________________ |
Neil Black
Member #7,867
October 2006
|
Thank goodness someone said something about the help tab, which I never noticed. Now I can use code tags! Yay!
|
Kris Asick
Member #1,424
July 2001
|
Here's one method that might work. Haven't tested it, only spent five minutes writing it...
I don't like that code, but it should do exactly what you want it to do. The reason I don't like it is because the method I use in my drawing program is a lot better, but about 20 times more complicated. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
fatboy2
Member #8,239
January 2007
|
Your code does not work the way I want it to because it does not have a while loop in it. With the if statement the line does not draw continuously, and as a result all i get are dots on the screen. I have tried adding an extra if statement: if(!mouse_b&1) { } This does not seem to work so please give some suggestions. EDIT: I got it, the problem is with the way I copy things from one bitmap to the other. I did not really understand the stuff written in the manual about copying functions such as blit and masked_blit. |
Kris Asick
Member #1,424
July 2001
|
Black is subjective. In 8-bit mode, palette entry #0 is almost always black, unless you change it. Thus if you change it, that becomes your new transparent colour. In 15/16/24/32-bit mode, magic pink is the transparent colour. You can make this colour by calling makecol(255,0,255). If you want transparent areas on a bitmap in higher colour depths, it needs to be that colour. To draw things onto the screen with transparent areas, you need to use masked_blit(), draw_sprite(), draw_character_ex(), or any of the other sprite-based drawing commands. I checked the code I provided by the way. It's bugged, but very easy to fix. If you move the "int initx = -999, inity = -999;" line to just before the while loop begins, it works perfectly. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
fatboy2
Member #8,239
January 2007
|
I get it now, thanks a lot. |
Kris Asick
Member #1,424
July 2001
|
Unfortunately, the mask colours are built from #define directives, which means the only way to make the transparency colour different is to create your own routine for blitting which accepts different transparency colours. Though another method is to use 32-bit, alpha blended sprites, but Allegro's routines for doing that are not the fastest. An old method for doing transparent blitting is to have two sprites, one which represents the sprite, another which represents the transparent areas called the mask. You then draw the mask to the screen using an AND binary operation and draw the sprite using an OR binary operation. Again though, Allegro doesn't have built-in features to accommodate this method of drawing. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Tobias Dammers
Member #2,604
August 2002
|
Quote: Again though, Allegro doesn't have built-in features to accommodate this method of drawing. It sort of does, using custom blenders, but I wouldn't recommend it. --- |
|