Skip to content

Commit

Permalink
Fixed some color stuff arising from allegro's shift to premultiplied …
Browse files Browse the repository at this point in the history
…alpha.
  • Loading branch information
RosaryMala committed Mar 5, 2011
1 parent 189820b commit fcb3c18
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ void drawFloorBlood ( Block *b, int32_t drawx, int32_t drawy )
int sheetOffsetX = TILEWIDTH * (sprite.sheetIndex % SHEET_OBJECTSWIDE),
sheetOffsetY = 0;

al_draw_tinted_bitmap_region( IMGBloodSheet, b->bloodcolor, sheetOffsetX, sheetOffsetY, TILEWIDTH, TILEHEIGHT+FLOORHEIGHT, drawx, drawy, 0);
al_draw_tinted_bitmap_region( IMGBloodSheet, al_map_rgb(255,255,255), sheetOffsetX, sheetOffsetY+TILEHEIGHT+FLOORHEIGHT, TILEWIDTH, TILEHEIGHT+FLOORHEIGHT, drawx, drawy, 0);
al_draw_tinted_bitmap_region( IMGBloodSheet, premultiply(b->bloodcolor), sheetOffsetX, sheetOffsetY, TILEWIDTH, TILEHEIGHT+FLOORHEIGHT, drawx, drawy, 0);
al_draw_bitmap_region( IMGBloodSheet, sheetOffsetX, sheetOffsetY+TILEHEIGHT+FLOORHEIGHT, TILEWIDTH, TILEHEIGHT+FLOORHEIGHT, drawx, drawy, 0);
}
}

16 changes: 4 additions & 12 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,19 @@ void parseConfigLine( string line ){
}
if( line.find("[FOG_RED") != -1){
int value = parseIntFromLine( "FOG_RED", line);
if(value > 255) value = 255;
if(value < 0) value = 0;
config.fogr = value;
config.fogr = value / 255.0;
}
if( line.find("[FOG_GREEN") != -1){
int value = parseIntFromLine( "FOG_GREEN", line);
if(value > 255) value = 255;
if(value < 0) value = 0;
config.fogg = value;
config.fogg = value / 255.0;
}
if( line.find("[FOG_BLUE") != -1){
int value = parseIntFromLine( "FOG_BLUE", line);
if(value > 255) value = 255;
if(value < 0) value = 0;
config.fogb = value;
config.fogb = value / 255.0;
}
if( line.find("[FOG_ALPHA") != -1){
int value = parseIntFromLine( "FOG_ALPHA", line);
if(value > 255) value = 255;
if(value < 0) value = 0;
config.foga = value;
config.foga = value / 255.0;
}
if( line.find("[SHOW_FOG") != -1){
string result = parseStrFromLine( "SHOW_FOG", line );
Expand Down
16 changes: 14 additions & 2 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,23 @@ vector<string*> IMGFilenames;
GLhandleARB tinter;
GLhandleARB tinter_shader;
Crd3D debugCursor;

ALLEGRO_COLOR premultiply(ALLEGRO_COLOR input)
{
ALLEGRO_COLOR out;
out.a = input.a;
out.r = input.r * input.a;
out.g = input.g * input.a;
out.b = input.b * input.a;
return out;
}

void draw_diamond(float x, float y, ALLEGRO_COLOR color)
{
al_draw_filled_triangle(x, y, x+4, y+4, x-4, y+4, color);
al_draw_filled_triangle(x+4, y+4, x, y+8, x-4, y+4, color);
}

void draw_borders(float x, float y, uint8_t borders)
{
if(borders & 1)
Expand Down Expand Up @@ -618,7 +630,7 @@ void DrawSpriteFromSheet( int spriteNum, ALLEGRO_BITMAP* spriteSheet, ALLEGRO_CO
color.g *= 0.25f;
color.b *= 0.25f;
}
al_draw_tinted_bitmap_region(spriteSheet, color, sheetx * SPRITEWIDTH, sheety * SPRITEHEIGHT, SPRITEWIDTH, SPRITEHEIGHT, x, y - (WALLHEIGHT), 0);
al_draw_tinted_bitmap_region(spriteSheet, premultiply(color), sheetx * SPRITEWIDTH, sheety * SPRITEHEIGHT, SPRITEWIDTH, SPRITEHEIGHT, x, y - (WALLHEIGHT), 0);
}

ALLEGRO_BITMAP * CreateSpriteFromSheet( int spriteNum, ALLEGRO_BITMAP* spriteSheet)
Expand All @@ -641,7 +653,7 @@ void DrawSpriteIndexOverlay(int imageIndex){
currentImage=IMGFilelist[imageIndex];
}
al_clear_to_color(al_map_rgb(255, 0, 255));
al_draw_tinted_bitmap(currentImage, al_map_rgb(255,255,255),0,0,0);
al_draw_bitmap(currentImage,0,0,0);
for(int i =0; i<= 20*SPRITEWIDTH; i+=SPRITEWIDTH)
al_draw_line(i,0,i, al_get_bitmap_height(al_get_target_bitmap()), al_map_rgb(0,0,0), 0);
for(int i =0; i< al_get_bitmap_height(al_get_target_bitmap()); i+=SPRITEHEIGHT)
Expand Down
8 changes: 4 additions & 4 deletions SpriteObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,9 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset,
if(chop && ( halftile == HALFTILECHOP))
{
if(fileindex < 0)
al_draw_tinted_bitmap_region(defaultsheet, shade_color, sheetx, sheety+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
al_draw_tinted_bitmap_region(defaultsheet, premultiply(shade_color), sheetx, sheety+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
else
al_draw_tinted_bitmap_region(getImgFile(fileindex), shade_color, sheetx, (sheety)+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
al_draw_tinted_bitmap_region(getImgFile(fileindex), premultiply(shade_color), sheetx, (sheety)+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
//draw cut-off floor thing
al_draw_bitmap_region(IMGObjectSheet,
TILEWIDTH * SPRITEFLOOR_CUTOFF, 0,
Expand All @@ -690,9 +690,9 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset,
if((isoutline == OUTLINENONE) || ((isoutline == OUTLINERIGHT) && (b->depthBorderNorth)) || ((isoutline == OUTLINELEFT) && (b->depthBorderWest)) || ((isoutline == OUTLINEBOTTOM) && (b->depthBorderDown)))
{
if(fileindex < 0)
al_draw_tinted_bitmap_region(defaultsheet, shade_color, sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
al_draw_tinted_bitmap_region(defaultsheet, premultiply(shade_color), sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
else
al_draw_tinted_bitmap_region(getImgFile(fileindex), shade_color, sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
al_draw_tinted_bitmap_region(getImgFile(fileindex), premultiply(shade_color), sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
}
if(needoutline)
{
Expand Down
9 changes: 3 additions & 6 deletions WorldSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ void WorldSegment::drawAllBlocks(){
int32_t vsymax = viewedSegment->sizey-1;
int32_t vszmax = viewedSegment->sizez-1; // grabbing one tile +z more than we should for tile rules
//al_hold_bitmap_drawing(true);
int op, src, dst, alpha_op, alpha_src, alpha_dst;
ALLEGRO_COLOR color;
al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst);

for(int32_t vsz=0; vsz < vszmax; vsz++)
{
Expand All @@ -213,18 +210,18 @@ void WorldSegment::drawAllBlocks(){
{
fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp));
al_set_target_bitmap(fog);
al_clear_to_color(al_map_rgb(config.fogr, config.fogg, config.fogb));
al_clear_to_color(premultiply(al_map_rgba_f(config.fogr, config.fogg, config.fogb, config.foga)));
al_set_target_bitmap(temp);
}
if(!((al_get_bitmap_width(fog) == al_get_bitmap_width(temp)) && (al_get_bitmap_height(fog) == al_get_bitmap_height(temp))))
{
al_destroy_bitmap(fog);
fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp));
al_set_target_bitmap(fog);
al_clear_to_color(al_map_rgb(config.fogr, config.fogg, config.fogb));
al_clear_to_color(al_map_rgba_f(config.fogr*config.foga, config.fogg*config.foga, config.fogb*config.foga, config.foga));
al_set_target_bitmap(temp);
}
al_draw_tinted_bitmap(fog, al_map_rgba(255, 255, 255, config.foga), 0, 0, 0);
al_draw_bitmap(fog, 0, 0, 0);
}
if(vsz == vszmax-1)
{
Expand Down
2 changes: 2 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,5 @@ extern ALLEGRO_MOUSE_STATE mouse;
#define FORM_LOG 4

extern int randomCube[RANDOM_CUBE][RANDOM_CUBE][RANDOM_CUBE];

ALLEGRO_COLOR premultiply(ALLEGRO_COLOR input);
8 changes: 4 additions & 4 deletions commonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ typedef struct {
int screenHeight;
bool Fullscreen;
bool show_intro;
int fogr;
int fogg;
int fogb;
int foga;
float fogr;
float fogg;
float fogb;
float foga;
int backr;
int backg;
int backb;
Expand Down
2 changes: 1 addition & 1 deletion init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Sets weather screenshots should have transparent backgrounds
Fog color, and alpha at the bottom z-level.
Setting the alpha to 0, or SHOW_FOG to NO disables fog, for a slight performance increase.
Color and alpha ranges are 0 (min) to 255 (max)
[SHOW_FOG:NO]
[SHOW_FOG:YES]
[FOG_RED:128]
[FOG_GREEN:158]
[FOG_BLUE:177]
Expand Down
Binary file modified stonesense.exe
Binary file not shown.

0 comments on commit fcb3c18

Please sign in to comment.