views:

273

answers:

2

Hi SO,

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_bitmap(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):

http://www.suitedcowboys.com/wp-content/uploads/2007/01/010607_0906_HelloVistai28.png

1) Why? 2) How can I ensure that this doesn't happen?

+5  A: 

Aero needs color set to 32 bit, but you're setting it to 16:

set_color_depth(16);

Brendan Long
I love simple solutions. :) Thanks for the speedy answer. Will this impact the programs cross-platform capabilities though? According to the tutorial I'm following it does, but it does look pretty old.
Matt H
What platforms use 16-bit color depth today? Most have 24 or 32.
jpyllman
jpyllman: Have you ever used RDP (Terminal Services) over a remote connection? I regularly use it at 8-bit color. It's also common for people to run VMs at lower bit depths because the hardware is easier to emulate.
Gabe
konforce's answer shows how to use the current color depth. Not much I can add.
Brendan Long
+2  A: 

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.

konforce