trouble loading bitmaps in allegro

This is a discussion on trouble loading bitmaps in allegro within the Game Programming forums, part of the General Programming Boards category; heres my code it currently allows you to move a circle around the screen but i want to replace the ...

  1. #1
    bobish
    Guest

    trouble loading bitmaps in allegro

    heres my code it currently allows you to move a circle around the screen but i want to replace the circle with a bitmap image

    #define left 1
    #define right 2
    #define up 3
    #define down 4
    #define UpandLeft 5
    #define DownandLeft 6
    #define UpandRight 7
    #define DownandRight 8

    #include <stdio.h>
    #include <allegro.h>

    PALETTE *Pal;
    BITMAP *ImageBuffer;

    int main(void)
    {
    BITMAP *dblbuffer;

    int x=100;
    int y=100;
    int lastkeypressed=0;
    allegro_init();

    install_keyboard();
    install_timer(); /* needed for `rest' function */

    // set_color_depth(24);
    if (set_gfx_mode(GFX_SAFE, 800, 600, 0, 0) < 0)
    {
    printf("%s\n", allegro_error);
    exit(1);
    }

    clear(screen);

    // Pay attention!!! We HAVE to allocate memory for our memory bitmap
    dblbuffer = create_bitmap(SCREEN_W, SCREEN_H);
    clear(dblbuffer);

    ImageBuffer = load_bmp("Eric.bmp", Pal);

    while(1)// main loop
    {
    /////////////////// input
    if (key[KEY_LEFT])
    {
    x--;
    lastkeypressed=left;
    }

    if (key[KEY_RIGHT])
    {
    x++;
    lastkeypressed=right;
    }

    if (key[KEY_UP])
    {
    y--;
    lastkeypressed=up;
    }

    if (key[KEY_DOWN])
    {
    y++;
    lastkeypressed=down;
    }

    if (key[KEY_LEFT] && key[KEY_UP])
    {
    lastkeypressed=UpandLeft;
    }

    if (key[KEY_LEFT] && key[KEY_DOWN])
    {
    lastkeypressed=DownandLeft;
    }

    if (key[KEY_RIGHT] && key[KEY_UP])
    {
    lastkeypressed=UpandRight;
    }

    if (key[KEY_RIGHT] && key[KEY_DOWN])
    {
    lastkeypressed=DownandRight;
    }

    //////////////////output


    if (lastkeypressed=right)
    {
    circlefill(dblbuffer, x - 1 , y , 50, makecol(000,000,000)); /* erase from last place */
    }

    if (lastkeypressed=left)
    {
    circlefill(dblbuffer, x + 1 , y , 50, makecol(000,000,000)); /* erase from last place */
    }

    if (lastkeypressed=up)
    {
    circlefill(dblbuffer, x , y + 1, 50, makecol(000,000,000)); /* erase from last place */
    }

    if (lastkeypressed=down)
    {
    circlefill(dblbuffer, x , y - 1, 50, makecol(000,000,000)); /* erase from last place */
    }

    if (lastkeypressed=UpandLeft)
    {
    circlefill(dblbuffer, x + 1 , y + 1, 50, makecol(000,000,000)); /* erase from last place */
    }

    if (lastkeypressed=DownandLeft)
    {
    circlefill(dblbuffer, x + 1 , y - 1, 50, makecol(000,000,000)); /* erase from last place */
    }

    if (lastkeypressed=UpandRight)
    {
    circlefill(dblbuffer, x - 1 , y + 1, 50, makecol(000,000,000)); /* erase from last place */
    }

    if (lastkeypressed=DownandRight)
    {
    circlefill(dblbuffer, x - 1 , y - 1, 50, makecol(000,000,000)); /* erase from last place */
    }

    circlefill(dblbuffer, x , y, 50, makecol(255,255,255)); /* redraw at new place */

    vsync();
    blit(dblbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);


    if (key[KEY_ESC])//clean up and quit
    {
    // Now, remember to FREE the memory you previously allocated
    destroy_bitmap(dblbuffer);
    exit(1);
    }
    }
    return 0;
    }
    END_OF_MAIN();

    heres the warnings i got:41) : warning C4047: 'function' : 'struct RGB *' differs in levels of indirection from 'struct RGB (*)[256]'
    and
    41) : warning C4024: 'load_bmp' : different types for formal and actual parameter 2

    also set color depth seems to make the program windowed is there anyway i can stop that and lastly is anyone have anyrecomendations for improving my code. im using msvc++6.0 windows ME and allegro 4.00

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    ImageBuffer = load_bmp("Eric.bmp", Pal);
    Should be changed to:

    ImageBuffer = load_bmp("Eric.bmp", &Pal);

    If your video card does not support 24 bit graphics, it will change to 32 bit graphics with an emulated 24 bit graphics window. Just change set_color_depth(24); to set_color_depth(32); or set_color_depth(16); to ensure it is full screen (also you can use the GFX_AUTODETECT_FULLSCREEN parameter in set_gfx_mode(...) to make sure you get an error if it can't do it full screen - instead of using a windowed screen).

    The lines:

    dblbuffer = create_bitmap(SCREEN_W, SCREEN_H);
    clear(dblbuffer);

    is not necessary because you use load_bmp on dblbuffer, which allocates your memory for you anyway.

    Well, that should be about it for now. Hope it helps.

    -Justin
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  3. #3
    Bobish
    Guest
    if thats the case then should i use 32 bit tga files instead of 24 bit bmp files or does it not really matter (the thing is converting files out of their normal format seems like a waste to me)

  4. #4
    bobish
    Guest
    oh and how do i make those annying warning messages go away (and i don't mean tell the compiler to ignore them)

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    Color depths are downward compatible. 32 will use 24 bit bitmaps just fine. 16 bit mode with 24 bit bitmap will attempt to convert right, but may look a bit strange depending upon the colors used.

    What are the warning messages? I don't usually get any. (edit: PS, I'm going to be gone for the next week, so sorry if I don't respond for a while again.)
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  6. #6
    Bobish
    Guest
    well still don't know whats wrong and id like to add that if I try to load two bitmaps the program won't even run

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    What are the errors (or warnings)? What exactly happens when you load a second picture? Is that where it is crashing, or when you use it? Please post a snippet of that code.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  8. #8
    Unregistered
    Guest
    heres the warnings

    --------------------Configuration: allegrotest - Win32 Debug--------------------
    Compiling...
    test.c
    c:\programming stuff\allegrotest\test.c(53) : warning C4047: 'function' : 'struct RGB *' differs in levels of indirection from 'struct RGB (** )[256]'
    c:\programming stuff\allegrotest\test.c(53) : warning C4024: 'load_bmp' : different types for formal and actual parameter 2
    c:\programming stuff\allegrotest\test.c(54) : warning C4047: 'function' : 'struct RGB *' differs in levels of indirection from 'struct RGB (** )[256]'
    c:\programming stuff\allegrotest\test.c(54) : warning C4024: 'load_bmp' : different types for formal and actual parameter 2
    Linking...

    allegrotest.exe - 0 error(s), 4 warning(s)

    note that since my code has changed the line numbers mentioned are differn't then in the posted code

    ImageBuffer = load_bmp("Eric.bmp", &Pal); is where the first on is occuring though

    and i solved the problem, with loading two bitmaps I hadent relized u need one pallet per bitmap.

  9. #9
    Bobish
    Guest
    oh sorry that last post was me

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    OK, here's a better way to do the Pal thing. Please forgive the somewhat erronious response I gave before.

    Instead of:
    PALETTE *Pal;
    ...
    ImageBuffer = load_bmp("pic.bmp", &Pal);

    It should be:
    PALETTE Pal;
    ...
    ImageBuffer = load_bmp("pic.bmp", Pal);


    I believe that will clear up those warnings (if not we'll get to the bottom of it anyway). Also, you should definitely be able to reuse Pal for multiple load_bmp() calls.

    Hope that helps.

    -Justin
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  11. #11
    Bobish
    Guest
    okay it works nowm thanks. We should probably tell this to hydro how seemed to be having the same problem as me. man is msvc++ 6 annoying at times

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Loading Bitmaps in Allegro
    By LiNeAr in forum Game Programming
    Replies: 1
    Last Post: 08-15-2005, 05:12 PM
  2. Loading bitmaps with createfile() +CreateDIBSection
    By Stevo in forum Windows Programming
    Replies: 7
    Last Post: 05-13-2004, 10:22 PM
  3. loading cursor in allegro
    By GaPe in forum Game Programming
    Replies: 4
    Last Post: 05-03-2003, 06:50 AM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-21-2002, 12:35 AM
  5. Allegro graphics trouble
    By Brian in forum C++ Programming
    Replies: 0
    Last Post: 02-25-2002, 02:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21