Jump to content

[C++] Allegro: Trying to make a simple grid


Porl123

Recommended Posts

Hi, I've been learning C++ for about 1-2 months now and I think I know enough of the basics to start using some packages like Allegro, but evidentally I don't. :( I'm just trying to make a 100x100 pixel screen with a 5 by 5 grid of images. Each image would be 20 pixels and called box.bmp

I've attempted to make this by chopping up parts of tutorials but I don't really understand why it isn't working. I just have a main function and another function which fills the grid. Here's what I've got:

 

#include <allegro.h>
BITMAP* box;
BITMAP* buffer;
int x = 0;
int y = 0;
void fillGrid()
{
     buffer = create_bitmap(100,100);
     box = load_bitmap("box.bmp", NULL);
     for(int rows = 1; rows <= 5; rows++)
     {
             for(int cols = 1; cols <= 5; cols++)
             {
                     draw_sprite(buffer,box,cols * 20,rows * 20);
             }
     }
     draw_sprite(screen,buffer,0,0);
}
int main(){
    
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT,100,100,0,0);
    fillGrid();
    return 0;
}
END_OF_MAIN();

 

If there's any chance any of you guys know how I'd do this I'd appreciate if you could give me an example or a little explanation. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/218566-c-allegro-trying-to-make-a-simple-grid/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.