void TA3DNetwork::draw() { if (!network_manager.isConnected()) return; // Only works in network mode pMutex.lock(); if (!messages.empty()) { const float Y_ref = 32 + gfx->TA_font->height(); float Y = Y_ref; const uint32 shadowmask = makeacol(0, 0, 0, 0xFF); const uint32 timer = msec_timer; for (std::deque<NetworkMessage>::const_iterator i = messages.begin(); i != messages.end(); ++i) { uint32 color = 0xFFFFFFFF; if ((int)(timer - i->timer) - CHAT_MESSAGE_TIMEOUT + 1000 >= 0) { color = makeacol( 0xFF, 0xFF, 0xFF, 255 - Math::Min(255, ((int)(timer - i->timer) - CHAT_MESSAGE_TIMEOUT + 1000) * 255 / 1000)); Y -= Math::Min(1.0f, float((int)(timer - i->timer) - CHAT_MESSAGE_TIMEOUT + 1000) * 0.001f) * (gfx->TA_font->height() + Y - Y_ref); } gfx->print(Gui::gui_font, 137.0f, Y + 1.0f, 0.0f, color & shadowmask, i->text); gfx->print(Gui::gui_font, 136.0f, Y, 0.0f, color, i->text); Y += Gui::gui_font->height(); } } pMutex.unlock(); }
void renderStepZoneDMX(int player) { int startColumn = player == 0 ? 0 : 4; if ( gs.isSingles() ) { if ( gs.player[0].centerLeft ) { startColumn = 0; } else if ( gs.player[0].centerRight ) { startColumn = 4; } else { startColumn = 2; // center play } } int endColumn = gs.isDoubles ? 8 : startColumn+4; for ( int i = startColumn; i < endColumn; i++ ) { int x = getColumnOffsetX_DMX(i); int blink = gs.player[player].stepZoneBlinkTimer > 0 ? 0 : 1; // pick the state of the step zone int hitcolor = 0x7F000000; int outlineColor = 0xFFB4B4B4; const int fadeOutLength = 100; if ( blink == 1 ) { static int colors[3] = { makeacol(41, 239, 115, 255), makeacol(239, 101, 190, 255), makeacol(76, 0, 190, 255) }; int stageColor = gs.player[player].stagesLevels[gs.currentStage] % 10; outlineColor = colors[stageColor]; } if ( gs.player[player].laneFlareColors[i] == 2 ) { blink = 2; // currently holding a hold note in this column } int color = getColorOfColumn(i); if ( im.isKeyDown(i) ) { hitcolor = color == 0 ? 0xEECC0000 : 0xEE0000CC; } else if ( im.getReleaseLength(i) <= fadeOutLength ) { int a = getValueFromRange(0xFF, 0x7F, im.getReleaseLength(i) * 100/ fadeOutLength); if ( i ==4 ) { al_trace("%d\r\n", a); } hitcolor = color == 0 ? makeacol32(0xFF, 0, 0, a) : makeacol32(0, 0, 0xFF, a); } renderStepLaneDMX(x, hitcolor, outlineColor); masked_blit(m_stepZoneSourceDMX[color], rm.m_backbuf, blink*34, 0, x, (gs.player[player].isColumnReversed(i) ? DMX_STEP_ZONE_REV_Y-34 : DMX_STEP_ZONE_Y), 34, 38); } }
void render_graymap_alleg(BITMAP* canvas, graymap_t* gm, color_t* pal_cols, double* pal_grays, int pal_n) { int limit_w = gm->w; int limit_h = gm->h; if(limit_w > canvas->w) limit_w = canvas->w; if(limit_h > canvas->h) limit_h = canvas->h; color_t col; int x,y,i; uint_8 r,g,b,a; for(y = 0, i = 0; y < limit_h; ++y) { for(x = 0; x < limit_w; ++x, ++i) { col = get_palette_color(gm->data[i], pal_cols, pal_grays, pal_n); r = (uint_8) round(col.r * 255.0); g = (uint_8) round(col.g * 255.0); b = (uint_8) round(col.b * 255.0); a = (uint_8) round(col.a * 255.0); putpixel(canvas, x,y,makeacol(r,g,b,a)); } } }
NaroolLurker::NaroolLurker(Vector2 opos, double shipAngle, ShipData *shipData, unsigned int code) : Ship(opos, shipAngle, shipData, code) { STACKTRACE; weaponRange = scale_range(get_config_float("Weapon", "Range", 0)); weaponVelocity = scale_velocity(get_config_float("Weapon", "Velocity", 0)); weaponDamage = get_config_int("Weapon", "Damage", 0); weaponArmour = get_config_int("Weapon", "Armour", 0); weaponDuration = get_config_int("Weapon", "Duration", 0); poison = get_config_float("Weapon", "poison", 0); normalRechargeAmount = recharge_amount; cloak = FALSE; cloak_frame = 0; BITMAP *shpbmp = sprite->get_bitmap(0); int bpp = bitmap_color_depth(shpbmp); lightningbmp = create_bitmap_ex(bpp, shpbmp->w, shpbmp->h); clear_to_color(lightningbmp, makeacol(0,0,0,255)); //maxsparktime = 2000; maxsparktime = get_config_float("Quirk", "maxsparktime", 2000); sparktime = maxsparktime; sparkpos = 0.5 * Vector2(lightningbmp->w,lightningbmp->h); Rmax = get_config_float("Quirk", "Rmax", 1); }
int blend_color(int from, int to, double t) { int r = getr(from) + static_cast<int>((getr(to) - getr(from)) * t); int g = getg(from) + static_cast<int>((getg(to) - getg(from)) * t); int b = getb(from) + static_cast<int>((getb(to) - getb(from)) * t); int a = geta(from) + static_cast<int>((geta(to) - geta(from)) * t); return makeacol(MID(0, r, 255), MID(0, g, 255), MID(0, b, 255), MID(0, a, 255)); }
static BITMAP *convert_bitmap_alpha(BITMAP *bmp_orig, bool keep_alpha) { if (!bmp_orig) return NULL; // Non 32bpp bitmap just can't contain alpha channel if (bitmap_color_depth(bmp_orig) != 32) return bmp_orig; // Try to detect alpha channel in the bitmap bool has_alpha = false; bool has_trans = false; bool has_opaque = false; for (int y = 0; y < bmp_orig->h; y++) { const uint32 *line = (const uint32 *)bmp_orig->line[y]; for (int x = 0; x < bmp_orig->w; x++) { uint32 a = line[x] & 0xFF000000; if (a == 0) has_trans = true; else if (a == 0xFF000000) has_opaque = true; else has_alpha = true; } } if (has_alpha || keep_alpha) { for (int x = 0; x < bmp_orig->w; x++) for (int y = 0; y < bmp_orig->h; y++) { int c = getpixel(bmp_orig, x, y); if (geta32(c) == 0) putpixel(bmp_orig, x, y, MASK_COLOR_32); } return bmp_orig; } else { bool has_1bit_alpha = has_trans && has_opaque; BITMAP *bmp = create_bitmap(bmp_orig->w, bmp_orig->h); clear_to_color(bmp, bitmap_mask_color(bmp)); for (int x = 0; x < bmp_orig->w; x++) for (int y = 0; y < bmp_orig->h; y++) { int c = getpixel(bmp_orig, x, y); if (!has_1bit_alpha || geta32(c) != 0) { putpixel(bmp, x, y, makeacol(getr32(c), getg32(c), getb32(c), 255)); } } destroy_bitmap(bmp_orig); return bmp; } }
void renderDMXHoldNoteBody(int column, int x, int topy, int bot, int color, int player) { static int lineColors[8][34] = { { 0,0,0,0,0,0, 0,0, 1,1, 2,2, 3,3,3,3,3,3,3,3,3,3, 2,2, 1,1, 0,0, 0,0,0,0,0,0 }, // visually, the charge note { 0,0,0,0,0,0, 0,0, 1,1, 2,2, 3,3,3,3,3,3,3,3,3,3, 2,2, 1,1, 0,0, 0,0,0,0,0,0 }, { 0,0,0,0,0,0, 0,0, 0,1, 1,2, 2,3,3,3,3,3,3,3,3,2, 2,1, 1,0, 0,0, 0,0,0,0,0,0 }, { 0,0,0,0,0,0, 0,0, 0,1, 1,2, 2,3,3,3,3,3,3,3,3,2, 2,1, 1,0, 0,0, 0,0,0,0,0,0 }, { 0,0,0,0,0,0, 0,0, 0,2, 2,3, 3,3,3,2,2,2,2,3,3,3, 3,2, 2,0, 0,0, 0,0,0,0,0,0 }, { 0,0,0,0,0,0, 0,0, 0,2, 2,3, 3,3,3,2,2,2,2,3,3,3, 3,2, 2,0, 0,0, 0,0,0,0,0,0 }, { 0,0,0,0,0,0, 0,0, 0,1, 1,2, 2,3,3,3,3,3,3,3,3,2, 2,1, 1,0, 0,0, 0,0,0,0,0,0 }, { 0,0,0,0,0,0, 0,0, 0,1, 1,2, 2,3,3,3,3,3,3,3,3,2, 2,1, 1,0, 0,0, 0,0,0,0,0,0 }, }; if ( color == HOLD_UNTOUCHED ) { color = column == 1 || column == 2 || column == 5 || column == 6 ? HOLD_DMX_RED : HOLD_DMX_BLUE; } for ( int chargex = 6; chargex < 34-6; chargex++ ) { int frame = 0; if ( color == HOLD_DMX_BRIGHT ) { frame = getValueFromRange(0, 7, (gs.player[player].stepZoneBeatTimer*100 / gs.player[player].stepZoneTimePerBeat)); } int col = makeacol( dmxHoldColors[color][lineColors[frame][chargex]][0], dmxHoldColors[color][lineColors[frame][chargex]][1], dmxHoldColors[color][lineColors[frame][chargex]][2], 255 ); int endcapMod = 0; if ( lineColors[frame][chargex] == 0 ) { endcapMod = 3; // this color is a little shorter, to create a subtle 'end cap' on the hold note } line(rm.m_backbuf, x+chargex, topy, x+chargex, bot-endcapMod, col); // for debugging //line(rm.m_backbuf, 0, topy, 640, topy, makeacol(255,255,255,255)); //for ( int i = 0; i < 10; i++ ) //{ // line(rm.m_backbuf, 0, bot+i, 640, bot+i, makeacol(255,128,128,255)); //} } }
void RenderingManager::dimScreen(int percent) { drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(m_backbuf, 0, 0, 640, 480, makeacol(0, 0, 0, getValueFromRange(0, 255, percent))); set_alpha_blender(); // the game assumes the graphics are left in this mode }
void fnt_ttf_print_string(BITMAP *b, int x, int y, char *text, int fg, int bg, int sd) { // Refined Version from tutorial FT_GlyphSlot slot = face->glyph; /* a small shortcut */ FT_Error error; fnt_t* cfont; BITMAP* line1,line0; int pen_x, pen_y, n; #ifdef USESDL Uint32 rmask,gmask,bmask,amask; #else int rmask,gmask,bmask,amask; #endif // ... initialize library ... // ... create face object ... // printf("fnt_ttf_print_string\n"); cfont=fnt_getactive(); // printf("scale_h=%d\n",cfont->scale_w); error = FT_Set_Pixel_Sizes(face, /* handle to face object */ cfont->scale_w, /* pixel_width */ cfont->scale_h ); /* pixel_height */ pen_x = x; pen_y = y+cfont->scale_h-1; pen_x = 0; pen_y = cfont->scale_h-1; if(fnt_render==RENDER_NATIVE) { // for SDL, you can use this #ifdef USESDL # if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask=0xff000000; gmask=0x00ff0000; bmask=0x0000ff00; amask=0x000000ff; # else rmask=0x000000ff; gmask=0x0000ff00; bmask=0x00ff0000; amask=0xff000000; # endif line1=SDL_CreateRGBSurface(SDL_SWSURFACE,640,cfont->scale_h*2,32,rmask,gmask,bmask,amask); #endif rectfill(line1,0,0,640,cfont->scale_h*2,makeacol(0,0,0,0)); } else { // For generic sdl/allegro, use this: line1=create_bitmap(640,cfont->scale_h*2); if(bg==-1) blit(screen,line1,x,y,0,0,640-x,y+cfont->scale_h*2); else rectfill(line1,0,0,640,cfont->scale_h*2,bg); } // printf ("x4\n"); // printf("rendering: %s\n",text); for ( n = 0; n < strlen(text); n++ ) { if(text[n] != 10 ) { error = FT_Load_Char( face, text[n], FT_LOAD_RENDER ); if ( error ) continue; /* ignore errors */ if(fnt_render==RENDER_SIMPLE) { if(sd>-1) fnt_ttf_draw_bitmap_simple( &slot->bitmap, line1, pen_x + slot->bitmap_left+1, pen_y - slot->bitmap_top+1, sd ); /* increment pen position */ fnt_ttf_draw_bitmap_simple( &slot->bitmap, line1, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top, fg ); /* increment pen position */ } if(fnt_render==RENDER_BLEND) { if(sd>-1) fnt_ttf_draw_bitmap_blend( &slot->bitmap, line1, pen_x + slot->bitmap_left+1, pen_y - slot->bitmap_top+1, sd ); /* increment pen position */ fnt_ttf_draw_bitmap_blend( &slot->bitmap, line1, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top, fg ); /* increment pen position */ } if(fnt_render==RENDER_NATIVE) { #ifdef USESDL if(sd>-1) fnt_ttf_draw_bitmap_sdl( &slot->bitmap, line1, pen_x + slot->bitmap_left+1, pen_y - slot->bitmap_top+1, sd ); /* increment pen position */ fnt_ttf_draw_bitmap_sdl( &slot->bitmap, line1, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top, fg ); /* increment pen position */ #endif } } pen_x += slot->advance.x >> 6; pen_y += slot->advance.y >> 6; /* not useful for now */ } // printf ("x5\n"); if(fnt_render==RENDER_NATIVE && bg>-1) rectfill(screen,x,y,pen_x+x,pen_y+y,bg); masked_blit(line1,screen,0,0,x,y,pen_x,cfont->scale_h+4); destroy_bitmap(line1); // destroy_bitmap(line0); // printf("%s\n",text); }
void NaroolLurker::calc_lightning() { STACKTRACE; Vector2 P; P = sparkpos; //return; //clear_to_color(lightningbmp, makeacol(0,0,0,255)); //circlefill(lightningbmp, P.x, P.y, 10, makeacol(255,0,0,200)); // first, let the image grow fainter BITMAP *b; b = lightningbmp; int ix, iy; int iw, ih; iw = b->w; ih = b->h; BITMAP *shpbmp; shpbmp = sprite->get_bitmap(sprite_index); // assume it's a 32 bit image ... unsigned char *a; for ( iy = 0; iy < ih; ++iy ) { a = (unsigned char*) b->line[iy]; a += 0; // red = the 3rd color (in my case). for ( ix = 0; ix < iw; ++ix ) { // reduce colors int i; for ( i = 0; i < 3; ++i ) { if (*a > 5) (*a) -= 5; else (*a) = 0; ++a; } ++a; } } if (sparktime > 0) { // create some kind of lightning now ? How ? int i, N; N = 5 + rand() % 5; //graphics double ang, R; //graphics ang = (rand() % 360) * PI/180; for ( i = 0; i < N; ++i ) { double dx, dy; //dx = (random(double(iw)) - 0.5*iw) / N; //dy = (random(double(ih)) - 0.5*ih) / N; //graphics ang += (rand() % 180 - 90) * PI/180; //graphics R = (rand() % int(Rmax+1)) / N; dx = R * cos(ang); dy = R * sin(ang); int j, M; M = 10; for ( j = 0; j < M; ++j ) { P.x += dx / M; P.y += dy / M; int col; int re, gr, bl; col = getpixel(shpbmp, iround(P.x), iround(P.y)); re = getr(col); gr = getg(col); bl = getb(col); if ( !(re == 255 && gr == 0 && bl == 255)) { int k; k = iround(128*(0.5 + 0.5*sparktime/maxsparktime)); // re = 0; // bl = 0; // if ( k > 96) // re = k + 127 / (i+1); // else // bl = k + 127 / (i+1); double c, f; //f = (0.5 + (0.5*sparktime)/maxsparktime); f = sparktime / maxsparktime; c = 255; // / (i+1); re = iround(f * c); bl = iround((1-f) * c); putpixel(b, iround(P.x), iround(P.y), makeacol(re,0,bl,255)); } } } } }
int main() { FONT *lucidia_fnt; FONT *allegro_fnt; DATAFILE *dat; struct { float x, y, z; int c; } coord[NUM_STRINGS]; char *string = STRING; int i; allegro_init(); install_allegro_gl(); install_timer(); LOCK_FUNCTION(the_timer); LOCK_VARIABLE(chrono); install_int(the_timer, 2); allegro_gl_clear_settings(); allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_Z_DEPTH, 24); allegro_gl_set(AGL_WINDOWED, TRUE); allegro_gl_set(AGL_DOUBLEBUFFER, 1); allegro_gl_set(AGL_RENDERMETHOD, 1); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD | AGL_Z_DEPTH | AGL_WINDOWED); if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0)) { allegro_message("Error initializing OpenGL!\n"); return -1; } install_keyboard(); /* Load 2 copies of the datafile */ dat = load_datafile("lucidia.dat"); if (!dat) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to load lucidia.dat\n"); return -2; } lucidia_fnt = allegro_gl_convert_allegro_font((FONT*)dat[0].dat, AGL_FONT_TYPE_TEXTURED, 16.0); if (!lucidia_fnt) { unload_datafile(dat); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to convert font!\n"); return -3; } allegro_fnt = allegro_gl_convert_allegro_font(font, AGL_FONT_TYPE_TEXTURED, 16.0); if (!allegro_fnt) { allegro_gl_destroy_font(lucidia_fnt); unload_datafile(dat); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to convert font!\n"); return -4; } srand(time(NULL)); for (i = 0; i < NUM_STRINGS; i++) { coord[i].z = 0; coord[i].c = 0; } i = 0; /* Start nice text demo */ /* Setup OpenGL like we want */ glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glViewport(0, 0, SCREEN_W, SCREEN_H); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0); /* Set culling mode - not that we have anything to cull */ glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glMatrixMode(GL_MODELVIEW); do { int c; /* Update rotation angle of text */ glLoadIdentity(); glTranslatef(0, 0, -30); glRotatef(-45, 1, 0, 0); glRotatef(-30, 0, 1, 0); /* Clear the screen and set a nice blender mode */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); /* Print the text wheel */ for (i = 0; i < NUM_STRINGS; i++) { allegro_gl_printf(lucidia_fnt, coord[i].x, coord[i].y, coord[i].z, coord[i].c, string); } /* Update the text wheel's position */ for (i = 0; i < NUM_STRINGS; i++) { int r, g, b; float angle2 = angle + i * M_PI * 2 / NUM_STRINGS; coord[i].x = 10 * cos(angle2) - 10; coord[i].y = 10 * sin(angle2); angle2 = angle2 * 180.0 / M_PI; #if ((((ALLEGRO_VERSION) << 16) | ((ALLEGRO_SUB_VERSION) << 8) | (ALLEGRO_WIP_VERSION)) == 0x40200) /* Work around an Allegro bug that's only in 4.2.0 */ while (angle2 > 360.0f) angle2 -= 360.0f; while (angle2 < 0) angle2 += 360.0f; #endif hsv_to_rgb(angle2, 1, 1, &r, &g, &b); coord[i].c = makeacol(r, g, b, 255); } /* Draw "AllegroGL" */ glLoadIdentity(); c = MID(0, (int)(255 - chrono / 100), 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING0) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 0, makecol(c, c, c), STRING0); c = MID(0, (int)(255 - chrono / 100) + 24, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING1) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 12, makecol(c, c, c), STRING1); c = MID(0, (int)(255 - chrono / 100) + 48, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING2) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 24, makecol(c, c, c), STRING2); c = MID(0, (int)(255 - chrono / 100) + 72, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING3) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 36, makecol(c, c, c), STRING3); c = MID(0, (int)(255 - chrono / 100) + 96, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING4) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 48, makecol(c, c, c), STRING4); c = MID(0, (int)(255 - chrono / 100) + 120, 255); allegro_gl_printf(allegro_fnt, -(strlen(URL) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 60, makecol(c, c, c), URL); allegro_gl_flip(); rest(2); } while (!key[KEY_ESC]); return 0; }
// this function void renderDDRHoldNoteBody(int column, int x, int topy, int bot, int color ) { static int columnSource[10] = { 0, 2, 3, 5, 0, 2, 3, 5, 1, 4 }; int frame = 0; int source = 6; int rectcolor = makeacol(arrowColors[5][0], arrowColors[5][1], arrowColors[5][2], 255); if ( color == HOLD_BRIGHT ) { frame = 3; rectcolor = 0xFFDDFFDD; } if ( color == HOLD_MELT ) { source = 8; rectcolor = 0xFF505050; } // down arrows render differently than holds in other columns if ( column == 2 || column == 7 ) { rectfill(rm.m_backbuf, x+1, topy+32, x+62, bot+26, rectcolor); int y = bot + 16; while ( y > topy + 16 ) { masked_blit(m_arrowSource[columnSource[column]][frame][source], rm.m_backbuf, 0, 16, x, y, 64, 48); y -= 16; } // the top of the hold is where the adjustment is made, if the length isn't % 16 int fractionalArrowHeight = (y - topy) % 16; masked_blit(m_arrowSource[columnSource[column]][frame][source], rm.m_backbuf, 0, 0, x, y, 64, fractionalArrowHeight); renderDDRArrow(0, column, source == 8 ? 8 : 5, 0, getColumnOffsetX_DDR(column), topy); } else { // solo arrows are technically a little narrower than other arrows if ( column == 1 || column == 4 ) { rectfill(rm.m_backbuf, x+9, topy+16, x+55, bot+0, rectcolor); } else { rectfill(rm.m_backbuf, x+1, topy+32, x+62, bot+31, rectcolor); } int y = topy; // the top of the hold is where the adjustment is made, if the length isn't % 16 int fractionalArrowHeight = (bot - y) % 16; masked_blit(m_arrowSource[columnSource[column]][frame][source], rm.m_backbuf, 0, 0, x, y, 64, fractionalArrowHeight); y += fractionalArrowHeight; while ( y < bot ) { masked_blit(m_arrowSource[columnSource[column]][frame][source], rm.m_backbuf, 0, 0, x, y, 64, 48); y += 16; } masked_blit(m_arrowSource[columnSource[column]][frame][source], rm.m_backbuf, 0, 0, x, bot, 64, 64); renderDDRArrow(0, column, source == 8 ? 8 : 5, 0, getColumnOffsetX_DDR(column), topy); } }
int main(void) { BITMAP *dbuf; BITMAP *b; BITMAP *b2; int mode = NORMAL; float fangle = 0; float fscale = 1; float inc = 0.002; int dir = -1; if (allegro_init() != 0) { return 1; } set_color_depth(32); install_keyboard(); if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) { allegro_message("Could not set graphics mode\n"); return 1; } dbuf = create_bitmap(SCREEN_W, SCREEN_H); if (!dbuf) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Could not create double buffer\n"); return 1; } /* Load the alpha bitmap. This is used for alpha and normal modes */ set_color_conversion(COLORCONV_KEEP_ALPHA); b = load_bitmap("inkblot.tga", NULL); if (!b) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Could not load inkblot.tga\n"); return 1; } /* Make a non-alpha copy for drawing lit */ b2 = create_bitmap(b->w, b->h); if (!b2) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error creating bitmap\n"); return 1; } clear_to_color(b2, makeacol(255, 255, 255, 255)); set_alpha_blender(); draw_trans_sprite(b2, b, 0, 0); while (!key[KEY_ESC]) { fixed angle = ftofix(fangle); fixed scale = ftofix(fscale); float x = (SCREEN_W-(b->w*fscale))/2; float y = (SCREEN_H-(b->h*fscale))/2; /* XXX flickers badly due to no buffering */ clear_to_color(dbuf, makecol(255, 255, 255)); textout_centre_ex(dbuf, font, "Press 'n' for next mode", SCREEN_W/2, SCREEN_H-30, makecol(0, 0, 0), -1); switch (mode) { case NORMAL: rotate_scaled_sprite(dbuf, b, x, y, angle, scale); textout_centre_ex(dbuf, font, "Normal", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1); break; case ALPHA: set_alpha_blender(); rotate_scaled_sprite_trans(dbuf, b, x, y, angle, scale); textout_centre_ex(dbuf, font, "Alpha", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1); break; case LIT: set_trans_blender(255, 0, 0, 0); rotate_scaled_sprite_lit(dbuf, b2, x, y, angle, scale, 128); textout_centre_ex(dbuf, font, "Lit", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1); break; } blit(dbuf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); fangle += 1; fscale += dir*inc; if (fscale < 0.5) { dir = -dir; fscale = 0.5; } else if (fscale > 1) { dir = -dir; fscale = 1; } rest(5); if (keypressed()) { int k = readkey(); switch (k >> 8) { case KEY_N: mode++; mode %= 3; break; } } } destroy_bitmap(b); destroy_bitmap(b2); destroy_bitmap(dbuf); return 0; }