void draw_background(BITMAP *dest, BITMAP *src, int x, int y, int alpha) { int nx1,ny1,ny2,nx2; set_trans_blender(0,0,0,0); if(x<=0)nx1=480+x; if(x>0)nx1=-(480-x); ny1=y; if(y<=0)ny2=480+y; if(y>0)ny2=-(480-y); nx2=x; if(alpha>0) { draw_lit_sprite(dest,src,x,y, alpha); draw_lit_sprite(dest,src,nx1,ny1, alpha); draw_lit_sprite(dest,src,nx2,ny2, alpha); draw_lit_sprite(dest,src,nx1,ny2, alpha); } else { draw_sprite(dest,src,x,y); draw_sprite(dest,src,nx1,ny1); draw_sprite(dest,src,nx2,ny2); draw_sprite(dest,src,nx1,ny2); } }
void Font::draw( BITMAP* aBuffer, const std::string& aText, int aX, int aY, Blending aBlending) { int x = aX; int y = aY; bool addBlend = aBlending == Blending_Add; setBlending(aBlending); for(unsigned int i = 0; i < aText.size(); i++) { BITMAP* bitmap = getBitmapForGlyph(aText[i]); if (aBlending == Blending_None) { draw_sprite(aBuffer, bitmap, x, y); } else if (addBlend) { draw_trans_sprite(aBuffer, bitmap, x, y); } else { draw_lit_sprite(aBuffer, bitmap, x, y, 0); } x += bitmap->w; } }
void fundo::desenha_transparente(int x, int y, int trans) { if(!egl_init) return; if(!bmp) return; draw_lit_sprite(tela,bmp,x,y,trans); }
void show_gripdesign(void) { BITMAP *bmp; BITMAP *bmp2; int end=0; int time=0; int alpha=255; bmp2 = load_bitmap("graphic/menu/logo.pcx",NULL); bmp = create_bitmap(480,480); stretch_sprite(bmp,bmp2,0,0,480,480); speed_counter = 0; while(!key[KEY_ESC] && !end) { while(speed_counter>0) { time++; if(time<350 && alpha>0) alpha-=2; if(alpha<0)alpha=0; if(time>350) alpha+=4; if(alpha>255)alpha=255; if(time>450)end=1; speed_counter--; } set_trans_blender(0,0,0,0); draw_lit_sprite(virt,bmp,0,0,alpha); vsync(); blit(virt,screen,0,0,80,0,480,480); } destroy_bitmap(bmp); destroy_bitmap(bmp2); }
void shadowed_masked_image::set_image(BITMAP *_image) { if (image = _image) { if (bitmap_color_depth(image) != 8) { if (shadow_mask) destroy_bitmap(shadow_mask); shadow_mask = create_bitmap_ex(bitmap_color_depth(image), image->w, image->h); clear_to_color(shadow_mask, bitmap_mask_color(shadow_mask)); set_trans_blender(shadow_level, shadow_level, shadow_level, 0); draw_lit_sprite(shadow_mask, image, 0, 0, 255); set_trans_blender(255, 0, 255, 0); draw_lit_sprite(shadow_mask, image, -x_offset, -y_offset, 255); } else { if (shadow_mask) destroy_bitmap(shadow_mask); shadow_mask = 0; } resize(image->w - 1 + x_offset, image->h - 1 + y_offset); } }
void draw_a_donkey(BITMAP *bmp, BITMAP *sprite, int x, int y, int color, int flip, fixed angle, fixed scale) { BITMAP *temp = create_bitmap(sprite->w, sprite->h); clear(temp); ((flip)? draw_sprite_h_flip: draw_sprite)(temp, sprite, 0, 0); color_map = tint_map; draw_lit_sprite(temp, temp, 0, 0, color); color_map = NULL; if ((angle == itofix(1)) && (scale == itofix(1))) draw_sprite(bmp, temp, x, y); else rotate_scaled_sprite(bmp, temp, x, y, angle, scale); destroy_bitmap(temp); }
BITMAP* generate_bg(BITMAP *img, unsigned char r, unsigned char g, unsigned char b) { bg_r = r; bg_g = g; bg_b = b; BITMAP *bg2 = create_bitmap(img->w*2, img->h*2); BITMAP *bg = create_bitmap(img->w*2, img->h*2); draw_sprite(bg, img, 0,0); draw_sprite_h_flip(bg, img, img->w,0); draw_sprite_v_flip(bg, img, 0,img->h); draw_sprite_vh_flip(bg, img, img->w,img->h); set_trans_blender(r,g,b,255); draw_lit_sprite(bg2, bg, 0,0, 96); destroy_bitmap(bg); return bg2; }
void draw_block(BITMAP *bmp, int x, int y, BLOCK block, int dark) { if (!block_bmp) block_bmp = create_bitmap(BLOCK_SIZE, BLOCK_SIZE); if (block) { if (!(block & 0xf0) || ((block & 0xf0) == BLOCK_GRAY)) blit(datafile[BLOCK_BMP].dat, block_bmp, 0, 0, 0, 0, BLOCK_SIZE, BLOCK_SIZE); else { blit(datafile[BLOCK_BMP].dat, block_bmp, ((block & 0xf0) >> 4) * BLOCK_SIZE, 0, 0, 0, BLOCK_SIZE, BLOCK_SIZE); block = PAL_GRAY; dark = FALSE; } color_map = (dark)? tint_dark_map: tint_map; draw_lit_sprite(bmp, block_bmp, x, y, (block & 0x0f)); } }
void Bitmap::LitBlendBlt(Bitmap *src, int dst_x, int dst_y, int light_amount) { BITMAP *al_src_bmp = src->_alBitmap; draw_lit_sprite(_alBitmap, al_src_bmp, dst_x, dst_y, light_amount); }
int main(int argc, char *argv[]) { char buf[256]; PALETTE pal; BITMAP *image1; BITMAP *image2; BITMAP *buffer; int r, g, b, a; int x, y, w, h; int x1, y1, x2, y2; int prevx1, prevy1, prevx2, prevy2; int timer; int bpp = -1; int ret = -1; if (allegro_init() != 0) return 1; install_keyboard(); install_timer(); /* what color depth should we use? */ if (argc > 1) { if ((argv[1][0] == '-') || (argv[1][0] == '/')) argv[1]++; bpp = atoi(argv[1]); if ((bpp != 15) && (bpp != 16) && (bpp != 24) && (bpp != 32)) { allegro_message("Invalid color depth '%s'\n", argv[1]); return 1; } } if (bpp > 0) { /* set a user-requested color depth */ set_color_depth(bpp); ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); } else { /* autodetect what color depths are available */ static int color_depths[] = { 16, 15, 32, 24, 0 }; for (a=0; color_depths[a]; a++) { bpp = color_depths[a]; set_color_depth(bpp); ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); if (ret == 0) break; } } /* did the video mode set properly? */ if (ret != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error setting %d bit graphics mode\n%s\n", bpp, allegro_error); return 1; } /* specify that images should be loaded in a truecolor pixel format */ set_color_conversion(COLORCONV_TOTAL); /* load the first picture */ replace_filename(buf, argv[0], "allegro.pcx", sizeof(buf)); image1 = load_bitmap(buf, pal); if (!image1) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error reading %s!\n", buf); return 1; } /* load the second picture */ replace_filename(buf, argv[0], "mysha.pcx", sizeof(buf)); image2 = load_bitmap(buf, pal); if (!image2) { destroy_bitmap(image1); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error reading %s!\n", buf); return 1; } /* create a double buffer bitmap */ buffer = create_bitmap(SCREEN_W, SCREEN_H); /* Note that because we loaded the images as truecolor bitmaps, we don't * need to bother setting the palette, and we can display both on screen * at the same time even though the source files use two different 256 * color palettes... */ prevx1 = prevy1 = prevx2 = prevy2 = 0; textprintf_ex(screen, font, 0, SCREEN_H-8, makecol(255, 255, 255), 0, "%d bpp", bpp); while (!keypressed()) { timer = retrace_count; clear_bitmap(buffer); /* the first image moves in a slow circle while being tinted to * different colors... */ x1= 160+fixtoi(fixsin(itofix(timer)/16)*160); y1= 140-fixtoi(fixcos(itofix(timer)/16)*140); r = 127-fixtoi(fixcos(itofix(timer)/6)*127); g = 127-fixtoi(fixcos(itofix(timer)/7)*127); b = 127-fixtoi(fixcos(itofix(timer)/8)*127); a = 127-fixtoi(fixcos(itofix(timer)/9)*127); set_trans_blender(r, g, b, 0); draw_lit_sprite(buffer, image1, x1, y1, a); textprintf_ex(screen, font, 0, 0, makecol(r, g, b), 0, "light: %d ", a); /* the second image moves in a faster circle while the alpha value * fades in and out... */ x2= 160+fixtoi(fixsin(itofix(timer)/10)*160); y2= 140-fixtoi(fixcos(itofix(timer)/10)*140); a = 127-fixtoi(fixcos(itofix(timer)/4)*127); set_trans_blender(0, 0, 0, a); draw_trans_sprite(buffer, image2, x2, y2); textprintf_ex(screen, font, 0, 8, makecol(a, a, a), 0, "alpha: %d ", a); /* copy the double buffer across to the screen */ vsync(); x = MIN(x1, prevx1); y = MIN(y1, prevy1); w = MAX(x1, prevx1) + 320 - x; h = MAX(y1, prevy1) + 200 - y; blit(buffer, screen, x, y, x, y, w, h); x = MIN(x2, prevx2); y = MIN(y2, prevy2); w = MAX(x2, prevx2) + 320 - x; h = MAX(y2, prevy2) + 200 - y; blit(buffer, screen, x, y, x, y, w, h); prevx1 = x1; prevy1 = y1; prevx2 = x2; prevy2 = y2; } clear_keybuf(); destroy_bitmap(image1); destroy_bitmap(image2); destroy_bitmap(buffer); return 0; }
void ALSoftwareGraphicsDriver::RenderToBackBuffer() { for (int i = 0; i < numToDraw; i++) { if (drawlist[i] == NULL) { if (_nullSpriteCallback) _nullSpriteCallback(drawx[i], drawy[i]); else throw Ali3DException("Unhandled attempt to draw null sprite"); continue; } ALSoftwareBitmap* bitmap = drawlist[i]; int drawAtX = drawx[i];// + x; int drawAtY = drawy[i];// + y; if ((bitmap->_opaque) && (bitmap->_bmp == virtualScreen)) { } else if (bitmap->_opaque) { blit(bitmap->_bmp, virtualScreen, 0, 0, drawAtX, drawAtY, bitmap->_bmp->w, bitmap->_bmp->h); } else if (bitmap->_transparency >= 255) { // fully transparent... invisible, do nothing } else if (bitmap->_hasAlpha) { if (bitmap->_transparency == 0) set_alpha_blender(); else set_blender_mode(NULL, NULL, _trans_alpha_blender32, 0, 0, 0, bitmap->_transparency); draw_trans_sprite(virtualScreen, bitmap->_bmp, drawAtX, drawAtY); } else { draw_sprite_with_transparency(bitmap->_bmp, drawAtX, drawAtY, bitmap->_transparency); } } if (((_tint_red > 0) || (_tint_green > 0) || (_tint_blue > 0)) && (_colorDepth > 8)) { // screen tint // This slows down the game no end, only experimental ATM set_trans_blender(_tint_red, _tint_green, _tint_blue, 0); draw_lit_sprite(virtualScreen, virtualScreen, 0, 0, 128); /* This alternate method gives the correct (D3D-style) result, but is just too slow! if ((_spareTintingScreen != NULL) && ((_spareTintingScreen->w != virtualScreen->w) || (_spareTintingScreen->h != virtualScreen->h))) { destroy_bitmap(_spareTintingScreen); _spareTintingScreen = NULL; } if (_spareTintingScreen == NULL) { _spareTintingScreen = create_bitmap_ex(bitmap_color_depth(virtualScreen), virtualScreen->w, virtualScreen->h); } tint_image(virtualScreen, _spareTintingScreen, _tint_red, _tint_green, _tint_blue, 100, 255); blit(_spareTintingScreen, virtualScreen, 0, 0, 0, 0, _spareTintingScreen->w, _spareTintingScreen->h);*/ } ClearDrawList(); }
// prepares the person_bmp BITMAP *Person::prepare_sprite() { static BITMAP *person_bmp = NULL; if (person_bmp == NULL) person_bmp = create_bitmap(TILE_W, TILE_H); int ani_frame = -1; switch (m_state) { case STAND_PERSON: ani_frame = ANI_FRAME_STAND; break; case WALKING_PERSON: ani_frame = ((GAME_T - m_state_time) % (BPS/4)) < (BPS/8) ? ANI_FRAME_WALK1: ANI_FRAME_WALK2; break; case LOOKING_PERSON: ani_frame = ANI_FRAME_LOOK; break; case CALLING_PERSON: { if (GAME_T - m_state_time < CALLING_DURATION*1/6) ani_frame = ANI_FRAME_HELP1; else if (GAME_T - m_state_time < CALLING_DURATION*2/6) ani_frame = ANI_FRAME_HELP2; else if (GAME_T - m_state_time < CALLING_DURATION*3/6) ani_frame = ANI_FRAME_HELP3; else if (GAME_T - m_state_time < CALLING_DURATION*4/6) ani_frame = ANI_FRAME_HELP3; else if (GAME_T - m_state_time < CALLING_DURATION*5/6) ani_frame = ANI_FRAME_HELP3; else ani_frame = ANI_FRAME_HELP1; break; } case ABDUCTING_PERSON: ani_frame = ANI_FRAME_HELP3; break; case FALLING_PERSON: ani_frame = ANI_FRAME_HELP2; break; case DEAD_PERSON: // impossible to be here break; } if (ani_frame < -1) { clear_to_color(person_bmp, bitmap_mask_color(person_bmp)); return person_bmp; } blit(MEDIA_BITMAP(PEOPLE_PCX), person_bmp, ani_frame*TILE_W, m_type*TILE_H, 0, 0, TILE_W, TILE_H); lit_mode(0, 0, 0); draw_lit_sprite(person_bmp, person_bmp, 0, 0, static_cast<int>(255 * m_toast_factor)); solid_mode(); return person_bmp; }