delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/20/15:14:25

From: "Paul Bibbings" <paul DOT bibbings AT tesco DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Allegro - masked_blit();
Date: Thu, 20 Jan 2000 16:42:39 -0000
Organization: Tesco ISP
Lines: 150
Message-ID: <867egt$dpf$1@barcode.tesco.net>
NNTP-Posting-Host: 212.140.69.220
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Please could someone give me a few pointers in the use of this function. I'm
new to Allegro and I'm not getting very far with the available docs.
    What I'm trying to do is simple enough, but I'm stuck with how to set
transparent pixels. My program simply draws a chessboard to the screen, then
accesses a single bitmap showing the chess pieces (black on a white
background). The question is, what do I need to do so that the masked_blit()
interprets the background as transparent, hence allowing the board to be
seen behind the pieces.
    I've tried everything I can think of. Allegro.txt under masked_blit()
that transparent pixels are marked by a zero in 256 color modes, or bright
pink for truecolor data. Hi do I set the background color of the bitmap so
that the program will interpret it as zero and skip the background pixels?
(I've tried changing the background color to bright pink out of desperation,
but since the function set_palette() uses the palette derived from the
bitmap, then ALL the colours are changed from what I set them.

    Allegro.txt also says something about the GRX_HW_VRAM_BLIT_MASKED flag
being set, but doesn't say how this is done.

Any help will be appreciated.

Please save the walls from the dent of my head!!!!

////////////////////////////////////////////////////////////////////////////
//////////

#include <stdio.h>

#include "allegro.h"

#define pieces "c:\\cprojs\\chess\\pieces.bmp"

/*function prototypes*/
void draw_board(void);
void load_pieces(BITMAP *);

int main()
{
        BITMAP *piece;
        PALETTE pal;

        piece = load_bmp(pieces, pal);
        if(!piece)
        {
                printf("can't find %s\n", pieces);
                return 1;
        }

        allegro_init();
        install_keyboard();
        install_mouse();
        install_timer();

        set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0);

        set_palette(pal);

        /*draw the empty chess_board to the screen*/
        draw_board();

        show_mouse(screen);

        readkey();

        load_pieces(piece);

        destroy_bitmap(piece);

        readkey();
        return 0;
}


void draw_board(void)
/*function to draw empty chess board onto the screen*/
{
        int background = 2, white = 1, black = 9;
        int color;
        int count_x, count_y;
        int x, y;
        clear_to_color(screen, 6);

        rectfill(screen, 230, 120, 560, 450, background);
        x = 235;
        y = 125;
        color = white;
        for(count_y = 0; count_y < 8; count_y++)
        {
                for(count_x = 0; count_x < 8; count_x++)
                {
                        rectfill(screen, x, y, x + 40, y + 40, color);
                        x = x + 40;
                        if(color == white)
                                 color = black;
                        else
                                 color = white;
                }
                x = 235;
                y = y + 40;
                if(color == white)
                         color = black;
                else
                         color = white;
        }
}


void load_pieces(BITMAP *piece)
/*function to load the pieces to the board in a starting position*/
{
        /*x controls the fonts. Options are 20, 86, 152, 218*/
        int x = 86, y;
        int count_col;

        masked_blit(piece, screen, 26, x, 356, 406, 38, 38); // white_queen
        masked_blit(piece, screen, 282, x, 396, 406, 38, 38); // white_king
        masked_blit(piece, screen, 58, x, 356, 126, 38, 38); // black_queen
        masked_blit(piece, screen, 314, x, 396, 126, 38, 38); // black_king
        masked_blit(piece, screen, 90, x, 316, 406, 38, 38); // w_q_bishop
        masked_blit(piece, screen, 90, x, 436, 406, 38, 38); // w_k_bishop
        masked_blit(piece, screen, 122, x, 316, 126, 38, 38); // b_q_bishop
        masked_blit(piece, screen, 122, x, 436, 126, 38, 38); // b_k_bishop
        masked_blit(piece, screen, 154, x, 276, 406, 38, 38); // w_q_knight
        masked_blit(piece, screen, 154, x, 476, 406, 38, 38); // w_k_knight
        masked_blit(piece, screen, 186, x, 276, 126, 38, 38); // b_q_knight
        masked_blit(piece, screen, 186, x, 476, 126, 38, 38); // b_k_knight
        masked_blit(piece, screen, 218, x, 236, 406, 38, 38); // w_q_rook
        masked_blit(piece, screen, 218, x, 516, 406, 38, 38); // w_k_rook
        masked_blit(piece, screen, 250, x, 236, 126, 38, 38); // b_q_rook
        masked_blit(piece, screen, 250, x, 516, 126, 38, 38); // b_k_rook

        y = 236;

        for(count_col = 0; count_col < 8; count_col++)
        {
                /*set the white pawns in the starting position*/
                masked_blit(piece, screen, 346, x, y, 366, 38, 38);

                /*set the black pawns in the starting position*/
                masked_blit(piece, screen, 378, x, y, 166, 38, 38);

                y+=40;
        }

}





- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019