Exemple #1
0
void mapper_import_tiles(ALLEGRO_BITMAP * bp)
{
	int i, j;
	T3F_ANIMATION * ap = NULL;
	ALLEGRO_BITMAP * newbp = NULL;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;

	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER | ALLEGRO_STATE_TRANSFORM);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	for(i = 0; i < al_get_bitmap_height(bp) / mapper_tile_height; i++)
	{
		for(j = 0; j < al_get_bitmap_width(bp) / mapper_tile_width; j++)
		{
			ap = t3f_create_animation();
			if(ap)
			{
				newbp = al_create_bitmap(mapper_tile_width, mapper_tile_height);
				if(newbp)
				{
					al_set_target_bitmap(newbp);
					al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
					al_draw_bitmap(bp, -j * mapper_tile_width, -i * mapper_tile_height, 0);
					t3f_animation_add_bitmap(ap, newbp);
					t3f_animation_add_frame(ap, 0, 0, 0, 0, mapper_tile_width, mapper_tile_height, 0, 1, 0);
					t3f_add_tile(mapper_tileset, ap);
				}
			}
		}
	}
	al_restore_state(&old_state);
}
Exemple #2
0
/* Function: al_convert_mask_to_alpha
 */
void al_convert_mask_to_alpha(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR mask_color)
{
   ALLEGRO_LOCKED_REGION *lr;
   int x, y;
   ALLEGRO_COLOR pixel;
   ALLEGRO_COLOR alpha_pixel;
   ALLEGRO_STATE state;

   if (!(lr = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ANY, 0))) {
      ALLEGRO_ERROR("Couldn't lock bitmap.");
      return;
   }

   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(bitmap);

   alpha_pixel = al_map_rgba(0, 0, 0, 0);

   for (y = 0; y < bitmap->h; y++) {
      for (x = 0; x < bitmap->w; x++) {
         pixel = al_get_pixel(bitmap, x, y);
         if (memcmp(&pixel, &mask_color, sizeof(ALLEGRO_COLOR)) == 0) {
            al_put_pixel(x, y, alpha_pixel);
         }
      }
   }

   al_unlock_bitmap(bitmap);

   al_restore_state(&state);
}
Exemple #3
0
static void dot_create_touch_start_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}
	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM | ALLEGRO_STATE_BLENDER);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
	al_set_clipping_rectangle(0, 0, 512, 512);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 1.0));
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_INVERSE_ALPHA);
	al_draw_filled_rectangle(DOT_GAME_TOUCH_START_X * sx, DOT_GAME_TOUCH_START_Y, DOT_GAME_TOUCH_END_X * sx, DOT_GAME_TOUCH_END_Y, al_map_rgba_f(1.0, 1.0, 1.0, 1.0));
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
}
static void t3f_render_static_tilemap(T3F_TILEMAP * tmp, T3F_TILESET * tsp, int layer, int tick, float ox, float oy, float oz, ALLEGRO_COLOR color)
{
	ALLEGRO_STATE old_blender;
	int i, j;
	bool held;

	held = al_is_bitmap_drawing_held();
	al_store_state(&old_blender, ALLEGRO_STATE_BLENDER);
	if(tmp->layer[layer]->flags & T3F_TILEMAP_LAYER_SOLID)
	{
		if(held)
		{
			al_hold_bitmap_drawing(false);
		}
		al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
	}
	al_hold_bitmap_drawing(true);
	for(i = 0; i < (t3f_virtual_display_height / tsp->height) + 1; i++)
	{
		for(j = 0; j < (t3f_virtual_display_width / tsp->width) + 1; j++)
		{
			t3f_draw_scaled_animation(tsp->tile[t3f_get_tile(tsp, tmp->layer[layer]->data[i][j], tick)]->ap, color, tick, (float)(j * tsp->width) * tmp->layer[layer]->scale, (float)(i * tsp->height) * tmp->layer[layer]->scale, 0, tmp->layer[layer]->scale, 0);
		}
	}
	if(tmp->layer[layer]->flags & T3F_TILEMAP_LAYER_SOLID)
	{
		al_hold_bitmap_drawing(false);
	}
	al_hold_bitmap_drawing(held);
	al_restore_state(&old_blender);
}
Exemple #5
0
static void dot_create_touch_dots_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	int i;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}
	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_set_clipping_rectangle(0, 0, 512, 512);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 0.0));
	al_hold_bitmap_drawing(true);
	for(i = 0; i < DOT_GAME_MAX_BALLS; i++)
	{
		if(app->game.ball[i].active)
		{
			t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_BALL_RED + app->game.ball[i].type], al_map_rgba_f(1.0, 1.0, 1.0, 1.0), (app->game.ball[i].x - app->game.ball[i].r) * sx, app->game.ball[i].y - app->game.ball[i].r, app->game.ball[i].z, (app->game.ball[i].r * 2.0) * sx, app->game.ball[i].r * 2.0, 0);
		}
	}
	al_hold_bitmap_drawing(false);
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
	t3f_set_clipping_rectangle(0.0, 0.0, 0.0, 0.0);
}
Exemple #6
0
static void dot_create_grab_spot_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float s;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}

	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM | ALLEGRO_STATE_BLENDER);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
	al_set_clipping_rectangle(0, 0, 512, 512);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 1.0));
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_INVERSE_ALPHA);
	s = DOT_GAME_GRAB_SPOT_SIZE;
	t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_COMBO], al_map_rgba_f(0.0, 0.0, 0.0, 1.0), (float)(app->game.player.ball.x - DOT_GAME_GRAB_SPOT_SIZE) * sx, app->game.player.ball.y - DOT_GAME_GRAB_SPOT_SIZE, 0.0, (s * 2.0) * sx, s * 2, 0);
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
}
Exemple #7
0
/* Converts a display bitmap to a memory bitmap preserving its contents.
 * Driver specific resources occupied by the display bitmap are freed.
 * A converted sub bitmap is invalid until its parent is converted.
 */
void _al_convert_to_memory_bitmap(ALLEGRO_BITMAP *bitmap)
{
   ALLEGRO_BITMAP *tmp;
   ALLEGRO_STATE backup;
   size_t old_size;

   /* Do nothing if it is a memory bitmap already. */
   if (bitmap->flags & ALLEGRO_MEMORY_BITMAP)
      return;

   if (bitmap->parent) {
      _al_vector_find_and_delete(&bitmap->display->bitmaps, &bitmap);

      //al_realloc(bitmap, sizeof(ALLEGRO_BITMAP));
      bitmap->display = NULL;
      bitmap->flags |= ALLEGRO_MEMORY_BITMAP;
      return;
   }

   ALLEGRO_DEBUG("converting display bitmap %p to memory bitmap\n", bitmap);

   /* Allocate a temporary bitmap which will hold the data
    * during the conversion process. */

   al_store_state(&backup, ALLEGRO_STATE_BITMAP | ALLEGRO_STATE_BLENDER);

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   al_set_new_bitmap_format(bitmap->format);
   tmp = _al_create_memory_bitmap(bitmap->w, bitmap->h);

   /* Preserve bitmap contents. */
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_set_target_bitmap(tmp);
   al_draw_bitmap(bitmap, 0, 0, 0);
   tmp->cb_excl = bitmap->cb_excl;
   tmp->cr_excl = bitmap->cr_excl;
   tmp->cl = bitmap->cl;
   tmp->ct = bitmap->ct;

   al_restore_state(&backup);

   /* Destroy the display bitmap to free driver-specific resources. */
   if (bitmap->vt)
      bitmap->vt->destroy_bitmap(bitmap);

   _al_vector_find_and_delete(&bitmap->display->bitmaps, &bitmap);

   /* Do not shrink the bitmap object. This way we can convert back to the
    * display bitmap.
    */
   /*al_realloc(bitmap, tmp->size);
     bitmap->size = tmp->size*/

   /* Put the contents back to the bitmap. */
   old_size = bitmap->size;
   memcpy(bitmap, tmp, tmp->size);
   bitmap->size = old_size;

   al_free(tmp);
}
Exemple #8
0
ALLEGRO_BITMAP_OGL* _al_ogl_create_backbuffer(ALLEGRO_DISPLAY *disp)
{
   ALLEGRO_BITMAP_OGL *ogl_backbuffer;
   ALLEGRO_BITMAP *backbuffer;
   ALLEGRO_STATE backup;
   int format;

   ALLEGRO_DEBUG("Creating backbuffer\n");

   al_store_state(&backup, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS);

   // FIXME: _al_deduce_color_format would work fine if the display paramerers
   // are filled in, for WIZ and IPOD
#ifdef ALLEGRO_GP2XWIZ
   format = ALLEGRO_PIXEL_FORMAT_RGB_565; /* Only support display format */
#elif defined ALLEGRO_IPHONE
   format = ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE;
   // TODO: This one is also supported
   //format = ALLEGRO_PIXEL_FORMAT_RGB_565;
#else
   format = _al_deduce_color_format(&disp->extra_settings);
   /* Eww. No OpenGL hardware in the world does that - let's just
    * switch to some default.
    */
   if (al_get_pixel_size(format) == 3) {
      /* Or should we use RGBA? Maybe only if not Nvidia cards? */
      format = ALLEGRO_PIXEL_FORMAT_ABGR_8888;
   }
#endif
   ALLEGRO_TRACE_CHANNEL_LEVEL("display", 1)("Deduced format %s for backbuffer.\n",
      _al_pixel_format_name(format));

   /* Now that the display backbuffer has a format, update extra_settings so
    * the user can query it back.
    */
   _al_set_color_components(format, &disp->extra_settings, ALLEGRO_REQUIRE);
   disp->backbuffer_format = format;

   ALLEGRO_DEBUG("Creating backbuffer bitmap\n");
   al_set_new_bitmap_format(format);
   /* Using ALLEGRO_NO_PRESERVE_TEXTURE prevents extra memory being allocated */
   al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP | ALLEGRO_NO_PRESERVE_TEXTURE);
   backbuffer = _al_ogl_create_bitmap(disp, disp->w, disp->h);
   al_restore_state(&backup);

   if (!backbuffer) {
      ALLEGRO_DEBUG("Backbuffer bitmap creation failed.\n");
      return NULL;
   }
   
   ALLEGRO_TRACE_CHANNEL_LEVEL("display", 1)(
      "Created backbuffer bitmap (actual format: %s)\n",
      _al_pixel_format_name(backbuffer->format));

   ogl_backbuffer = (ALLEGRO_BITMAP_OGL*)backbuffer;
   ogl_backbuffer->is_backbuffer = 1;
   backbuffer->display = disp;

   return ogl_backbuffer;
}
Exemple #9
0
void _al_win_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *bmp)
{
   ALLEGRO_BITMAP *scaled_bmp;
   HICON icon, old_small, old_big;
   ALLEGRO_DISPLAY_WIN *win_display = (ALLEGRO_DISPLAY_WIN *)display;
   ALLEGRO_STATE backup;

   al_store_state(&backup, ALLEGRO_STATE_BITMAP | ALLEGRO_STATE_BLENDER);

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ARGB_8888);
   scaled_bmp = al_create_bitmap(32, 32);
   al_set_target_bitmap(scaled_bmp);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO, al_map_rgb(255, 255, 255));
   al_draw_scaled_bitmap(bmp, 0, 0,
      al_get_bitmap_width(bmp),
      al_get_bitmap_height(bmp),
      0, 0, 32, 32, 0);

   al_restore_state(&backup);

   icon = _al_win_create_icon(win_display->window, scaled_bmp, 0, 0, false);

   old_small = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_SMALL, (LPARAM)icon);
   old_big = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_BIG, (LPARAM)icon);

   if (old_small)
      DestroyIcon(old_small);
   if (old_big)
      DestroyIcon(old_big);

   al_destroy_bitmap(scaled_bmp);
}
Exemple #10
0
ResourceBitmap *Atlas::load(const std::string &path)
{
	std::string fpath = path + ".png";
	//NBT_Debug("attempting to load %s", fpath.c_str());
	
	ALLEGRO_STATE state;
	al_store_state(&state, ALLEGRO_STATE_BITMAP);
	
	//al_set_new_bitmap_flags(ALLEGRO_NO_PREMULTIPLIED_ALPHA);
	ALLEGRO_BITMAP *bmp = al_load_bitmap(fpath.c_str());
	if(!bmp)
	{
		//NBT_Debug("failed to load %s", fpath.c_str());
		return nullptr;
	}
	
	AtlasSheet *sheet = getSheet();
	Item sheetItem;
	if(!sheet->allocItem(bmp, &sheetItem))
		return nullptr;

	al_destroy_bitmap(bmp);
	
	ResourceBitmap *res = new ResourceBitmap(path);
	sheetItem.id = res->id();
	
	idItemMap_.emplace(res->id(), sheetItem);
	
	al_restore_state(&state);
	
	return res;
}
ALLEGRO_BITMAP *create_pixel_pattern_4(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int x_distance, float slope)
{
   //TODO this function is not complete, and may not return expected results when other values than the default values are given. 
   // Further development is needed to provide this flexibility to the function, but at the default values, it returns the intended
   // pattern

   int bitmap_size_x = x_distance * 8;
   int bitmap_size_y = x_distance * 8;

   ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size_x, bitmap_size_y);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(surface);

   if (x_distance < 0) { al_restore_state(&state); return surface; }
   while (slope < 0) { slope += x_distance; }

   // clear to the back color
   al_clear_to_color(pixel2_color);

   // begin drawing the surface
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct?
   for (int y=0; y<bitmap_size_y; y+=1)
      for (int x=0; x<bitmap_size_x; x+=x_distance)
      {
         al_put_pixel(x + ((int)(y*slope))%x_distance, y, pixel1_color);
      }
   al_unlock_bitmap(surface);

   al_restore_state(&state);
   return surface;
}
ALLEGRO_BITMAP *generate_gradient_bitmap(float size, ALLEGRO_COLOR top_color, ALLEGRO_COLOR bottom_color, int padding)
{
   // set everything up for rendering
   int w = size;
   int h = size;
   ALLEGRO_BITMAP *surface = al_create_bitmap(w, h);
   ALLEGRO_STATE previous_state;
   al_store_state(&previous_state, ALLEGRO_STATE_TARGET_BITMAP);

   // start drawing on the bitmap
   al_set_target_bitmap(surface);
   al_clear_to_color(color::transparent);

   // build the gradient as a primitive
   ALLEGRO_VERTEX v[4];
   v[0] = build_vertex(0+padding, 0+padding, 0, top_color, 0, 0);
   v[1] = build_vertex(w-padding, 0+padding, 0, top_color, 0, 0);
   v[2] = build_vertex(w-padding, h-padding, 0, bottom_color, 0, 0);
   v[3] = build_vertex(0+padding, h-padding, 0, bottom_color, 0, 0);

   // draw it to the surface
   al_draw_prim(v, NULL, NULL, 0, 4, ALLEGRO_PRIM_TRIANGLE_FAN);

   // restore everything back to where it was
   al_restore_state(&previous_state);

   // return the generated image
   return surface; 
}
ALLEGRO_BITMAP *generate_triangle_bitmap(float x1, float y1, float x2, float y2, float x3, float y3, ALLEGRO_COLOR col)
{
   // find the width and height of the bitmap (this could be more comprehensive? What about -negative points?)
   float max_x = std::max(std::max(x1, x2), x2);
   float max_y = std::max(std::max(y1, y2), y3);

   // start drawing
   ALLEGRO_BITMAP *surface = al_create_bitmap(max_x, max_y);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_clear_to_color(color::transparent);
   al_set_target_bitmap(surface);

   // build our triangle
   ALLEGRO_VERTEX v[3];
   v[0] = build_vertex(x1, y1, 0, col, 0, 0);
   v[1] = build_vertex(x2, y2, 0, col, 0, 0);
   v[2] = build_vertex(x3, y3, 0, col, 0, 0);

   // draw the triangle
   al_draw_prim(v, NULL, NULL, 0, 3, ALLEGRO_PRIM_TRIANGLE_LIST);

   // restore drawing state
   al_restore_state(&state);
   return surface;
}
static void dot_create_bg_object_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	int i;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}
	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_set_clipping_rectangle(0, 0, 512, 512);
    al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 0.0));
    al_set_clipping_rectangle(0, 0, 512, DOT_GAME_PLAYFIELD_HEIGHT);
    al_hold_bitmap_drawing(true);
	for(i = 0; i < DOT_MAX_BG_OBJECTS; i++)
	{
		t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_BALL_RED], al_map_rgba_f(1.0, 1.0, 1.0, 1.0), app->bg_object[i].x * sx, app->bg_object[i].y, app->bg_object[i].z, DOT_GAME_BALL_SIZE * 2.0 * sx, DOT_GAME_BALL_SIZE * 2.0, 0);
	}
	al_hold_bitmap_drawing(false);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
}
Exemple #15
0
void Prog::draw_samples()
{
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER);
      
   /* Draw a background, in case our target bitmap will end up with
    * alpha in it.
    */
   draw_background(40, 20);
   draw_background(400, 20);
   
   /* Test standard blending. */
   al_set_target_bitmap(target);
   blending_test(false);

   /* Test memory blending. */
   al_set_target_bitmap(target_bmp);
   blending_test(true);

   /* Display results. */
   al_restore_state(&state);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
   al_draw_bitmap(target, 40, 20, 0);
   al_draw_bitmap(target_bmp, 400, 20, 0);
 
   al_restore_state(&state);
}
ALLEGRO_BITMAP *create_pixel_pattern_1(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int checker_size)
{
   int bitmap_size = 64;
   ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size, bitmap_size);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(surface);

   // clear to the back color
   al_clear_to_color(pixel2_color);

   // begin drawing the surface
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct?
   int num_rows_cols = bitmap_size / checker_size;
   for (int row=0; row<num_rows_cols; row++)
      for (int col=0; col<num_rows_cols; col++)
      {
         if ((row+col) % 2 == 1) continue; // skip if the square is even

         // draw a square of n x n size, at (x, y)
         for (int yy=0; yy<checker_size; yy++)
            for (int xx=0; xx<checker_size; xx++)
            {
               al_put_pixel(col*checker_size + xx, row*checker_size + yy, pixel1_color);
            }
      }
   al_unlock_bitmap(surface);

   al_restore_state(&state);
   return surface;
}
Exemple #17
0
ALGIF_ANIMATION *algif_load_animation_f(ALLEGRO_FILE *file) {
    ALGIF_ANIMATION *gif = algif_load_raw(file);

    if (!gif)
        return gif;

    al_init_primitives_addon();

    gif->duration = 0;
    ALLEGRO_STATE s;
    al_store_state(&s, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER);
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
    int n = gif->frames_count;
    int i;
    for (i = 0; i < n; i++) {
        ALGIF_FRAME *f = &gif->frames[i];
        f->rendered = al_create_bitmap(gif->width, gif->height);
        al_set_target_bitmap(f->rendered);
        algif_render_frame(gif, i, 0, 0);
        gif->duration += f->duration;
    }

    al_restore_state(&s);
    return gif;
}
ALLEGRO_BITMAP *generate_noise_bitmap(float w, float h, float min_intensity, float max_intensity)
{
   // set everything up
   ALLEGRO_BITMAP *surface = al_create_bitmap(w, h);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);

   // set the drawing surface
   al_set_target_bitmap(surface);

   // write the (randomly colored) pixels
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ARGB_8888, ALLEGRO_LOCK_WRITEONLY);
   for (int x=0; x<w; x++)
   {
      for (int y=0; y<h; y++)
      {
         float val = random_float(min_intensity, max_intensity);
         al_put_pixel(x, y, al_map_rgba_f(val, val, val, 1.0));
      }
   }
   al_unlock_bitmap(surface);

   // return everything back to the way it was
   al_restore_state(&state);

   // return the generated image
   return surface;
}
Exemple #19
0
ALLEGRO_FONT *_al_load_bitmap_font(const char *fname, int size, int flags)
{
   ALLEGRO_BITMAP *import_bmp;
   ALLEGRO_FONT *f;
   ALLEGRO_STATE backup;
   int range[2];
   ASSERT(fname);

   (void)size;
   (void)flags;

   al_store_state(&backup, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS);
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA);
   import_bmp = al_load_bitmap(fname);
   al_restore_state(&backup);

   if (!import_bmp) 
     return NULL;

   /* We assume a single unicode range, starting at the space
    * character.
    */
   range[0] = 32;
   range[1] = 32 + bitmap_font_count(import_bmp) - 1;

   f = al_grab_font_from_bitmap(import_bmp, 1, range);

   al_destroy_bitmap(import_bmp);

   return f;
}
Exemple #20
0
static ALLEGRO_BITMAP *example_bitmap(int w, int h)
{
   int i, j;
   float mx = w * 0.5;
   float my = h * 0.5;
   ALLEGRO_STATE state;
   ALLEGRO_BITMAP *pattern = al_create_bitmap(w, h);
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(pattern);
   al_lock_bitmap(pattern, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
   for (i = 0; i < w; i++) {
      for (j = 0; j < h; j++) {
         float a = atan2(i - mx, j - my);
         float d = sqrt(pow(i - mx, 2) + pow(j - my, 2));
         float sat = pow(1.0 - 1 / (1 + d * 0.1), 5);
         float hue = 3 * a * 180 / ALLEGRO_PI;
         hue = (hue / 360 - floorf(hue / 360)) * 360;
         al_put_pixel(i, j, al_color_hsv(hue, sat, 1));
      }
   }
   al_put_pixel(0, 0, al_map_rgb(0, 0, 0));
   al_unlock_bitmap(pattern);
   al_restore_state(&state);
   return pattern;
}
ALLEGRO_BITMAP *create_pixel_pattern_3(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int x_distance, int y_distance)
{
   int bitmap_size_x = x_distance * 8;
   int bitmap_size_y = y_distance * 8;
   ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size_x, bitmap_size_y);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(surface);

   // clear to the back color
   al_clear_to_color(pixel2_color);

   // begin drawing the surface
   int slope = (int)(x_distance * 1.5);
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct?
   for (int y=0; y<bitmap_size_y; y+=y_distance)
      for (int x=0; x<bitmap_size_x; x+=x_distance)
      {
         al_put_pixel(x + (y*slope)%x_distance, y, pixel1_color);
      }
   al_unlock_bitmap(surface);

   al_restore_state(&state);
   return surface;
}
bool Player::load(void)
{
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER);

   bitmap = al_load_bitmap(getResource("gfx/ship.tga"));
   if (!bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/ship.tga"));
      return false;
   }

   trans_bitmap = al_create_bitmap(al_get_bitmap_width(bitmap),
      al_get_bitmap_height(bitmap));
   if (!trans_bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/ship_trans.tga"));
      al_destroy_bitmap(bitmap);
      return false;
   }

   /* Make a translucent copy of the ship */
   al_set_target_bitmap(trans_bitmap);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_draw_tinted_bitmap(bitmap, al_map_rgba(255, 255, 255, 160),
      0, 0, 0);
   al_restore_state(&state);

   trail_bitmap = al_load_bitmap(getResource("gfx/trail.tga"));
   if (!trail_bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/trail.tga"));
      al_destroy_bitmap(bitmap);
      al_destroy_bitmap(trans_bitmap);
      return false;
   }

   icon = al_load_bitmap(getResource("gfx/ship_icon.tga"));
   if (!icon) {
      debug_message("Error loading %s\n", getResource("gfx/icon.tga"));
      al_destroy_bitmap(bitmap);
      al_destroy_bitmap(trans_bitmap);
      al_destroy_bitmap(trail_bitmap);
      return false;
   }

   highscoreBitmap = al_create_bitmap(300, 200);
   al_set_target_bitmap(highscoreBitmap);
   al_clear_to_color(al_map_rgba(0, 0, 0, 0));

   al_restore_state(&state);

   draw_radius = al_get_bitmap_width(bitmap)/2;
   radius = draw_radius / 2;

   newGame();
   reset();

   return true;
}
  void draw(vec3d camera_position, vec3d light_position)
  {
		ALLEGRO_STATE previous_state;
		ALLEGRO_TRANSFORM transform;

		
		if (shader && shader_applies_transform)
		{
			// construct our entity's transform
			place.build_transform(&transform);

			// Now apply it to the shader
			shader->use();
			Shader::set_vec3("camera_position", camera_position);
			Shader::set_vec3("light_position", light_position);
			Shader::set_mat4("position_transform", &transform);

			Shader::set_bool("reflecting", cube_map_reflecting);

			Shader::set_sampler("diffuse_texture", diffuse_texture, 2);
			Shader::set_sampler("specular_texture", specular_texture, 3);
			Shader::set_sampler("normal_texture", normal_texture, 4);
			Shader::set_sampler_cube("cube_map_A", cube_map_A, 5);
			Shader::set_sampler_cube("cube_map_B", cube_map_B, 6);
		}
		else
		{
			// when not using the shader, we'll need to 
			// apply the transform directly here
			al_store_state(&previous_state, ALLEGRO_STATE_TRANSFORM);
			al_identity_transform(&transform);
			al_use_transform(&transform);
			place.start_transform();

			// also, we set the texture on this model directly
			if (diffuse_texture) model->set_texture(diffuse_texture);
		}



		// actually draw our model here
		if (model) model->draw();



		if (shader && shader_applies_transform)
		{
			Shader::stop();
		}
		else
		{
			place.restore_transform();
			al_restore_state(&previous_state);
		}
  }
Exemple #24
0
/* emulate textout_centre() */
void textout_centre(const ALLEGRO_FONT *font, const char *s, int x, int y, ALLEGRO_COLOR c)
{
   ALLEGRO_STATE state;

   al_store_state(&state, ALLEGRO_STATE_BLENDER);

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, c);
   al_draw_text(font, x, y, ALLEGRO_ALIGN_CENTRE, s);

   al_restore_state(&state);
}
ALLEGRO_BITMAP *generate_interpolator_graph_bitmap(float(* interpolator_func)(float), float size, ALLEGRO_COLOR col, float thickness, float padding)
{
   // setup the drawing surface
   ALLEGRO_BITMAP *surface = al_create_bitmap(size, size);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(surface);
   al_clear_to_color(color::transparent);


   //
   //	 start drawing the graph
   //


   float line_width = thickness;

   float w = size;
   float h = size;

   float x = padding;
   float y = padding;
   w += padding*2;
   h += padding*2;

   //y *= -1;
   h *= -1;

   int num_points = 50;

   vec2d previous_point(0, 1);
   for (int i=0; i<=(num_points-1); i++)
   {
      float point_x = (float)i/(num_points-1);
      float point_y = interpolator_func(point_x);

      point_x *= (size-padding*2);
      point_y *= -(size-padding*2);

      point_x += x;
      point_y += y+(size-padding*2);

      al_draw_filled_circle(point_x, point_y, line_width*1.3, col);
   }



   // restore things to the way they were
   al_restore_state(&state);

   // return the created image
   return surface;
}
void _al_win_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *bmp)
{
   ALLEGRO_BITMAP *sm_bmp, *big_bmp;
   HICON sm_icon, big_icon, old_small, old_big;
   ALLEGRO_DISPLAY_WIN *win_display = (ALLEGRO_DISPLAY_WIN *)display;
   ALLEGRO_STATE backup;
   int sm_w, sm_h, big_w, big_h;

   al_store_state(&backup, ALLEGRO_STATE_BITMAP | ALLEGRO_STATE_BLENDER);

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ARGB_8888);

   sm_w = GetSystemMetrics(SM_CXSMICON);
   sm_h = GetSystemMetrics(SM_CYSMICON);
   big_w = GetSystemMetrics(SM_CXICON);
   big_h = GetSystemMetrics(SM_CYICON);

   sm_bmp = al_create_bitmap(sm_w, sm_h);
   al_set_target_bitmap(sm_bmp);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_draw_scaled_bitmap(bmp, 0, 0,
      al_get_bitmap_width(bmp),
      al_get_bitmap_height(bmp),
      0, 0, sm_w, sm_h, 0);

   big_bmp = al_create_bitmap(big_w, big_h);
   al_set_target_bitmap(big_bmp);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_draw_scaled_bitmap(bmp, 0, 0,
      al_get_bitmap_width(bmp),
      al_get_bitmap_height(bmp),
      0, 0, big_w, big_h, 0);

   al_restore_state(&backup);

   sm_icon = _al_win_create_icon(win_display->window, sm_bmp, 0, 0, false, false);
   big_icon = _al_win_create_icon(win_display->window, big_bmp, 0, 0, false, false);

   old_small = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_SMALL, (LPARAM)sm_icon);
   old_big = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_BIG, (LPARAM)big_icon);

   if (old_small)
      DestroyIcon(old_small);
   if (old_big)
      DestroyIcon(old_big);

   al_destroy_bitmap(sm_bmp);
   al_destroy_bitmap(big_bmp);
}
ALLEGRO_BITMAP * t3f_resize_bitmap(ALLEGRO_BITMAP * bp, int w, int h)
{
	ALLEGRO_BITMAP * rbp = NULL;
	int start_w = al_get_bitmap_width(bp);
	int start_h = al_get_bitmap_height(bp);
	int x, y;
	float pixx, pixx_f, pixy, pixy_f;
	ALLEGRO_COLOR a, b, c, d, ab, cd, result;
	ALLEGRO_STATE old_state;

	/* don't resize if size is already correct */
	if(w == start_w && h == start_h)
	{
		return al_clone_bitmap(bp);
	}

	/* scale with software filtering */
	rbp = al_create_bitmap(w, h);
	if(!rbp)
	{
		printf("failed to create return bitmap\n");
		return NULL;
	}
	al_lock_bitmap(rbp, ALLEGRO_LOCK_READWRITE, ALLEGRO_PIXEL_FORMAT_ANY);
	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP);
	al_set_target_bitmap(rbp);
	for(y = 0; y < h; y++)
	{
		pixy = ((float)y / h) * ((float)start_h - 1);
		pixy_f = floor(pixy);
		for(x = 0; x < w; x++)
		{
			pixx = ((float)x / w) * ((float)start_w - 1);
			pixx_f = floor(pixx);

			a = al_get_pixel(bp, pixx_f, pixy_f);
			b = al_get_pixel(bp, pixx_f + 1, pixy_f);
			c = al_get_pixel(bp, pixx_f, pixy_f + 1);
			d = al_get_pixel(bp, pixx_f + 1, pixy_f + 1);

			ab = interpolate(a, b, pixx - pixx_f);
			cd = interpolate(c, d, pixx - pixx_f);
			result = interpolate(ab, cd, pixy - pixy_f);

			al_put_pixel(x, y, result);
		}
	}
	al_unlock_bitmap(rbp);
	al_restore_state(&old_state);
	return rbp;
}
Exemple #28
0
// FIXME: Add a special case for when a single glyph rendering won't fit
// into 256x256 pixels.
static ALLEGRO_BITMAP *push_new_page(ALLEGRO_TTF_FONT_DATA *data)
{
    ALLEGRO_BITMAP **back;
    ALLEGRO_BITMAP *page;
    ALLEGRO_STATE state;

    unlock_current_page(data);

    /* The bitmap will be destroyed when the parent font is destroyed so
     * it is not safe to register a destructor for it.
     */
    _al_push_destructor_owner();
    al_store_state(&state, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS);
    al_set_new_bitmap_format(data->bitmap_format);
    al_set_new_bitmap_flags(data->bitmap_flags);
    page = al_create_bitmap(256, 256);
    al_restore_state(&state);
    _al_pop_destructor_owner();

    back = _al_vector_alloc_back(&data->page_bitmaps);
    *back = page;

    /* Sometimes OpenGL will partly sample texels from the border of
     * glyphs. So we better clear the texture to transparency.
     * XXX This is very slow and avoidable with some effort.
     */
    al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
    al_hold_bitmap_drawing(false);
    al_set_target_bitmap(*back);
    al_clear_to_color(al_map_rgba_f(0, 0, 0, 0));
    al_restore_state(&state);

    data->page_pos_x = 0;
    data->page_pos_y = 0;
    data->page_line_height = 0;

    return page;
}
Exemple #29
0
/* Function: al_save_jpg_f
 */
bool al_save_jpg_f(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp)
{
    ALLEGRO_STATE state;
    struct save_jpg_entry_helper_data data;

    al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);

    memset(&data, 0, sizeof(data));
    save_jpg_entry_helper(fp, bmp, &data);

    al_restore_state(&state);

    return !data.error;
}
Exemple #30
0
/* Function: al_load_jpg_f
 */
ALLEGRO_BITMAP *al_load_jpg_f(ALLEGRO_FILE *fp)
{
    ALLEGRO_STATE state;
    struct load_jpg_entry_helper_data data;

    al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);

    memset(&data, 0, sizeof(data));
    load_jpg_entry_helper(fp, &data);

    al_restore_state(&state);

    return data.bmp;
}