How to create Bitmaps?
fatboy2

I am trying to make an algorithm that draws lines. I am trying create a bitmap that the line will be written to and then load that bitmap to the screen. The only thing I do not know is how to make the line be written to the bitmap. I know how to create load bitmaps that are pictures but I have trouble with making a bitmap that is created using a drawing function.

Kitty Cat
fatboy2

I meant writing a drawing to a bitmap, I know how to define bitmaps and load pictures into them but I do not know to load products of real-time drawing functions into them.

Kitty Cat

I'm not sure what you're asking. create_bitmap creates a bitmap that you can draw to.

```BITMAP *bmp = create_bitmap(64, 64);
line(bmp, 0, 0, 64, 64, makecol(255, 0, 0));
...
```

axilmar
fatboy2 said:

I meant writing a drawing to a bitmap, I know how to define bitmaps and load pictures into them but I do not know to load products of real-time drawing functions into them.

You actually have to draw onto a bitmap. For example, drawing a line goes like this:

```BITMAP *bmp = create_bitmap(320, 200);
line(bmp, 0, 0, 319, 199, makecol(255, 255, 255));
```

If by 'real-time' you mean to move a line onto a bitmap, then you have to draw it and erase it in every loop, using xor mode:

```BITMAP *bmp = create_bitmap(320, 200);
int x = 0;
int y = 0;
xor_mode(true);
line(bmp, x, y, x + 319, y + 199, makecol(255, 255, 255));
while (loop) {
line(bmp, x, y, x + 319, y + 199, makecol(255, 255, 255));
x++;
line(bmp, x, y, x + 319, y + 199, makecol(255, 255, 255));
readkey();
}
```

xor mode draws stuff in such a way that the 2nd time a picture is drawn (in the same position as in the first time), it is erased.

fatboy2

Thanks for the explanation
So, I just have to change the place where I draw the line, like instead of screen I put the name of the bitmap, right?

Kauhiz

cough RTFM cough, but yes, you got it.

Dustin Dettmer

I think thats a perfectly valid questing that the fcuking manual does not answer.

LennyLen
Quote:

I think thats a perfectly valid questing that the fcuking manual does not answer.

Yeah, because the documentation for line() only says that the first parameter is the BITMAP that the line will be drawn too.

HardTranceFan

Sounds like fatboy2 isn't using double buffering, and may not be aware of drawing to a bitmap other than screen.

Dustin Dettmer

What I'm saying is there is no section that generally describes this sort of concept. If he really wanted to learn from the manual he would have to read tons and tons of functions' documentation (most of which he would not even understand) until he just happened to come across some useful information. The whole process would probably take him a week and he would just give up.

Its a conceptual question, not a syntactical one. Therefore I believe it is totally valid and the phrase "RTFM" is out of place.

LennyLen

You mean such as this part?

Quote:

Once you have selected a graphics mode, you can draw things onto the display via the `screen' bitmap. All the Allegro graphics routines draw onto BITMAP structures, which are areas of memory containing rectangular images, stored as packed byte arrays (in 8-bit modes one byte per pixel, in 15- and 16-bit modes two bytes per pixel, in 24-bit modes 3 bytes per pixel and in 32-bit modes 4 bytes per pixel). You can create and manipulate bitmaps in system RAM, or you can write to the special `screen' bitmap which represents the video memory in your graphics card.

Kauhiz
Quote:

Its a conceptual question, not a syntactical one. Therefore I believe it is totally valid and the phrase "RTFM" is out of place.

He asked the question after he was given example code that demonstrated this, though. It would have been quicker for him to confirm this by looking at the manual than it was for him to post that question. Also, I'd consider TFM to include the allegro examples, since in many cases they are as good/better than the manual. Maybe I should have said RTFMOLATFAE.

Thread #589818. Printed from Allegro.cc