Mail Archives: djgpp/1998/09/21/22:45:51
From: | dragun AT my-dejanews DOT com
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Why doesnt this lighting work right in Allegro?
|
Date: | Tue, 22 Sep 1998 02:05:06 GMT
|
Organization: | Deja News - The Leader in Internet Discussion
|
Lines: | 142
|
Message-ID: | <6u70ki$d34$1@nnrp1.dejanews.com>
|
NNTP-Posting-Host: | 168.191.156.93
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
I coded this in Allegro (I'm using C++):
//// INCLUDE
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include "allegro.h"
#include "game.hpp"
//// DEFINE
#define tilSIZE 32
#define maxLEVS 3
#define maxCOLS 100
#define maxROWS 100
#define maxTILE 144
//// STRUCTURES
typedef struct
{
unsigned char img;
} tileMAP;
//// GLOBALS
BITMAP *buffer;
DATAFILE *game_dat, *exec_dat, *base_dat, *mask_dat, *objt_dat;
COLOR_MAP *clr_map, *lit_map, *trn_map, *drk_map;
char map_name[80];
int mapX, mapY, DONE;
float tileX, tileY;
float speed = 1, sped = 4;
tileMAP levelMAP[maxLEVS][maxCOLS][maxROWS];
//// FUNCTION PROTOTYPES
void LoadMap(void);
void DrawMap(int x, int y);
void Bounds(void);
//// FUNCTIONS
RGB add_blender(PALETTE pal, int x, int y)
{
RGB rgb;
int r, g, b;
r = (int)pal[x].r + (int)pal[y].r;
g = (int)pal[x].g + (int)pal[y].g;
b = (int)pal[x].b + (int)pal[y].b;
rgb.r = MIN(r, 63);
rgb.g = MIN(g, 63);
rgb.b = MIN(b, 63);
return rgb;
}
//// MAIN
main()
{
allegro_init();
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
install_keyboard();
install_mouse();
install_timer();
exec_dat = load_datafile("exec.dat");
game_dat = load_datafile("game.dat");
base_dat = load_datafile("base.dat");
mask_dat = load_datafile("mask.dat");
objt_dat = load_datafile("objt.dat");
if (!game_dat || !base_dat || !mask_dat || !objt_dat)
{
allegro_exit();
exit(1);
}
set_pallete(game_dat[2].dat);
buffer = create_bitmap(640, 480);
clear(buffer);
rgb_map = new RGB_MAP;
create_rgb_table(rgb_map, (RGB *)game_dat[2].dat, NULL);
clr_map = new COLOR_MAP;
create_color_table(clr_map, (RGB *)game_dat[2].dat, add_blender, NULL);
lit_map = new COLOR_MAP;
create_light_table(lit_map, (RGB *)game_dat[2].dat, 64, 64, 64, NULL);
drk_map = new COLOR_MAP;
create_light_table(drk_map, (RGB *)game_dat[2].dat, 0, 0, 0, NULL);
trn_map = new COLOR_MAP;
create_trans_table(trn_map, (RGB *)game_dat[2].dat, 128, 128, 128, NULL);
color_map = lit_map;
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
color_map = drk_map;
draw_trans_sprite(buffer, exec_dat[2].dat, 228, 216);
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
draw_sprite(buffer, exec_dat[1].dat, 224, 212);
blit(exec_dat[3].dat, buffer, 0, 0, 480, 0, 160, 480);
vsync();
blit(buffer, screen, 0, 0, 0, 0, 640, 480);
unload_datafile(game_dat);
unload_datafile(base_dat);
unload_datafile(mask_dat);
unload_datafile(objt_dat);
destroy_bitmap(buffer);
allegro_exit();
exit(0);
}
whenever I blit a transparent image with draw_trans_sprite(), I have to set
the background color that's suppose to be masked (originally 0) to 255
because that sets the transparent function to do a small tranparency. I want
it to do a normal masked blitting WITH the transparency effect. Any ideas on
how to do this?
Note that most of the functions to do the transparency is ripped off from the
lighting demo on Allegro's homepage.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
- Raw text -