I'm just trying out the allegro library, and here is the code which I've got so far:
#include <allegro.h>
int main(int argc, char *argv[]) {
allegro_init(); // initialize the allegro libraries
install_keyboard(); // initialize keyboard functions
set_color_depth(16); // set the color depth
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); // set up 640*480px window
BITMAP *pic = NULL;
pic = load_bitmap("C:/picture.bmp", NULL); // load the picture
blit(pic, screen, 0, 0, 0, 0, 1000, 1000);
readkey();
destroy_b开发者_如何学编程itmap(pic);
return 0;
}
END_OF_MAIN()
It works fine, but when I run it, while the program's window is open, Windows 7 changes the theme from Aero to Aero basic. If you aren't sure what I mean, this pops up (I got this from Google, which is why it says Vista rather than Windows 7):
(source: suitedcowboys.com)- Why?
- How can I ensure that this doesn't happen?
Aero needs color set to 32 bit, but you're setting it to 16:
set_color_depth(16);
Unless you have good reason to use a specific color depth, do this:
int cd = desktop_color_depth();
if (cd < 15) cd = 32;
set_color_depth(cd);
While generally not a problem today, many older video cards only support one of 15/16 bit and one of 24/32 bit.
If you need to use 8-bit color depth because you use a palette, then just use the GFX_GDI
driver for maximum compatibility.
精彩评论