/* init_gfx: * Set up graphics mode. */ static int init_gfx(PALETTE pal) { int i; int gfx_mode = GFX_AUTODETECT; int w, h, bpp; /* color 0 = black */ pal[0].r = pal[0].g = pal[0].b = 0; /* color 1 = red */ pal[1].r = 63; pal[1].g = pal[1].b = 0; /* copy the desktop palette */ for (i = 2; i < 64; i++) { pal[i] = desktop_palette[i]; } ///* make a blue gradient */ for (i = 64; i < 96; i++) { pal[i].b = (byte)((i - 64) * 2); pal[i].g = pal[i].r = 0; } for (i = 96; i < 256; i++) { pal[i].r = pal[i].g = pal[i].b = 0; } /* set the graphics mode */ if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to set any graphic mode\n{0}\n", allegro_error)); return(1); } set_palette(desktop_palette); w = SCREEN_W; h = SCREEN_H; bpp = bitmap_color_depth(screen); if (gfx_mode_select_ex(ref gfx_mode, ref w, ref h, ref bpp) == 0) { allegro_exit(); return(1); } set_color_depth(bpp); if (set_gfx_mode(gfx_mode, w, h, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error setting graphics mode\n{0}\n", allegro_error)); return(1); } return(0); }
static int show(string name) { BITMAP bmp, buffer; PALETTE pal = new PALETTE(); int alpha; /* load the file */ bmp = load_bitmap(name, pal); if (!bmp) { return(-1); } buffer = create_bitmap(SCREEN_W, SCREEN_H); blit(screen, buffer, 0, 0, 0, 0, SCREEN_W, SCREEN_H); set_palette(pal); /* fade it in on top of the previous picture */ for (alpha = 0; alpha < 256; alpha += 8) { set_trans_blender(0, 0, 0, alpha); draw_trans_sprite(buffer, bmp, (SCREEN_W - bmp.w) / 2, (SCREEN_H - bmp.h) / 2); vsync(); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); if (keypressed()) { destroy_bitmap(bmp); destroy_bitmap(buffer); if ((readkey() & 0xFF) == 27) { return(1); } else { return(0); } } } blit(bmp, screen, 0, 0, (SCREEN_W - bmp.w) / 2, (SCREEN_H - bmp.h) / 2, bmp.w, bmp.h); destroy_bitmap(bmp); destroy_bitmap(buffer); if ((readkey() & 0xFF) == 27) { return(1); } else { return(0); } }
/* The negative_color function is quite the same like the grayscale one, * since we are ignoring the value of the drawn color (aka x). */ static void return_negative_color(IntPtr ppal, int x, int y, IntPtr prgb) { // TODO: are the following 2 lines necessary? PALETTE pal = ppal; RGB rgb = prgb; /* To get the negative color, subtract the color values of red, green * and blue from the full (63) color value. */ rgb.r = (byte)(63 - pal[y].r); rgb.g = (byte)(63 - pal[y].g); rgb.b = (byte)(63 - pal[y].b); }
static void test(int colordepth) { PALETTE pal = new PALETTE(); int x; /* set the screen mode */ set_color_depth(colordepth); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { return; } /* in case this is a 256 color mode, we'd better make sure that the * palette is set to something sensible. This function generates a * standard palette with a nice range of different colors... */ generate_332_palette(pal); set_palette(pal); acquire_screen(); clear_to_color(screen, makecol(0, 0, 0)); textprintf_ex(screen, font, 0, 0, makecol(255, 255, 255), -1, colordepth + " bit color..."); /* use the makecol() function to specify RGB values... */ textout_ex(screen, font, "Red", 32, 80, makecol(255, 0, 0), -1); textout_ex(screen, font, "Green", 32, 100, makecol(0, 255, 0), -1); textout_ex(screen, font, "Blue", 32, 120, makecol(0, 0, 255), -1); textout_ex(screen, font, "Yellow", 32, 140, makecol(255, 255, 0), -1); textout_ex(screen, font, "Cyan", 32, 160, makecol(0, 255, 255), -1); textout_ex(screen, font, "Magenta", 32, 180, makecol(255, 0, 255), -1); textout_ex(screen, font, "Grey", 32, 200, makecol(128, 128, 128), -1); /* or we could draw some nice smooth color gradients... */ for (x = 0; x < 256; x++) { vline(screen, 192 + x, 112, 176, makecol(x, 0, 0)); vline(screen, 192 + x, 208, 272, makecol(0, x, 0)); vline(screen, 192 + x, 304, 368, makecol(0, 0, x)); } textout_centre_ex(screen, font, "<press a key>", SCREEN_W / 2, SCREEN_H - 16, makecol(255, 255, 255), -1); release_screen(); readkey(); }
/* Here comes our custom function. It's designed to take the input colors * (red, green & blue) and return a greyscale color for it. This way, when * any drawing function draws say over green, it draws the greyscale color * for green. * 'pal' is the palette we are looking in to find the colors. * Now, imagine we want to draw a pixel with color A, over color B. * Once the table is created, set, and the drawing mode is TRANSLUCENT, then * A is the 'x' color passed to the function and B is the 'y' color passed * to the function. * Since we want a greyscale effect with no matter what A (or 'x') color, we * ignore it and use y to look at the palette. * NOTE: * When you return the rgb value, you don't need to search the palette for * the nearest color, Allegro does this automatically. */ static void return_grey_color(IntPtr ppal, int x, int y, IntPtr prgb) { int c; // TODO: are the following 2 lines necessary? PALETTE pal = ppal; RGB rgb = prgb; /* first create the greyscale color */ c = (int)(pal[y].r * 0.3 + pal[y].g * 0.5 + pal[y].b * 0.2); /* now assign to our rgb triplet the palette greyscale color... */ rgb.r = rgb.g = rgb.b = (byte)c; }
static int Main(string[] argv) { BITMAP the_image; PALETTE the_palette = new PALETTE(); if (allegro_init() != 0) { return(1); } if (argv.Length != 1) { allegro_message("Usage: 'exbitmap filename.[bmp|lbm|pcx|tga]'\n"); return(1); } install_keyboard(); if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n" + allegro_error); return(1); } } /* read in the bitmap file */ the_image = load_bitmap(argv[0], the_palette); if (!the_image) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error reading bitmap file '{0}'\n", argv[0])); return(1); } /* select the bitmap palette */ set_palette(the_palette); /* blit the image onto the screen */ blit(the_image, screen, 0, 0, (SCREEN_W - the_image.w) / 2, (SCREEN_H - the_image.h) / 2, the_image.w, the_image.h); /* destroy the bitmap */ destroy_bitmap(the_image); readkey(); return(0); }
static int Main(string[] argv) { PALETTE my_palette = new PALETTE(); BITMAP scr_buffer; byte[] pcx_name = new byte[256]; if (allegro_init() != 0) { return(1); } install_keyboard(); if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n" + allegro_error); return(1); } } replace_filename(pcx_name, "./", "mysha.pcx", 256); scr_buffer = load_pcx(Encoding.ASCII.GetString(pcx_name), my_palette); if (!scr_buffer) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error loading " + pcx_name + "!\n"); return(1); } set_palette(my_palette); blit(scr_buffer, screen, 0, 0, 0, 0, scr_buffer.w, scr_buffer.h); while (!keypressed()) { stretch_blit(scr_buffer, screen, 0, 0, AL_RAND() % scr_buffer.w, AL_RAND() % scr_buffer.h, AL_RAND() % SCREEN_W, AL_RAND() % SCREEN_H, AL_RAND() % SCREEN_W, AL_RAND() % SCREEN_H); vsync(); } destroy_bitmap(scr_buffer); return(0); }
/* converts a bitmap from the normal Allegro format into our magic layout */ static BITMAP get_magic_bitmap_format(BITMAP orig, PALETTE pal) { BITMAP bmp; int c, r, g, b; int x, y; int bpp; /* create an 8 bpp image, three times as wide as the original */ bmp = create_bitmap_ex(8, orig.w * 3, orig.h); /* store info about the original bitmap format */ bpp = bitmap_color_depth(orig); //select_palette(pal); /* convert the data */ for (y = 0; y < orig.h; y++) { for (x = 0; x < orig.w; x++) { c = getpixel(orig, x, y); r = getr_depth(bpp, c); g = getg_depth(bpp, c); b = getb_depth(bpp, c); //bmp->line[y][x*3] = r*31/255 | AMBIENT_LIGHT; //bmp->line[y][x*3+1] = g*31/255 | AMBIENT_LIGHT; //bmp->line[y][x*3+2] = b*31/255 | AMBIENT_LIGHT; r = (r * 31 / 255) | AMBIENT_LIGHT; g = (g * 31 / 255) | AMBIENT_LIGHT; b = (b * 31 / 255) | AMBIENT_LIGHT; ManagedBytePointerArray line = new ManagedBytePointerArray(bmp.line).Offset(y * 3 * orig.w * sizeof(byte)); line[x * 3] = (byte)r; line[x * 3 + 1] = (byte)g; line[x * 3 + 2] = (byte)b; } } /* return our new, magic format version of the image */ return(bmp); }
/* Genesis */ public world() { PALETTE pal = new PALETTE(); active = TRUE; dbuffer = create_bitmap(SCREEN_W, SCREEN_H); mouse_sprite = load_bitmap("../examples/mysha.pcx", pal); if (!mouse_sprite) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error loading bitmap\n{0}\n", allegro_error)); //exit(1); } set_palette(pal); for (int what_mouse = 0; what_mouse < RODENTS; what_mouse++) { mouse[what_mouse] = new rodent(mouse_sprite); } }
/* these functions can be used in any 12-bit program */ //int makecol12(int r, int g, int b); //void set_12bit_palette(); //BITMAP create_bitmap_12(int w, int h); /* these functions are just for this example */ //void blur_12(BITMAP bmp, BITMAP back); //void rgb_scales_12(BITMAP bmp, int ox, int oy, int w, int h); //POINT_T make_points(ref int numpoints, string msg); //BITMAP make_ball(int w, int h, int br, int bg, int bb); /* construct the magic palette that makes it all work */ static void set_12bit_palette() { int r, g, b; PALETTE pal = new PALETTE(); for (b = 0; b < 15; b++) { for (g = 0; g < 16; g++) { pal[b * 16 + g].r = 0; pal[b * 16 + g].g = (byte)(g * 63 / 15); pal[b * 16 + g].b = (byte)(b * 63 / 15); } } for (r = 0; r < 16; r++) { pal[r + 240].r = (byte)(r * 63 / 15); pal[r + 240].g = 0; pal[r + 240].b = 0; } set_palette(pal); }
static int Main(string[] argv) { PALETTE pal = new PALETTE(); BITMAP s; BITMAP spotlight; BITMAP truecolor_spotlight; BITMAP background; int i, x, y; byte[] buf = new byte[256]; string filename; if (allegro_init() != 0) { return(1); } install_keyboard(); install_timer(); install_mouse(); if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to set any graphic mode\n{0}\n", allegro_error)); return(1); } } /* load the main screen image */ if (argv.Length > 0) { filename = argv[1]; } else { replace_filename(buf, "./", "allegro.pcx", buf.Length); filename = Encoding.ASCII.GetString(buf); } background = load_bitmap(filename, pal); if (!background) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error reading {0}!\n", filename)); return(1); } /* this isn't needed, but it speeds up the color table calculations */ create_rgb_table(rgb_table, pal, NULL); rgb_map = rgb_table; /* build a color lookup table for lighting effects */ create_light_table(light_table, pal, 0, 0, 0, NULL); /* build a color lookup table for translucent drawing */ create_trans_table(trans_table, pal, 128, 128, 128, NULL); set_palette(pal); s = create_bitmap(320, 200); spotlight = create_bitmap_ex(8, 128, 128); truecolor_spotlight = create_bitmap_ex(32, 128, 128); /* generate an 8bpp spotlight image */ clear_bitmap(spotlight); for (i = 0; i < 256; i++) { circlefill(spotlight, 64, 64, 64 - i / 4, i); } /* select the lighting table */ color_map = light_table; /* display a spotlight effect */ do { poll_mouse(); x = mouse_x - SCREEN_W / 2 - 64 + 160; y = mouse_y - SCREEN_H / 2 - 64 + 100; clear_bitmap(s); /* unluckily we have to do something 'weird' for truecolor modes */ if (bitmap_color_depth(screen) != 8) { /* copy background on the truecolor spotlight */ blit(background, truecolor_spotlight, x, y, 0, 0, 127, 127); /* set special write alpha blender */ set_write_alpha_blender(); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); /* draw the alpha channel */ rectfill(truecolor_spotlight, 0, 0, 128, 128, 0); draw_trans_sprite(truecolor_spotlight, spotlight, 0, 0); /* set alpha blender and draw on the 's' bitmap */ drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); set_alpha_blender(); draw_trans_sprite(s, truecolor_spotlight, x, y); /* restore a not-alpha blender */ set_trans_blender(0, 0, 0, 128); } else { blit(background, s, x, y, x, y, 128, 128); draw_trans_sprite(s, spotlight, x, y); } blit(s, screen, 0, 0, SCREEN_W / 2 - 160, SCREEN_H / 2 - 100, 320, 200); /* reduce CPU usage */ rest(20); } while (!keypressed()); clear_keybuf(); /* for the next part we want spotlight and s to share color depth */ if (bitmap_color_depth(spotlight) != bitmap_color_depth(s)) { destroy_bitmap(spotlight); spotlight = create_bitmap(128, 128); } /* generate an overlay image (just shrink the main image) */ stretch_blit(background, spotlight, 0, 0, 320, 200, 0, 0, 128, 128); /* select the translucency table */ color_map = trans_table; /* select translucency blender */ set_trans_blender(0, 0, 0, 128); /* display a translucent overlay */ do { poll_mouse(); x = mouse_x - SCREEN_W / 2 - 64 + 160; y = mouse_y - SCREEN_H / 2 - 64 + 100; blit(background, s, 0, 0, 0, 0, 320, 200); draw_trans_sprite(s, spotlight, x, y); blit(s, screen, 0, 0, SCREEN_W / 2 - 160, SCREEN_H / 2 - 100, 320, 200); /* reduce CPU usage */ rest(20); } while (!keypressed()); clear_keybuf(); destroy_bitmap(s); destroy_bitmap(spotlight); destroy_bitmap(truecolor_spotlight); destroy_bitmap(background); return(0); }
static int Main() { ZBUFFER zbuf; BITMAP buffer; PALETTE pal = new PALETTE(); MATRIX_f matrix1 = new MATRIX_f(), matrix2 = new MATRIX_f(); V3D_f[] x1 = new V3D_f[8], x2 = new V3D_f[8]; int i; int c = GFX_AUTODETECT; int w, h, bpp; int frame = 0; float fps = 0.0F; float rx1, ry1, rz1; /* cube #1 rotations */ float drx1, dry1, drz1; /* cube #1 rotation speed */ float rx2, ry2, rz2; /* cube #2 rotations */ float drx2, dry2, drz2; /* cube #1 rotation speed */ float tx = 16.0F; /* x shift between cubes */ float tz1 = 100.0F; /* cube #1 z coordinate */ float tz2 = 105.0F; /* cube #2 z coordinate */ if (allegro_init() != 0) { return(1); } install_keyboard(); install_mouse(); install_timer(); LOCK_VARIABLE(t); LOCK_FUNCTION(t_tick); install_int(tick, 10); /* color 0 = black */ pal[0].r = pal[0].g = pal[0].b = 0; /* color 1 = red */ pal[1].r = 255; pal[1].g = pal[1].b = 0; /* copy the desktop palette */ for (i = 1; i < 64; i++) { pal[i] = desktop_palette[i]; } /* make a blue gradient */ for (i = 64; i < 96; i++) { pal[i].b = (byte)((i - 64) * 2); pal[i].g = pal[i].r = 0; } /* make a green gradient */ for (i = 96; i < 128; i++) { pal[i].g = (byte)((i - 96) * 2); pal[i].r = pal[i].b = 0; } /* set the graphics mode */ if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to set any graphic mode\n{0}\n", allegro_error)); return(1); } set_palette(desktop_palette); w = SCREEN_W; h = SCREEN_H; bpp = bitmap_color_depth(screen); if (gfx_mode_select_ex(ref c, ref w, ref h, ref bpp) == 0) { allegro_exit(); return(1); } set_color_depth(bpp); if (set_gfx_mode(c, w, h, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error setting graphics mode\n{0}\n", allegro_error)); return(1); } set_palette_range(pal, 0, 127, FALSE); /* double buffer the animation and create the Z-buffer */ buffer = create_bitmap(SCREEN_W, SCREEN_H); zbuf = create_zbuffer(buffer); set_zbuffer(zbuf); /* set up the viewport for the perspective projection */ set_projection_viewport(0, 0, SCREEN_W, SCREEN_H); /* compute rotations and speed rotation */ rx1 = ry1 = rz1 = 0.0F; rx2 = ry2 = rz2 = 0.0F; drx1 = (float)(((AL_RAND() & 31) - 16) / 4.0); dry1 = (float)(((AL_RAND() & 31) - 16) / 4.0); drz1 = (float)(((AL_RAND() & 31) - 16) / 4.0); drx2 = (float)(((AL_RAND() & 31) - 16) / 4.0); dry2 = (float)(((AL_RAND() & 31) - 16) / 4.0); drz2 = (float)(((AL_RAND() & 31) - 16) / 4.0); /* set the transformation matrices */ get_transformation_matrix_f(ref matrix1, 1.0F, rx1, ry1, rz1, tx, 0.0F, tz1); get_transformation_matrix_f(ref matrix2, 1.0F, rx2, ry2, rz2, -tx, 0.0F, tz2); /* set colors */ for (i = 0; i < 8; i++) { x1[i].c = palette_color[cube1[i].c]; x2[i].c = palette_color[cube2[i].c]; } /* main loop */ while (true) { clear_bitmap(buffer); clear_zbuffer(zbuf, 0.0F); anim_cube(matrix1, matrix2, x1, x2); draw_cube(buffer, x1, x2); /* update transformation matrices */ rx1 += drx1; ry1 += dry1; rz1 += drz1; rx2 += drx2; ry2 += dry2; rz2 += drz2; get_transformation_matrix_f(ref matrix1, 1.0F, rx1, ry1, rz1, tx, 0.0F, tz1); get_transformation_matrix_f(ref matrix2, 1.0F, rx2, ry2, rz2, -tx, 0.0F, tz2); //textprintf_ex(buffer, font, 10, 1, palette_color[1], 0, // string.Format("Z-buffered polygons ({0:.0} fps)", fps)); textprintf_ex(buffer, font, 10, 1, makecol(255, 0, 0), 0, string.Format("Z-buffered polygons ({0:.0} fps)", fps)); vsync(); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); frame++; if (t > 100) { fps = (float)((100.0 * frame) / t); t = 0; frame = 0; } if (keypressed()) { if ((readkey() & 0xFF) == 27) { break; } } } destroy_bitmap(buffer); destroy_zbuffer(zbuf); return(0); }
static int Main() { PALETTE pal = new PALETTE(); bool finished = false; int last_counter = 0; int c = GFX_AUTODETECT; int w, h, bpp, i; if (allegro_init() != 0) { return(1); } install_keyboard(); install_mouse(); install_timer(); if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n" + allegro_error); return(1); } set_palette(desktop_palette); w = SCREEN_W; h = SCREEN_H; bpp = bitmap_color_depth(screen); if (gfx_mode_select_ex(ref c, ref w, ref h, ref bpp) == 0) { allegro_exit(); return(1); } set_color_depth(bpp); if (set_gfx_mode(c, w, h, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error setting graphics mode\n" + allegro_error); return(1); } for (i = 0; i < 256; i++) { pal[i].r = pal[i].g = pal[i].b = (byte)(i / 4); } int c0 = makecol(pal[0].r, pal[0].g, pal[0].b); int c255 = makecol(pal[255].r, pal[255].g, pal[255].b); set_palette(pal); int c2 = palette_color[255]; text_area = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H / 2); graphics_area = create_sub_bitmap(screen, 0, SCREEN_H / 2, SCREEN_W / 2, SCREEN_H / 2); if ((!text_area) || (!graphics_area)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Out of memory!\n"); return(1); } LOCK_VARIABLE(counter); LOCK_FUNCTION(t_counter); install_int(t_counter, 10); show_msg("Console switching test"); show_msg("Press 1-5 to change mode"); show_msg(null); show_switch_mode(); show_msg(null); while (!finished) { if (counter != last_counter) { last_counter = counter; acquire_screen(); textprintf_centre_ex(screen, font, SCREEN_W * 3 / 4, SCREEN_H * 3 / 4, //palette_color[255], palette_color[0], c255, c0, "Time: " + last_counter); release_screen(); acquire_bitmap(graphics_area); for (i = 0; i < 10; i++) { draw_pointless_graphics(); } release_bitmap(graphics_area); } if (keypressed()) { switch (readkey() & 255) { case '1': set_sw_mode(SWITCH_NONE); break; case '2': set_sw_mode(SWITCH_PAUSE); break; case '3': set_sw_mode(SWITCH_AMNESIA); break; case '4': set_sw_mode(SWITCH_BACKGROUND); break; case '5': set_sw_mode(SWITCH_BACKAMNESIA); break; case 27: finished = true; break; } } while (in_callback > 0) { in_callback--; show_msg("SWITCH_IN callback"); show_msg(null); } while (out_callback > 0) { out_callback--; show_msg("SWITCH_OUT callback"); show_msg(null); } } destroy_bitmap(text_area); destroy_bitmap(graphics_area); return(0); }
static int Main(string[] argv) { PALETTE pal = new PALETTE(); BITMAP[] bmp = new BITMAP[3]; int card = GFX_AUTODETECT; int w, h, bpp, page, i; if (allegro_init() != 0) { return(1); } /* check command line arguments */ if (argv.Length == 1) { num_pages = int.Parse(argv[0]); } else { num_pages = 0; } if (num_pages == 4) { num_pages = 1; use_system_bitmaps = true; } else { use_system_bitmaps = false; } if ((num_pages < 1) || (num_pages > 3)) { allegro_message("\nUsage: 'exupdate num_pages', where num_pages is one of:\n\n" + "1 = double buffered (memory bitmap)\n\n" + " + easy, reliable\n" + " + drawing onto a memory bitmap is very fast\n" + " - blitting the finished image to the screen can be quite slow\n\n" + "2 = page flipping (two pages of video memory)\n\n" + " + avoids the need for a memory to screen blit of the completed image\n" + " + can use hardware acceleration when it is available\n" + " - drawing directly to vram can be slower than using a memory bitmap\n" + " - requires a card with enough video memory for two screen pages\n\n" + "3 = triple buffered (three pages of video memory)\n\n" + " + like page flipping, but faster and smoother\n" + " - requires a card with enough video memory for three screen pages\n" + " - only possible with some graphics drivers\n\n" + "4 = double buffered (system bitmap)\n\n" + " + as easy as normal double buffering\n" + " + system bitmaps can be hardware accelerated on some platforms\n" + " - drawing to system bitmaps is sometimes slower than memory bitmaps\n\n"); return(1); } /* set up Allegro */ install_keyboard(); install_timer(); install_mouse(); if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to set any graphic mode\n{0}\n", allegro_error)); return(1); } set_palette(desktop_palette); w = SCREEN_W; h = SCREEN_H; bpp = bitmap_color_depth(screen); if (gfx_mode_select_ex(ref card, ref w, ref h, ref bpp) == 0) { return(0); } set_color_depth(bpp); #if ALLEGRO_VRAM_SINGLE_SURFACE if (set_gfx_mode(card, w, h, w, num_pages * h) != 0) { #else if (set_gfx_mode(card, w, h, 0, 0) != 0) { #endif set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error setting graphics mode\n{0}\n", allegro_error)); return(1); } generate_332_palette(pal); pal[0].r = pal[0].g = pal[0].b = 0; set_palette(pal); switch (num_pages) { case 1: /* double buffering setup */ if (use_system_bitmaps) { bmp[0] = create_system_bitmap(SCREEN_W, SCREEN_H); } else { bmp[0] = create_bitmap(SCREEN_W, SCREEN_H); } break; case 2: /* page flipping setup */ bmp[0] = create_video_bitmap(SCREEN_W, SCREEN_H); bmp[1] = create_video_bitmap(SCREEN_W, SCREEN_H); break; case 3: /* triple buffering setup */ if ((gfx_capabilities & GFX_CAN_TRIPLE_BUFFER) == 0) { enable_triple_buffer(); } if ((gfx_capabilities & GFX_CAN_TRIPLE_BUFFER) == 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); #if ALLEGRO_DOS allegro_message("This driver does not support triple buffering\n" "\nTry using mode-X in clean DOS mode (not under " "Windows)\n"); #else allegro_message("This driver does not support triple buffering\n"); #endif return(1); } bmp[0] = create_video_bitmap(SCREEN_W, SCREEN_H); bmp[1] = create_video_bitmap(SCREEN_W, SCREEN_H); bmp[2] = create_video_bitmap(SCREEN_W, SCREEN_H); break; } for (i = 0; i < num_pages; i++) { if (!bmp[i]) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to create {0} video memory pages\n", num_pages)); return(1); } } /* install timer handlers to control and measure the program speed */ LOCK_VARIABLE(update_count); LOCK_VARIABLE(frame_count); LOCK_VARIABLE(fps); LOCK_FUNCTION(t_timer); LOCK_FUNCTION(t_fps); install_int_ex(timer_proc, BPS_TO_TIMER(60)); install_int_ex(fps_proc, BPS_TO_TIMER(1)); page = 1; /* main program loop */ while (!keypressed()) { /* draw the next frame of graphics */ switch (num_pages) { case 1: /* draw onto a memory bitmap, then blit to the screen */ draw_screen(bmp[0]); vsync(); blit(bmp[0], screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); break; case 2: /* flip back and forth between two pages of video memory */ draw_screen(bmp[page]); show_video_bitmap(bmp[page]); page = 1 - page; break; case 3: /* triple buffering */ draw_screen(bmp[page]); do { } while (poll_scroll()); request_video_bitmap(bmp[page]); page = (page + 1) % 3; break; } /* update the program state */ while (update_count > 0) { do_update(); update_count--; } frame_count++; } for (i = 0; i < num_pages; i++) { destroy_bitmap(bmp[i]); } return(0); } }
static int Main() { BITMAP buffer; PALETTE pal = new PALETTE(); int c, w, h, bpp; int last_retrace_count; if (allegro_init() != 0) { return(1); } install_keyboard(); install_mouse(); install_timer(); /* color 0 = black */ pal[0].r = pal[0].g = pal[0].b = 0; /* copy the desktop palette */ for (c = 1; c < 64; c++) { pal[c] = desktop_palette[c]; } /* make a red gradient */ for (c = 64; c < 96; c++) { pal[c].r = (byte)((c - 64) * 2); pal[c].g = pal[c].b = 0; } /* make a green gradient */ for (c = 96; c < 128; c++) { pal[c].g = (byte)((c - 96) * 2); pal[c].r = pal[c].b = 0; } /* set up a greyscale in the top half of the palette */ for (c = 128; c < 256; c++) { pal[c].r = pal[c].g = pal[c].b = (byte)((c - 128) / 2); } /* build rgb_map table */ create_rgb_table(rgb_table, pal, NULL); rgb_map = rgb_table; /* build a lighting table */ create_light_table(light_table, pal, 0, 0, 0, NULL); color_map = light_table; /* build a transparency table */ /* textures are 25% transparent (75% opaque) */ create_trans_table(trans_table, pal, 192, 192, 192, NULL); /* set up the truecolor blending functions */ /* textures are 25% transparent (75% opaque) */ set_trans_blender(0, 0, 0, 192); /* set the graphics mode */ if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to set any graphic mode\n{0}\n", allegro_error)); return(1); } set_palette(desktop_palette); c = GFX_AUTODETECT; w = SCREEN_W; h = SCREEN_H; bpp = bitmap_color_depth(screen); if (gfx_mode_select_ex(ref c, ref w, ref h, ref bpp) == 0) { allegro_exit(); return(1); } set_color_depth(bpp); if (set_gfx_mode(c, w, h, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error setting graphics mode\n{0}\n", allegro_error)); return(1); } set_palette(pal); /* make a bitmap for use as a texture map */ texture = create_bitmap(32, 32); clear_to_color(texture, bitmap_mask_color(texture)); line(texture, 0, 0, 31, 31, palette_color[1]); line(texture, 0, 31, 31, 0, palette_color[1]); rect(texture, 0, 0, 31, 31, palette_color[1]); textout_ex(texture, font, "dead", 0, 0, palette_color[2], -1); textout_ex(texture, font, "pigs", 0, 8, palette_color[2], -1); textout_ex(texture, font, "cant", 0, 16, palette_color[2], -1); textout_ex(texture, font, "fly.", 0, 24, palette_color[2], -1); /* double buffer the animation */ buffer = create_bitmap(SCREEN_W, SCREEN_H); /* set up the viewport for the perspective projection */ set_projection_viewport(0, 0, SCREEN_W, SCREEN_H); /* initialise the bouncing shapes */ init_shapes(); last_retrace_count = retrace_count; for (; ;) { clear_bitmap(buffer); while (last_retrace_count < retrace_count) { animate_shapes(); last_retrace_count++; } translate_shapes(); draw_shapes(buffer); textprintf_ex(buffer, font, 0, 0, palette_color[192], -1, string.Format("{0}, {1} bpp", mode_desc[(int)_render_mode], bitmap_color_depth(screen))); textout_ex(buffer, font, "Press a key to change", 0, 12, palette_color[192], -1); vsync(); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); if (keypressed()) { if ((readkey() & 0xFF) == 27) { break; } else { _render_mode++; if (_render_mode >= render_mode.last_mode) { _render_mode = render_mode.wireframe; color_map = light_table; } if (render_type[(int)_render_mode] >= POLYTYPE_ATEX_TRANS) { color_map = trans_table; } } } } destroy_bitmap(buffer); destroy_bitmap(texture); return(0); }
unsafe static int Main() { PALETTE palette = new PALETTE(); uint address; int x, y, c; if (allegro_init() != 0) { return(1); } install_keyboard(); if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { allegro_message(string.Format("Error setting graphics mode\n{0}\n", allegro_error)); return(1); } } temp = new byte[SCREEN_W]; if (temp == null) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Not enough memory? This is a joke right!?!\n"); return(0); } for (c = 0; c < FIRE_HOTSPOTS; c++) { hotspot[c] = AL_RAND() % SCREEN_W; } /* fill our palette with a gradually altering sequence of colors */ for (c = 0; c < 64; c++) { palette[c].r = (byte)c; palette[c].g = 0; palette[c].b = 0; } for (c = 64; c < 128; c++) { palette[c].r = 63; palette[c].g = (byte)(c - 64); palette[c].b = 0; } for (c = 128; c < 192; c++) { palette[c].r = 63; palette[c].g = 63; palette[c].b = (byte)(c - 128); } for (c = 192; c < 256; c++) { palette[c].r = 63; palette[c].g = 63; palette[c].b = 63; } set_palette(palette); textout_ex(screen, font, "Using get/putpixel()", 0, 0, makecol(255, 255, 255), makecol(0, 0, 0)); /* using getpixel() and putpixel() is slow :-) */ while (!keypressed()) { acquire_screen(); draw_bottom_line_of_fire(); for (y = 64; y < SCREEN_H - 1; y++) { /* read line */ for (x = 0; x < SCREEN_W; x++) { c = getpixel(screen, x, y + 1); if (c > 0) { c--; } putpixel(screen, x, y, c); } } release_screen(); } clear_keybuf(); textout_ex(screen, font, "Using direct memory writes", 0, 0, makecol(255, 255, 255), makecol(0, 0, 0)); /* It is much faster if we access the screen memory directly. This * time we read an entire line of the screen into our own buffer, * modify it there, and then write the whole line back in one go. * That is to avoid having to keep switching back and forth between * different scanlines: if we only copied one pixel at a time, we * would have to call bmp_write_line() for every single pixel rather * than just twice per line. */ while (!keypressed()) { acquire_screen(); draw_bottom_line_of_fire(); bmp_select(screen); for (y = 64; y < SCREEN_H - 1; y++) { /* get an address for reading line y+1 */ address = (uint)bmp_read_line(screen, y + 1); /* read line with farptr functions */ for (x = 0; x < SCREEN_W; x++) { temp[x] = bmp_read8((int)(address + x)); } /* adjust it */ for (x = 0; x < SCREEN_W; x++) { if (temp[x] > 0) { temp[x]--; } } /* get an address for writing line y */ address = bmp_write_line(screen, y); /* write line with farptr functions */ for (x = 0; x < SCREEN_W; x++) { bmp_write8((int)(address + x), temp[x]); } } bmp_unwrite_line(screen); release_screen(); } clear_keybuf(); textout_ex(screen, font, "Using block data transfers", 0, 0, makecol(255, 255, 255), makecol(0, 0, 0)); /* It is even faster if we transfer the data in 32 bit chunks, rather * than only one pixel at a time. This method may not work on really * unusual machine architectures, but should be ok on just about * anything that you are practically likely to come across. */ while (!keypressed()) { acquire_screen(); draw_bottom_line_of_fire(); bmp_select(screen); for (y = 64; y < SCREEN_H - 1; y++) { /* get an address for reading line y+1 */ address = (uint)bmp_read_line(screen, y + 1); /* read line in 32 bit chunks */ for (x = 0; x < SCREEN_W; x += sizeof(uint)) //*((uint*)&temp[x]) = (uint)bmp_read32((int)(address + x)); fixed(byte *addr = temp) { *((uint *)(addr + x)) = (uint)bmp_read32((int)(address + x)); } /* adjust it */ for (x = 0; x < SCREEN_W; x++) { if (temp[x] > 0) { temp[x]--; } } /* get an address for writing line y */ address = bmp_write_line(screen, y); /* write line in 32 bit chunks */ for (x = 0; x < SCREEN_W; x += sizeof(uint)) //bmp_write32((int)(address + x), *((uint*)&temp[x])); fixed(byte *addr = temp) { bmp_write32((uint)(address + x), (int)*((uint *)(addr + x))); } } bmp_unwrite_line(screen); release_screen(); } //free(temp); return(0); }
public static int Main(string[] argv) { byte[] buf = new byte[256]; PALETTE pal = new PALETTE(); BITMAP image; BITMAP[] page = new BITMAP[2]; BITMAP vimage; IMAGE[] images = new IMAGE[MAX_IMAGES]; int num_images = 4; int page_num = 1; bool done = false; int i; if (allegro_init() != 0) { return(1); } install_keyboard(); install_timer(); /* see comments in exflip.c */ #if ALLEGRO_VRAM_SINGLE_SURFACE if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 2 * 768 + 200) != 0) { #else if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) { #endif set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error setting graphics mode\n{0}\n", allegro_error)); return(1); } /* read in the source graphic */ replace_filename(buf, "./", "mysha.pcx", buf.Length); image = load_bitmap(Encoding.ASCII.GetString(buf), pal); if (!image) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error reading {0}!\n", buf)); return(1); } set_palette(pal); /* initialise the images to random positions */ for (i = 0; i < MAX_IMAGES; i++) { init_image(ref images[i]); } /* create two video memory bitmaps for page flipping */ page[0] = create_video_bitmap(SCREEN_W, SCREEN_H); page[1] = create_video_bitmap(SCREEN_W, SCREEN_H); /* create a video memory bitmap to store our picture */ vimage = create_video_bitmap(image.w, image.h); if ((!page[0]) || (!page[1]) || (!vimage)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Not enough video memory (need two 1024x768 pages " + "and a 320x200 image)\n"); return(1); } /* copy the picture into offscreen video memory */ blit(image, vimage, 0, 0, 0, 0, image.w, image.h); while (!done) { acquire_bitmap(page[page_num]); /* clear the screen */ clear_bitmap(page[page_num]); /* draw onto it */ for (i = 0; i < num_images; i++) { blit(vimage, page[page_num], 0, 0, (int)images[i].x, (int)images[i].y, vimage.w, vimage.h); } textprintf_ex(page[page_num], font, 0, 0, 255, -1, string.Format("Images: {0} (arrow keys to change)", num_images)); /* tell the user which functions are being done in hardware */ if ((gfx_capabilities & GFX_HW_FILL) > 0) { textout_ex(page[page_num], font, "Clear: hardware accelerated", 0, 16, 255, -1); } else { textout_ex(page[page_num], font, "Clear: software (urgh, this " + "is not good!)", 0, 16, 255, -1); } if ((gfx_capabilities & GFX_HW_VRAM_BLIT) > 0) { textout_ex(page[page_num], font, "Blit: hardware accelerated", 0, 32, 255, -1); } else { textout_ex(page[page_num], font, "Blit: software (urgh, this program " + "will run too sloooooowly without hardware acceleration!)", 0, 32, 255, -1); } release_bitmap(page[page_num]); /* page flip */ show_video_bitmap(page[page_num]); page_num = 1 - page_num; /* deal with keyboard input */ while (keypressed()) { switch (readkey() >> 8) { case KEY_UP: case KEY_RIGHT: if (num_images < MAX_IMAGES) { num_images++; } break; case KEY_DOWN: case KEY_LEFT: if (num_images > 0) { num_images--; } break; case KEY_ESC: done = true; break; } } /* bounce the images around the screen */ for (i = 0; i < num_images; i++) { update_image(ref images[i]); } } destroy_bitmap(image); destroy_bitmap(vimage); destroy_bitmap(page[0]); destroy_bitmap(page[1]); return(0); } }
static int Main(string[] argv) { PALETTE pal = new PALETTE(); int i; if (allegro_init() != 0) { return(1); } install_keyboard(); install_timer(); if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to set any graphic mode\n{0}\n", allegro_error)); return(1); } } for (i = 0; i < 16; i++) { pal[i].r = pal[i].g = pal[i].b = 0; } /* greyscale */ pal[16].r = pal[16].g = pal[16].b = 63; pal[17].r = pal[17].g = pal[17].b = 48; pal[18].r = pal[18].g = pal[18].b = 32; pal[19].r = pal[19].g = pal[19].b = 16; pal[20].r = pal[20].g = pal[20].b = 8; /* red range */ for (i = 0; i < 16; i++) { pal[i + 32].r = (byte)(31 + i * 2); pal[i + 32].g = 15; pal[i + 32].b = 7; } /* a nice fire orange */ for (i = 64; i < 68; i++) { pal[i].r = 63; pal[i].g = (byte)(17 + (i - 64) * 3); pal[i].b = 0; } set_palette(pal); buffer = create_bitmap(SCREEN_W, SCREEN_H); clear_bitmap(buffer); set_projection_viewport(0, 0, SCREEN_W, SCREEN_H); init_stars(); draw_stars(); init_ship(); draw_ship(); int a = 0; for (; ;) { erase_stars(); erase_ship(); move_stars(); draw_stars(); textprintf_centre_ex(buffer, font, SCREEN_W / 2, SCREEN_H - 10, palette_color[17], 0, string.Format(" direction: [{0:f6}] [{0:f6}] [{0:f6}] ", fixtof(direction.x), fixtof(direction.y), fixtof(direction.z))); textprintf_centre_ex(buffer, font, SCREEN_W / 2, SCREEN_H - 20, palette_color[17], 0, string.Format(" delta: [{0:f6}] [{0:f6}] [{0:f6}] ", fixtof(delta.x), fixtof(delta.y), fixtof(delta.z))); textprintf_centre_ex(buffer, font, SCREEN_W / 2, SCREEN_H - 30, palette_color[17], 0, string.Format(" velocity: {0} ", ship.velocity)); textout_centre_ex(buffer, font, "Press ESC to exit", SCREEN_W / 2, 16, palette_color[18], 0); textout_centre_ex(buffer, font, "Press CTRL to fire engine", SCREEN_W / 2, 32, palette_color[18], 0); draw_ship(); vsync(); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); poll_keyboard(); /* exit program */ if (key[KEY_ESC]) { break; } /* rotates */ if (key[KEY_UP]) { ship.rx -= itofix(5); } else if (key[KEY_DOWN]) { ship.rx += itofix(5); } if (key[KEY_LEFT]) { ship.ry -= itofix(5); } else if (key[KEY_RIGHT]) { ship.ry += itofix(5); } if (key[KEY_PGUP]) { ship.rz -= itofix(5); } else if (key[KEY_PGDN]) { ship.rz += itofix(5); } /* thrust */ if ((key[KEY_LCONTROL]) || (key[KEY_RCONTROL])) { ship.faces[ENGINE].colour = ENGINE_ON; ship.faces[ENGINE].range = 3; if (ship.velocity < SPEED_LIMIT) { ship.velocity += 2; } } else { ship.faces[ENGINE].colour = ENGINE_OFF; ship.faces[ENGINE].range = 15; if (ship.velocity > 0) { ship.velocity -= 2; } } ship.rx &= itofix(255); ship.ry &= itofix(255); ship.rz &= itofix(255); delta.x = fixmul(direction.x, itofix(ship.velocity)); delta.y = fixmul(direction.y, itofix(ship.velocity)); delta.z = fixmul(direction.z, itofix(ship.velocity)); } destroy_bitmap(buffer); return(0); }
static int Main() { PALETTE palette = new PALETTE(); RGB temp; int c; if (allegro_init() != 0) { return(1); } install_keyboard(); if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { allegro_message("Error setting graphics mode\n" + allegro_error); return(1); } } /* first set the palette to black to hide what we are doing */ set_palette(black_palette); /* draw some circles onto the screen */ acquire_screen(); for (c = 255; c > 0; c--) { circlefill(screen, SCREEN_W / 2, SCREEN_H / 2, c, c); } release_screen(); install_mouse(); show_mouse(screen); /* fill our palette with a gradually altering sequence of colors */ for (c = 0; c < 64; c++) { palette[c].r = (byte)c; palette[c].g = 0; palette[c].b = 0; } for (c = 64; c < 128; c++) { palette[c].r = (byte)(127 - c); palette[c].g = (byte)(c - 64); palette[c].b = 0; } for (c = 128; c < 192; c++) { palette[c].r = 0; palette[c].g = (byte)(191 - c); palette[c].b = (byte)(c - 128); } for (c = 192; c < 256; c++) { palette[c].r = 0; palette[c].g = 0; palette[c].b = (byte)(255 - c); } /* animate the image by rotating the palette */ while (!keypressed()) { temp = palette[255]; for (c = 255; c > 0; c--) { palette[c] = palette[c - 1]; } palette[0] = temp; set_palette(palette); } return(0); }
static int Main() { int w, h, bpp; int windowed; int count = -1; string[] data; string title; string filename; int r, g, b; BITMAP background; int display; //RGB[] pal = new RGB[256]; PALETTE pal = new PALETTE(); int x, y; /* you should always do this at the start of Allegro programs */ if (allegro_init() != 0) { return(1); } /* set up the keyboard handler */ install_keyboard(); /* save the current ini file, then set the program specific one */ push_config_state(); set_config_file("exconfig.ini"); /* the gfx mode is stored like this: * 640 480 16 * the get_config_argv() function returns a pointer to a char * array, and stores the size of the char array in an int */ data = get_config_argv("graphics", "mode", ref count); if (count != 3) { /* We expect only 3 parameters */ allegro_message(string.Format("Found {0} parameters in graphics.mode instead of " + "the 3 expected.\n", count)); w = 320; h = 200; bpp = 8; } else { //w = atoi(data[0]); w = int.Parse(data[0]); //h = atoi(data[1]); h = int.Parse(data[1]); //bpp = atoi(data[2]); bpp = int.Parse(data[2]); } /* Should we use a windowed mode? * In the config file this is stored as either FALSE or TRUE. * So we need to read a string and see what it contains. * If the entry is not found, we use "FALSE" by default */ //if (ustricmp(get_config_string("graphics", "windowed", "FALSE"), "FALSE") == 0) if (get_config_string("graphics", "windowed", "FALSE").ToUpper() == "FALSE") { windowed = GFX_AUTODETECT_FULLSCREEN; } else { windowed = GFX_AUTODETECT_WINDOWED; } /* the title string * The string returned is stored inside of the config system * and would be lost if we call pop_config_state(), so we create * a copy of it. */ //title = ustrdup(get_config_string("content", "headline", "<no headline>")); title = get_config_string("content", "headline", "<no headline>"); /* the title color * once again this is stored as three ints in one line */ data = get_config_argv("content", "headercolor", ref count); if (count != 3) { /* We expect only 3 parameters */ allegro_message(string.Format("Found {0} parameters in content.headercolor " + "instead of the 3 expected.\n", count)); r = g = b = 255; } else { //r = atoi(data[0]); r = int.Parse(data[0]); //g = atoi(data[1]); g = int.Parse(data[1]); //b = atoi(data[2]); b = int.Parse(data[2]); } /* The image file to read * The string returned is stored inside of the config system * and would be lost if we call pop_config_state(), so we create * a copy of it. */ //filename = ustrdup(get_config_string("content", "image", "mysha.pcx")); filename = get_config_string("content", "image", "mysha.pcx"); /* and it's tiling mode */ display = get_config_int("content", "display", 0); if (display < 0 || display > 2) { allegro_message("content.display must be within 0..2\n"); display = 0; } /* restore the old config file */ pop_config_state(); /* set the graphics mode */ set_color_depth(bpp); if (set_gfx_mode(windowed, w, h, 0, 0) != 0) { allegro_message(string.Format("Unable to set mode {0}x{1} with {2}bpp\n", w, h, bpp)); //free(filename); //free(title); //exit(-1); return(-1); } /* Clear the screen */ clear_bitmap(screen); /* load the image */ background = load_bitmap(filename, pal); if (background != NULL) { set_palette(pal); switch (display) { case 0: /* stretch */ stretch_blit(background, screen, 0, 0, background.w, background.h, 0, 0, SCREEN_W, SCREEN_H); break; case 1: /* center */ blit(background, screen, 0, 0, (SCREEN_W - background.w) / 2, (SCREEN_H - background.h) / 2, background.w, background.h); break; case 2: /* tile */ for (y = 0; y < SCREEN_H; y += background.h) { for (x = 0; x < SCREEN_W; x += background.w) { blit(background, screen, 0, 0, x, y, background.w, background.h); } } break; } } else { textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H / 2, makecol(r, g, b), -1, string.Format("{0} not found", filename)); } textout_centre_ex(screen, font, title, SCREEN_W / 2, 20, makecol(r, g, b), -1); readkey(); //free(filename); //free(title); return(0); }
static int Main(string[] argv) { byte[] buf = new byte[256]; PALETTE pal = new PALETTE(); 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 (argv.Length > 0) { if ((argv[0][0] == '-') || (argv[0][0] == '/')) { argv[0] = argv[0].Substring(1); } bpp = int.Parse(argv[0]); if ((bpp != 15) && (bpp != 16) && (bpp != 24) && (bpp != 32)) { allegro_message(string.Format("Invalid color depth '{0}'\n", argv[0])); 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 */ for (a = 0; color_depths[a] > 0; 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(string.Format("Error setting {0} bit graphics mode\n{1}\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, "./", "allegro.pcx", 256); image1 = load_bitmap(Encoding.ASCII.GetString(buf), pal); if (!image1) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error reading {0}!\n", buf)); return(1); } /* load the second picture */ replace_filename(buf, "./", "mysha.pcx", 256); image2 = load_bitmap(Encoding.ASCII.GetString(buf), pal); if (!image2) { destroy_bitmap(image1); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error reading {0}!\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, string.Format("{0} 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, string.Format("light: {0} ", 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, string.Format("alpha: {0} ", 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); }
static int Main() { //IntPtr _colors = new Marshal.AllocCoTaskMem(6 * sizeof(Int32)); _colors[0].WriteInt(0, 255); _colors[1].WriteInt(0, 255); _colors[2].WriteInt(0, 255); _colors[3].WriteInt(0, 0); _colors[4].WriteInt(0, 0); _colors[5].WriteInt(0, 255); the_dlg[0] = new DIALOG(d_my_slider_proc, 32, 16, 256, 16, 0, 255, 0, 0, 255, 0, NULL, Marshal.GetFunctionPointerForDelegate(d_update_color_value), _colors[S_R]); the_dlg[1] = new DIALOG(d_my_slider_proc, 32, 64, 256, 16, 0, 255, 0, 0, 255, 0, NULL, Marshal.GetFunctionPointerForDelegate(d_update_color_value), _colors[S_G]); the_dlg[2] = new DIALOG(d_my_slider_proc, 32, 112, 256, 16, 0, 255, 0, 0, 255, 0, NULL, Marshal.GetFunctionPointerForDelegate(d_update_color_value), _colors[S_B]); the_dlg[3] = new DIALOG(d_my_slider_proc, 352, 336, 256, 16, 0, 255, 0, 0, 255, 0, NULL, Marshal.GetFunctionPointerForDelegate(d_update_color_value), _colors[S_H]); the_dlg[4] = new DIALOG(d_my_slider_proc, 352, 384, 256, 16, 0, 255, 0, 0, 255, 0, NULL, Marshal.GetFunctionPointerForDelegate(d_update_color_value), _colors[S_S]); the_dlg[5] = new DIALOG(d_my_slider_proc, 352, 432, 256, 16, 0, 255, 0, 0, 255, 0, NULL, Marshal.GetFunctionPointerForDelegate(d_update_color_value), _colors[S_V]); the_dlg[6] = new DIALOG("d_text_proc", 308, 22, 0, 0, 0, 255, 0, 0, 0, 0, Marshal.StringToCoTaskMemAnsi("R"), NULL, NULL); the_dlg[7] = new DIALOG("d_text_proc", 308, 70, 0, 0, 0, 255, 0, 0, 0, 0, Marshal.StringToCoTaskMemAnsi("G"), NULL, NULL); the_dlg[8] = new DIALOG("d_text_proc", 308, 118, 0, 0, 0, 255, 0, 0, 0, 0, Marshal.StringToCoTaskMemAnsi("B"), NULL, NULL); the_dlg[9] = new DIALOG("d_text_proc", 326, 342, 0, 0, 0, 255, 0, 0, 0, 0, Marshal.StringToCoTaskMemAnsi("H"), NULL, NULL); the_dlg[10] = new DIALOG("d_text_proc", 326, 390, 0, 0, 0, 255, 0, 0, 0, 0, Marshal.StringToCoTaskMemAnsi("S"), NULL, NULL); the_dlg[11] = new DIALOG("d_text_proc", 326, 438, 0, 0, 0, 255, 0, 0, 0, 0, Marshal.StringToCoTaskMemAnsi("V"), NULL, NULL); the_dlg[12] = new DIALOG("d_bitmap_proc", 32, 32, 256, 16, 0, 255, 0, 0, 0, 0, NULL, NULL, NULL); the_dlg[13] = new DIALOG("d_bitmap_proc", 32, 80, 256, 16, 0, 255, 0, 0, 0, 0, NULL, NULL, NULL); the_dlg[14] = new DIALOG("d_bitmap_proc", 32, 128, 256, 16, 0, 255, 0, 0, 0, 0, NULL, NULL, NULL); the_dlg[15] = new DIALOG("d_bitmap_proc", 352, 352, 256, 16, 0, 255, 0, 0, 0, 0, NULL, NULL, NULL); the_dlg[16] = new DIALOG("d_bitmap_proc", 352, 400, 256, 16, 0, 255, 0, 0, 0, 0, NULL, NULL, NULL); the_dlg[17] = new DIALOG("d_bitmap_proc", 352, 448, 256, 16, 0, 255, 0, 0, 0, 0, NULL, NULL, NULL); the_dlg[18] = new DIALOG("d_box_proc", 170, 170, 300, 140, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL); the_dlg[19] = new DIALOG(NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL); int i; if (allegro_init() != 0) { return(1); } install_keyboard(); install_mouse(); install_timer(); /* Set the deepest color depth we can set */ set_color_depth(32); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { set_color_depth(24); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { set_color_depth(16); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { set_color_depth(15); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { set_color_depth(8); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { allegro_message(string.Format("Error setting a graphics mode\n{0}\n", allegro_error)); return(1); } } } } } /* In the case we're using an 8-bit color screen, we must set up the palette */ if (get_color_depth() == 8) { PALETTE pal332 = new PALETTE(); generate_332_palette(pal332); /* Set the palette to the best approximation of a truecolor palette * we can get with 8-bit color */ set_palette(pal332); /* In 8-bit color mode, if there's an RGB table, the sliders * will move a lot more smoothly and the updating will be * a lot quicker. But if there's no RGB table, this has the * advantage that the color conversion routines will take into * account any changes in the background color. Instead of * changing background color, we could also rely on the colored * rectangle like in the other color modes, but using the 3-3-2 * palette, this doesn't display the color as accurately as * changing the background color. */ #if ZERO /* Create an RGB table to speedup makecol8() */ create_rgb_table(&rgb_table, pal332, NULL); rgb_map = &rgb_table; #endif } clear_to_color(screen, makecol(255, 255, 255)); /* color the dialog controls appropriately */ /* R -> Red */ the_dlg[S_R].fg = the_dlg[DIALOG_NUM_SLIDERS + S_R].fg = makecol(255, 0, 0); /* G -> Green */ the_dlg[S_G].fg = the_dlg[DIALOG_NUM_SLIDERS + S_G].fg = makecol(0, 255, 0); /* B -> Blue */ the_dlg[S_B].fg = the_dlg[DIALOG_NUM_SLIDERS + S_B].fg = makecol(0, 0, 255); /* H -> Grey */ the_dlg[S_H].fg = the_dlg[DIALOG_NUM_SLIDERS + S_H].fg = makecol(192, 192, 192); /* S -> Dark Grey */ the_dlg[S_S].fg = the_dlg[DIALOG_NUM_SLIDERS + S_S].fg = makecol(128, 128, 128); /* V -> Black */ the_dlg[S_V].fg = the_dlg[DIALOG_NUM_SLIDERS + S_V].fg = makecol(0, 0, 0); /* Create the bitmaps for the color-bars */ for (i = 0; i < DIALOG_NUM_SLIDERS; i++) { if (!(color_bar_bitmap[i] = create_bitmap_ex(32, 256, 16))) { allegro_message("Error creating a color-bar bitmap\n"); return(1); } the_dlg[DIALOG_FIRST_COLOR_BAR + i].dp = color_bar_bitmap[i]; } for (i = 0; i < DIALOG_NUM_SLIDERS * 3; i++) { the_dlg[i].bg = makecol(255, 255, 255); } the_dlg[DIALOG_COLOR_BOX].fg = makecol(0, 0, 0); textout_ex(screen, font, "RGB<->HSV color spaces example.", 344, 4, makecol(0, 0, 0), -1); textout_ex(screen, font, "Drag sliders to change color values.", 344, 12, makecol(0, 0, 0), -1); textout_ex(screen, font, "The color-bars beneath the sliders", 24, 384, makecol(128, 128, 128), -1); textout_ex(screen, font, "show what the resulting color will", 24, 392, makecol(128, 128, 128), -1); textout_ex(screen, font, "look like when the slider is", 24, 400, makecol(128, 128, 128), -1); textout_ex(screen, font, "dragged to that position.", 24, 408, makecol(128, 128, 128), -1); switch (get_color_depth()) { case 32: textout_ex(screen, font, "Running in truecolor (32-bit 888)", 352, 24, makecol(128, 128, 128), -1); textout_ex(screen, font, "16777216 colors", 352, 32, makecol(128, 128, 128), -1); break; case 24: textout_ex(screen, font, "Running in truecolor (24-bit 888)", 352, 24, makecol(128, 128, 128), -1); textout_ex(screen, font, "16777216 colors", 352, 32, makecol(128, 128, 128), -1); break; case 16: textout_ex(screen, font, "Running in hicolor (16-bit 565)", 352, 24, makecol(128, 128, 128), -1); textout_ex(screen, font, "65536 colors", 352, 32, makecol(128, 128, 128), -1); break; case 15: textout_ex(screen, font, "Running in hicolor (15-bit 555)", 352, 24, makecol(128, 128, 128), -1); textout_ex(screen, font, "32768 colors", 352, 32, makecol(128, 128, 128), -1); break; case 8: textout_ex(screen, font, "Running in paletted mode (8-bit 332)", 352, 24, makecol(128, 128, 128), -1); textout_ex(screen, font, "256 colors", 352, 32, makecol(128, 128, 128), -1); break; default: textout_ex(screen, font, "Unknown color depth", 400, 16, 0, -1); break; } update_color_rectangle(colors[S_R], colors[S_G], colors[S_B]); update_color_bars(colors[S_R], colors[S_G], colors[S_B], colors[S_H] * 360.0f / 255.0f, colors[S_S] / 255.0f, colors[S_V] / 255.0f); do_dialog(the_dlg, -1); for (i = 0; i < DIALOG_NUM_SLIDERS; i++) { destroy_bitmap(color_bar_bitmap[i]); } return(0); }
static int Main() { BITMAP buffer; PALETTE pal = new PALETTE(); MATRIX_f matrix = new MATRIX_f(), matrix1 = new MATRIX_f(), matrix2 = new MATRIX_f(), matrix3 = new MATRIX_f(); int rx = 0, ry = 0, tz = 40; int rot = 0, inc = 1; int i, j, k; int frame = 0; float fps = 0.0f; if (allegro_init() != 0) { return(1); } install_keyboard(); install_mouse(); install_timer(); LOCK_VARIABLE(t); LOCK_FUNCTION(t_tick); install_int(t_tick, 10); /* set up graphics mode */ if (init_gfx(pal) > 0) { return(1); } set_palette(pal); /* initialize buffers and viewport */ buffer = create_bitmap(SCREEN_W, SCREEN_H); create_scene(24 * MAX_CUBES * MAX_CUBES * MAX_CUBES, 6 * MAX_CUBES * MAX_CUBES * MAX_CUBES); set_projection_viewport(0, 0, SCREEN_W, SCREEN_H); /* initialize pointers */ for (j = 0; j < 4; j++) { //pv[j] = &v[j]; pv[j] = v[j]; } for (j = 0; j < 12; j++) { //pvtmp[j] = &vtmp[j]; //pvout[j] = &vout[j]; pvtmp[j] = vtmp[j]; pvout[j] = vout[j]; } while (!key[KEY_ESC]) { clear_bitmap(buffer); clear_scene(buffer); /* matrix2: rotates cube */ get_rotation_matrix_f(ref matrix2, rx, ry, 0); /* matrix3: turns head right/left */ get_rotation_matrix_f(ref matrix3, 0, rot, 0); for (k = MAX_CUBES - 1; k >= 0; k--) { for (j = 0; j < MAX_CUBES; j++) { for (i = 0; i < MAX_CUBES; i++) { /* matrix1: locates cubes */ get_translation_matrix_f(ref matrix1, j * 40 - MAX_CUBES * 20 + 20, i * 40 - MAX_CUBES * 20 + 20, tz + k * 40); /* matrix: rotates cube THEN locates cube THEN turns * head right/left */ matrix_mul_f(ref matrix2, ref matrix1, out matrix); matrix_mul_f(ref matrix, ref matrix3, out matrix); /* cubes are just added to the scene. * No sorting is done at this stage. */ draw_cube(ref matrix, 6); } } } /* sorts and renders polys */ render_scene(); textprintf_ex(buffer, font, 2, 2, palette_color[1], -1, string.Format("({0:f1} fps)", fps)); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); frame++; /* manage cubes movement */ tz -= 2; if (tz == 0) { tz = 40; } rx += 4; ry += 4; rot += inc; if ((rot >= 25) || (rot <= -25)) { inc = -inc; } /* computes fps */ if (t > 100) { fps = (100.0f * frame) / t; t = 0; frame = 0; } } destroy_bitmap(buffer); destroy_scene(); return(0); }
static int Main(string[] argv) { PALETTE pal = new PALETTE(); BITMAP buffer; BITMAP planet; byte[] buf = new byte[256]; if (allegro_init() != 0) { return(1); } install_keyboard(); install_mouse(); if (set_gfx_mode(GFX_AUTODETECT, 320, 240, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 240, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Unable to set any graphic mode\n{0}\n", allegro_error)); return(1); } } replace_filename(buf, "./", "planet.pcx", buf.Length); planet = load_bitmap(Encoding.ASCII.GetString(buf), pal); if (!planet) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(string.Format("Error reading {0}\n", Encoding.ASCII.GetString(buf))); return(1); } buffer = create_bitmap(SCREEN_W, SCREEN_H); clear_bitmap(buffer); set_palette(pal); create_rgb_table(rgb_table, pal, NULL); rgb_map = rgb_table; create_light_table(light_table, pal, 0, 0, 0, NULL); color_map = light_table; set_trans_blender(0, 0, 0, 128); do { poll_mouse(); draw_gouraud_sprite(buffer, planet, SCREEN_W / 2, SCREEN_H / 2, distance(SCREEN_W / 2, SCREEN_H / 2, mouse_x, mouse_y), distance(SCREEN_W / 2 + planet.w, SCREEN_H / 2, mouse_x, mouse_y), distance(SCREEN_W / 2 + planet.w, SCREEN_H / 2 + planet.h, mouse_x, mouse_y), distance(SCREEN_W / 2, SCREEN_H / 2 + planet.h, mouse_x, mouse_y)); textout_ex(buffer, font, "Gouraud Shaded Sprite Demo", 0, 0, palette_color[10], -1); show_mouse(buffer); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); show_mouse(NULL); } while (!keypressed()); destroy_bitmap(planet); destroy_bitmap(buffer); return(0); }