Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [a5] One time Render to Target Bitmap then display Bitmap?(ex. Background Img)

This thread is locked; no one can reply to it. rss feed Print
[a5] One time Render to Target Bitmap then display Bitmap?(ex. Background Img)
Phrasz
Member #10,091
August 2008

Sorry to bug you all with such a n00bish question. (It's late... my brain isn't working)

I haven't looked at doing this since 4.2, but I used to generate a background or a static image (ex. A Chess/Checkers board) and then print that bitmap to the display vs. re-rendering each time.

1) How would I go about this in A5?

Example thoughts:

#SelectExpand
1int Rendered_Gameboard=0; 2ALLEGRO_DISPLAY *display; 3ALLEGRO_BITMAP *bg, *tile1, *tile2; 4... 5//Load BitMaps: al_load_bitmap(filename); 6... 7//Select target bitmap? 8while(RunGame){ 9 if(!Rendered_Gameboard){ 10 al_set_target_bitmap(bg); 11 // RENDER GAMEBOARD with tile1 and tile2 12 Rendered_Gameboard=1; 13 // Need to do something like al_flip()? 14 al_set_target_backbuffer(display); 15 } 16 al_draw_bitmap(bg, 0, 0, 0); 17}

2) Also can I grab the current "screen" and save it as a bitmap?

Thanks in Advance!

Arthur Kalliokoski
Second in Command
February 2005
avatar

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

Thomas Fjellstrom
Member #476
June 2000
avatar

Phrasz said:

1) How would I go about this in A5?

you'd create a bitmap, call al_set_target_bitmap, draw using allegro's api, then set the target back to the display's backbuffer.

Quote:

2) Also can I grab the current "screen" and save it as a bitmap?

If you mean your ALLEGRO_DISPLAY I think so yes. If you mean the actual screen, including the windows desktop and other apps, allegro doesn't support that.

--
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

Phrasz
Member #10,091
August 2008

Arthur thanks for that code. I was wondering about screen shots, so now it's Bookmarked :D.

Thomas: Thanks! 1) It looks like I am not completely lost! 2) I do mean the allegro display. Would I use the clipping functions? To clip the display to a bitmap?

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

Would I use the clipping functions? [alleg.sourceforge.net] To clip the display to a bitmap?

Nope.

Allegro, and the underlying 3D HW acceleration APIs have the concept of a render target. All you have to do is change the target of rendering to the new bitmap, and any rendering happens to it, rather than the display.

--
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

Phrasz
Member #10,091
August 2008

To summarize: Save it to a bitmap before you ship it to the display.

Got it!

Edit: Thanks again.... still have to try it out.

Thomas Fjellstrom
Member #476
June 2000
avatar

Phrasz said:

To summarize: Save it to a bitmap before you ship it to the display.

I thought that's what you asked. You wanted to know how to draw to a bitmap, I told you.

Now if you mean al_save_bitmap when you say "Save", no you don't need to do that.

--
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

Phrasz
Member #10,091
August 2008

Ha. Now I am just being confusing. It's is what I asked.

The 2nd case above was bass ackwards to what makes conventional sense. It's more of a case that I write a bunch on bit maps to display, and THEN decide to capture that as a bitmap. (Whereas you proposed/told to simply write to the bitmap first.)

I guess the 2nd case is akin to "Print Screen" which is then stored in a buffer. However, it's irrelevant IF you simply draw to a bitmap in the first place.

Go to: