Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
void _al_point_2d(ALLEGRO_BITMAP* texture, ALLEGRO_VERTEX* v)
{
   int shade = 1;
   int op, src_mode, dst_mode, op_alpha, src_alpha, dst_alpha;
   ALLEGRO_COLOR vc;
   int clip_min_x, clip_min_y, clip_max_x, clip_max_y;
   int x = (int)floorf(v->x);
   int y = (int)floorf(v->x);
   
   al_get_clipping_rectangle(&clip_min_x, &clip_min_y, &clip_max_x, &clip_max_y);
   clip_max_x += clip_min_x;
   clip_max_y += clip_min_y;
   
   if(x < clip_min_x || x >= clip_max_x || y < clip_min_y || y >= clip_max_y)
      return;

   vc = v->color;

   al_get_separate_blender(&op, &src_mode, &dst_mode, &op_alpha, &src_alpha, &dst_alpha);
   if (_AL_DEST_IS_ZERO && _AL_SRC_NOT_MODIFIED) {
      shade = 0;
   }
   
   if (texture) {
      float U = fix_var(v->u, al_get_bitmap_width(texture));
      float V = fix_var(v->v, al_get_bitmap_height(texture));
      ALLEGRO_COLOR color = al_get_pixel(texture, U, V);

      if(vc.r != 1 || vc.g != 1 || vc.b != 1 || vc.a != 1) {
         color.r *= vc.r;
         color.g *= vc.g;
         color.b *= vc.b;
         color.a *= vc.a;
      }

      if (shade) {
         al_put_blended_pixel(v->x, v->y, color);
      } else {
         al_put_pixel(v->x, v->y, color);
      }
   } else {
      ALLEGRO_COLOR color = al_map_rgba_f(vc.r, vc.g, vc.b, vc.a);
      if (shade) {
         al_put_blended_pixel(v->x, v->y, color);
      } else {
         al_put_pixel(v->x, v->y, color);
      }
   }
}
Ejemplo n.º 3
0
void redrawCells(ALLEGRO_BITMAP* pBuffer, bool** pCells, bool** pNextCells, short int iWidth, short int iHeight, ALLEGRO_COLOR oCellColor, ALLEGRO_COLOR oBackColor) {
	al_lock_bitmap(pBuffer, al_get_bitmap_format(pBuffer), ALLEGRO_LOCK_WRITEONLY);
	al_set_target_bitmap(pBuffer);	
	for (short int i = 0; i < iWidth; i++) {
		for (short int j = 0; j < iHeight; j++) {			
			if (pCells[i][j] == true) {
				al_put_pixel(i, j, oCellColor);
			}
			else {
				al_put_pixel(i, j, oBackColor);
			}
		}
	}	
	al_unlock_bitmap(pBuffer);
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
void    special_effects_update_before (void)
{
return;
	t_skin *skin = Skins_GetCurrentSkin();

	al_lock_bitmap(gui_buffer, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);

	al_set_target_bitmap(gui_buffer);
	switch (skin->effect)
	{
		// BLOOD DROPS -------------------------------------------------------------
	case SKIN_EFFECT_BLOOD:
		for (int i = 0; i < MAX_BLOOD_DROP; i ++)
		{
			t_skinfx_particle* p = &g_skinfx_particles[i];
			if (p->v && p->save.a != 0)
				al_put_pixel(p->x, p->y, p->save);
		}
		break;
	case SKIN_EFFECT_HEARTS:
		// Save old graphics --------------------------------------------------
		const int w = al_get_bitmap_width(Graphics.Misc.Heart1);
		const int h = al_get_bitmap_height(Graphics.Misc.Heart1);
		for (int i = 0; i < MAX_HEARTS; i ++)
		{
			t_skinfx_particle* p = &g_skinfx_particles[i];
			al_draw_bitmap_region(hearts_save[i], 0, 0, w, h, p->x, p->y, 0x0000);
		}
		break;
	}
	al_unlock_bitmap(gui_buffer);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
ALLEGRO_BITMAP *
apply_palette (ALLEGRO_BITMAP *bitmap, palette p)
{
  if (! bitmap) return NULL;

  ALLEGRO_BITMAP *cached = get_cached_palette (bitmap, p);
  if (cached) return cached;

  int x, y;
  ALLEGRO_BITMAP *rbitmap = clone_bitmap (bitmap);
  int w = al_get_bitmap_width (bitmap);
  int h = al_get_bitmap_height (bitmap);
  al_lock_bitmap (rbitmap, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);
  set_target_bitmap (rbitmap);
  for (y = 0; y < h; y++)
    for (x = 0; x < w; x++)
      al_put_pixel (x, y, p (al_get_pixel (rbitmap, x, y)));
  al_unlock_bitmap (rbitmap);

  struct palette_cache pc;
  pc.ib = bitmap;
  pc.pal = p;
  pc.ob = rbitmap;

  palette_cache =
    add_to_array (&pc, 1, palette_cache, &palette_cache_nmemb,
                  palette_cache_nmemb, sizeof (pc));

  qsort (palette_cache, palette_cache_nmemb, sizeof (pc),
         compare_palette_caches);

  return rbitmap;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
void Block::DrawPixel(int drawx, int drawy)
{
	ALLEGRO_COLOR temp;
	if(
		tileShapeBasic==tiletype_shape_basic::Floor || 
		tileShapeBasic==tiletype_shape_basic::Wall ||
		tileShapeBasic==tiletype_shape_basic::Ramp || 
		tileShapeBasic==tiletype_shape_basic::Stair
		)
	{
		al_put_pixel(drawx, drawy, lookupMaterialColor(this->material.type, this->material.index));
	}
	if(this->water.index)
	{
		if(this->water.type == 0) //water
			al_draw_pixel(drawx, drawy, al_map_rgba_f(0.6f, 0.85f, 0.92f, (float)water.index / 7.0f));
		else
			al_draw_pixel(drawx, drawy, al_map_rgba_f(1.0f, 0.5f, 0.15f, (float)water.index / 7.0f));
	}
	//Grass
	if(grasslevel > 0 && (
		(tileMaterial == tiletype_material::GRASS_DARK) || 
		(tileMaterial == tiletype_material::GRASS_DARK) ||
		(tileMaterial == tiletype_material::GRASS_DRY) ||
		(tileMaterial == tiletype_material::GRASS_DEAD)))
	{
		temp = lookupMaterialColor(WOOD, grassmat);
		al_draw_pixel(drawx, drawy, al_map_rgba_f(temp.r,temp.g, temp.b, (float)grasslevel/100.0f));
	}
}
Ejemplo n.º 12
0
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *icons[NUM_ICONS];
   ALLEGRO_EVENT_QUEUE *queue;
   int u, v;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   al_install_keyboard();
   al_init_image_addon();

   display = al_create_display(320, 200);
   if (!display) {
      abort_example("Error creating display\n");
   }
   al_clear_to_color(al_map_rgb_f(0, 0, 0));
   al_flip_display();

   /* First icon 16x16: Read from file. */
   icons[0] = al_load_bitmap("data/cursor.tga");
   if (!icons[0]) {
      abort_example("icons.tga not found\n");
   }

   /* Second icon 32x32: Create it. */
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   icons[1] = al_create_bitmap(32, 32);
   al_set_target_bitmap(icons[1]);
   for (v = 0; v < 32; v++) {
      for (u = 0; u < 32; u++) {
         al_put_pixel(u, v, al_map_rgb_f(u / 31.0, v / 31.0, 1));
      }
   }
   al_set_target_backbuffer(display);

   al_set_display_icons(display, NUM_ICONS, icons);

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));

   for (;;) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);

      if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
            event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
   }

   al_uninstall_system();

   return 0;
}
Ejemplo n.º 13
0
void
draw_star (struct star *s, struct stars_bitmap *sb, enum vm vm)
{
  al_lock_bitmap (sb->b, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);
  al_set_target_bitmap (sb->b);
  al_put_pixel (s->x - sb->c.x, s->y - sb->c.y, get_star_color (s->color, vm));
  al_unlock_bitmap (sb->b);
}
Ejemplo n.º 14
0
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
	struct GamestateResources *data = malloc(sizeof(struct GamestateResources));
	data->timeline = TM_Init(game, "main");
	data->bitmap = al_create_bitmap(game->viewport.width, game->viewport.height);
	data->checkerboard = al_create_bitmap(game->viewport.width, game->viewport.height);
	data->pixelator = al_create_bitmap(game->viewport.width, game->viewport.height);

	al_set_target_bitmap(data->checkerboard);
	al_lock_bitmap(data->checkerboard, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
	int x, y;
	for (x = 0; x < al_get_bitmap_width(data->checkerboard); x=x+2) {
		for (y = 0; y < al_get_bitmap_height(data->checkerboard); y=y+2) {
			al_put_pixel(x, y, al_map_rgba(0,0,0,64));
			al_put_pixel(x+1, y, al_map_rgba(0,0,0,0));
			al_put_pixel(x, y+1, al_map_rgba(0,0,0,0));
			al_put_pixel(x+1, y+1, al_map_rgba(0,0,0,0));
		}
	}
	al_unlock_bitmap(data->checkerboard);
	al_set_target_backbuffer(game->display);
	(*progress)(game);

	data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"),
	                              (int)(game->viewport.height*0.1666 / 8) * 8 ,0 );
	(*progress)(game);
	data->sample = al_load_sample( GetDataFilePath(game, "dosowisko.flac") );
	data->sound = al_create_sample_instance(data->sample);
	al_attach_sample_instance_to_mixer(data->sound, game->audio.music);
	al_set_sample_instance_playmode(data->sound, ALLEGRO_PLAYMODE_ONCE);
	(*progress)(game);

	data->kbd_sample = al_load_sample( GetDataFilePath(game, "kbd.flac") );
	data->kbd = al_create_sample_instance(data->kbd_sample);
	al_attach_sample_instance_to_mixer(data->kbd, game->audio.fx);
	al_set_sample_instance_playmode(data->kbd, ALLEGRO_PLAYMODE_ONCE);
	(*progress)(game);

	data->key_sample = al_load_sample( GetDataFilePath(game, "key.flac") );
	data->key = al_create_sample_instance(data->key_sample);
	al_attach_sample_instance_to_mixer(data->key, game->audio.fx);
	al_set_sample_instance_playmode(data->key, ALLEGRO_PLAYMODE_ONCE);
	(*progress)(game);

	return data;
}
Ejemplo n.º 15
0
void
draw_star (struct stars *stars, int i, enum vm vm)
{
  al_lock_bitmap (stars->b, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);
  set_target_bitmap (stars->b);
  al_put_pixel (stars->s[i].x - stars->c.x, stars->s[i].y - stars->c.y,
                get_star_color (stars->s[i].color, vm));
  al_unlock_bitmap (stars->b);
}
Ejemplo n.º 16
0
static void shader_solid_any_draw_opaque(uintptr_t state, int x1, int y, int x2)
{
   state_solid_any_2d* s = (state_solid_any_2d*)state;
   int x;

   for (x = x1; x <= x2; x++) {
      al_put_pixel(x, y - 1, s->cur_color);
   }
}
Ejemplo n.º 17
0
//Draw the mask, DEBUG ONLY
void
mask_draw(Mask *temp, int x, int y) {
	int j, k;
	for(j = 0; j < temp->widht; j++) {
		for(k = 0; k < temp->height; k++) {
			if (!temp->bits[j][k])
				al_put_pixel(x + j, y + k, al_map_rgba_f(0.75, 0, 0.75, 0.75));
		}
	}
}
Ejemplo n.º 18
0
static mrb_value
put_pixel(mrb_state *mrb, mrb_value self)
{
  mrb_int x;
  mrb_int y;
  ALLEGRO_COLOR *c;
  mrb_get_args(mrb, "iio", &x, &y, &c, &mrbal_color_data_type);
  al_put_pixel(mrbal_clamp_int(x), mrbal_clamp_int(y), *c);
  return mrb_nil_value();
}
Ejemplo n.º 19
0
// Draw
void particle::draw(){
  if( type == PIXEL){
    al_put_pixel( x, y, color);
  }
  else if( type == SQUARE){
    al_draw_rectangle( x, y, x + size, y + size, color, 1);
  }
  else if( type == CIRCLE){
    al_draw_circle( x, y, size, color, 1);
  }
}
BOOST_FIXTURE_TEST_CASE(can_set_the_alpha_threshold, Fixture)
{
   ALLEGRO_BITMAP *bmp = al_create_bitmap(1, 1);
   UISurfaceAreaBitmapAlpha surface_area = UISurfaceAreaBitmapAlpha(0, 0, bmp);
   surface_area.placement.align = vec2d(0, 0);
   al_set_target_bitmap(bmp);

   float alpha = 0.5;

   surface_area.set_alpha_threshold(alpha);
   al_put_pixel(0, 0, al_map_rgba_f(1.0, 1.0, 1.0, alpha - 0.01));
   BOOST_CHECK_EQUAL(false, surface_area.collides(0.5, 0.5));
   al_put_pixel(0, 0, al_map_rgba_f(1.0, 1.0, 1.0, alpha + 0.01));
   BOOST_CHECK_EQUAL(true, surface_area.collides(0.5, 0.5));

   alpha = 0.1;

   surface_area.set_alpha_threshold(alpha);
   al_put_pixel(0, 0, al_map_rgba_f(1.0, 1.0, 1.0, alpha - 0.01));
   BOOST_CHECK_EQUAL(false, surface_area.collides(0.5, 0.5));
   al_put_pixel(0, 0, al_map_rgba_f(1.0, 1.0, 1.0, alpha + 0.01));
   BOOST_CHECK_EQUAL(true, surface_area.collides(0.5, 0.5));

   alpha = 0.9;

   surface_area.set_alpha_threshold(alpha);
   al_put_pixel(0, 0, al_map_rgba_f(1.0, 1.0, 1.0, alpha - 0.01));
   BOOST_CHECK_EQUAL(false, surface_area.collides(0.5, 0.5));
   al_put_pixel(0, 0, al_map_rgba_f(1.0, 1.0, 1.0, alpha + 0.01));
   BOOST_CHECK_EQUAL(true, surface_area.collides(0.5, 0.5));
}
Ejemplo n.º 21
0
void
draw_pattern (ALLEGRO_BITMAP *bitmap, int ox, int oy, int w, int h,
              ALLEGRO_COLOR color_0, ALLEGRO_COLOR color_1)
{
  int x, y;
  set_target_bitmap (bitmap);
  al_lock_bitmap (bitmap, ALLEGRO_PIXEL_FORMAT_ANY,
                  ALLEGRO_LOCK_READWRITE);
  for (y = oy; y < oy + h; y++)
    for (x = ox; x < ox + w; x++)
      al_put_pixel (x, y, (x % 2 != y % 2) ? color_0 : color_1);
  al_unlock_bitmap (bitmap);
}
Ejemplo n.º 22
0
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;
}
Ejemplo n.º 23
0
void shal_put_pixel(int x,
                    int y,
                    float color_r,
                    float color_g,
                    float color_b,
                    float color_a)
{
    ALLEGRO_COLOR color;
    color.r = color_r;
    color.g = color_g;
    color.b = color_b;
    color.a = color_a;
    return al_put_pixel(x, y, color);
}
Ejemplo n.º 24
0
void WhiteNoise(struct Game *game) {
	ALLEGRO_BITMAP *bitmap = al_get_target_bitmap();
	al_lock_bitmap(bitmap, ALLEGRO_LOCK_WRITEONLY, 0);
	float val; int width, height;
	width = al_get_bitmap_width(bitmap);
	height = al_get_bitmap_height(bitmap);
	for (int i=0; i < width; i++) {
		for (int j=0; j < height; j++) {
			val = (float)rand()/(float)RAND_MAX;
			al_put_pixel(i, j, al_map_rgb_f(val, val, val));
		}
	}
	al_unlock_bitmap(bitmap);
}
bool			parseFile(const std::string &filename, int &w, int &h)
{
  std::string           line;
  std::ifstream		myfile(filename.c_str());
  int			i = 0;
  int			x = 0;
  int			y = 0;

  if (myfile.is_open())
    {
      while (myfile.good())
        {
	  std::getline(myfile, line);

	  if (i == 0)
	    {
	      std::string tk1, tk2;
	      std::stringstream ss(line);

	      ss >> tk1;
	      ss >> tk2;

	      if (tk2.size() < 1)
		return false;
	      w = std::atoi(tk1.c_str());
	      h = std::atoi(tk2.c_str());
	      if (w <= 0 || h <= 0)
		return false;
	      if (!al_create_display(w, h))
		return false;
	    }

	  else
	    {
	      std::vector<std::string> list;
	      splitString(list, line);
	      std::vector<std::string>::iterator it = list.begin();
	      x = 0;
	      while (it != list.end())
		{
		  int r, g, b;
		  getColor(r, g, b, (*it));
		  al_put_pixel(x, y, al_map_rgb(r, g, b));
		  ++it;
		  ++x;
		}
	      ++y;
	    }
	  ++i;
        }
Ejemplo n.º 26
0
void KinectPlayer::Render()
{
//   if (!mPlayerPresent) {
//      return;
//   }

   std::vector<UserData> users;
   mUserTracking.GetUsers(users);

   if (users.empty()) {
      return;
   }

   al_set_target_bitmap(mBitmap);
   al_clear_to_color(al_map_rgb(0x00, 0x00, 0x00));
   al_convert_mask_to_alpha(mBitmap, al_map_rgb(0x00, 0x00, 0x00));

   xn::SceneMetaData scene_meta;
   mUserTracking.GetUserPixels(users[0], scene_meta);

   const XnRGB24Pixel* pRgbBuf = mKinect.GetImageData();
   const XnLabel* pLabelBuf = scene_meta.Data();

   ALLEGRO_LOCKED_REGION* lock = al_lock_bitmap(mBitmap,
                                                al_get_bitmap_format(mBitmap),
                                                ALLEGRO_LOCK_WRITEONLY);

   al_set_target_bitmap(mBitmap);
   for (int y = 0; y < mBitmapHeight; y++)
   {
      for (int x = 0; x < mBitmapWidth; x++, pLabelBuf++, pRgbBuf++)
      {
         if (*pLabelBuf == users[0].GetId())
         {
            al_put_pixel(x, y, al_map_rgb(pRgbBuf->nRed,
                                          pRgbBuf->nGreen,
                                          pRgbBuf->nBlue));
         }
      }
   }
   al_unlock_bitmap(mBitmap);

   const int screen_x_res = al_get_display_width(al_get_current_display());
   const int screen_y_res = al_get_display_height(al_get_current_display());

   al_set_target_bitmap(al_get_backbuffer(al_get_current_display()));
   al_draw_scaled_bitmap(mBitmap, 0, 0, mBitmapWidth, mBitmapHeight,
      GetXPos(), GetYPos(), GetWidth(), GetHeight(), 0);
}
Ejemplo n.º 27
0
static void shader_grad_any_draw_opaque(uintptr_t state, int x1, int y, int x2)
{
   state_grad_any_2d* s = (state_grad_any_2d*)state;
   ALLEGRO_COLOR color = s->solid.cur_color;
   int x;

   for (x = x1; x <= x2; x++) {
      al_put_pixel(x, y - 1, color);
      
      color.r += s->color_dx.r;
      color.g += s->color_dx.g;
      color.b += s->color_dx.b;
      color.a += s->color_dx.a;
   }
}
Ejemplo n.º 28
0
ALLEGRO_BITMAP * Starfield::makeStarfield(int numStars, ALLEGRO_DISPLAY *display) {
    ALLEGRO_BITMAP * bit = al_create_bitmap(ScreenWidth, ScreenHeight);

    al_set_target_bitmap(bit);

    //al_clear_to_color(al_map_rgb(0, 0, 0));

    int i;
    for(i = 0; i < numStars; i++) {
        al_put_pixel(qrand() % ScreenWidth, qrand() % ScreenHeight, al_map_rgb(255,255,255));
    }

    al_set_target_bitmap(al_get_backbuffer(display));

    return bit;
}
Ejemplo n.º 29
0
static void shader_texture_solid_any_draw_opaque_white(uintptr_t state, int x1, int y, int x2)
{
   state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
   float u = s->u;
   float v = s->v;
   int x;
   ALLEGRO_COLOR color;
   
   for (x = x1; x <= x2; x++) {
      color = al_get_pixel(s->texture, fix_var(u, s->w), fix_var(v, s->h));
      al_put_pixel(x, y - 1, color);
      
      u += s->du_dx;
      v += s->dv_dx;
   }
}
Ejemplo n.º 30
0
// unused
void convert_grayscale(ALLEGRO_BITMAP *bmp) {
	ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
	int x, y, w, h, lum;
	unsigned char r, g, b;
	w = al_get_bitmap_width(bmp);
	h = al_get_bitmap_height(bmp);

	al_set_target_bitmap(bmp);
	al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ABGR_8888, ALLEGRO_LOCK_READWRITE);

	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			al_unmap_rgb(al_get_pixel(bmp, x, y), &r, &g, &b);
			lum = (0.299*r + 0.587*g + 0.114*b)/2; // dividing by two makes it darker, default should be not dividing
			al_put_pixel(x, y, al_map_rgb(lum, lum, lum)); // RGB to grayscale
		}
	}
	al_unlock_bitmap(bmp);
	al_set_target_bitmap(dispbuf);
}