Thread: trouble with stretch_sprite()

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    trouble with stretch_sprite()

    I'm working on a simple tile engine, and I've gotten to the point where I want to put a character on top of my scenery. The problem is that when I try to draw with stretch_sprite(), the black space in my bitmap shows. I've gone through the allegro doc but I didn't find anything, does anyone know why this might be happening?
    Illusion and reality become impartiality and confidence.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Are you changing the palette to the one loaded from the bitmaps?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  3. #3
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    I've been using this function:
    Code:
    void fix_image_pal(BITMAP * image, PALETTE imgpal)
    {
        int size_x = image -> w;
        int size_y = image -> h;
        BITMAP *temp;
        temp = create_bitmap(size_x, size_y);
        int srcclr, newclr;
        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_y; y++)
            {
                srcclr=getpixel(image,x,y);
                newclr=makecol8((imgpal[srcclr].r*4),(imgpal[srcclr].g*4),(imgpal[srcclr].b*4));
                putpixel(temp,x,y,newclr);
            }
        }
        blit(temp,image,0,0,0,0,size_x,size_y);
        destroy_bitmap(temp);
    }
    is that what you mean?
    Illusion and reality become impartiality and confidence.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I don't undertand what that function does. At first I thought it was for some special effect you were using. You set the palette by calling set_palette(pal);

    What compiler are you using to compile this? I am unable to get it compile with dev-c++ or borland.

    I am uploading a modifed version of your code in an attempt to help you.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  5. #5
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    I don't undertand what that function does. At first I thought it was for some special effect you were using.
    The idea with that function is that it fixes the color in the bitmap, or else they always blit with inverted colors. I got it from an allegro board somewhere.

    The problem still remains, when I use draw_sprite() or stretch_sprite() to put any of my bitmaps on the screen, they don't show up with transparent sections where the bitmap is black like they're supposed to, but just show the black. I'll attach the whole thing so you can run it and see what I'm talking about. (If you don't have allg40.dll you can get it here)
    Illusion and reality become impartiality and confidence.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Ok, I think I found your problem. By default Allegro uses 8-bit color depth and your bitmaps are saved as 24-bit. So either save your bitmaps as 8-bit or change the transparent areas from black to magic pink(255,0,255) and use set_color_conversion(COLORCONV_TOTAL|COLORCONV_KEE P_TRANS) before loading any graphics. There might be other solutions to this.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  7. #7
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    OK, I went over to the allegro site and figured out what I was doing wrong. Since my program was running in 8-bit color depth, the transparent part of a bitmap would be black, but mspaint was putting in the wrong kind of black, so I did this:
    Code:
    for (int x = 0; x < bmp->w; ++x)
        for (int y = 0; y < bmp->h; ++y) {
            int c = getpixel(bmp,x,y);
            if (c == makecol8(0,0,0))
                putpixel(bmp,x,y,0); //0 index is transparent
        }
    and all of the rgb black was replaced with 0-value black, just the way allegro likes it.
    Illusion and reality become impartiality and confidence.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    17
    and btw ichijoji i would strongly recommend getting a better image program like The Gimp its free and really good. Download the 2 files under main. Its really good for being free.
    Drink Yer Wilk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2003, 11:55 PM