[Freeciv-Dev] (PR#11433) Fog of War rendering improvement
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11433 >
Following the discussion on how to do fog of war with alpha blending, I
did a little test to implement an improvement to the fog of war rendering.
It doesn't use alpha-blending, since you would need to use pixbufs.
Instead the brightness of every pixel is reduced by 50%, by iterating over
each pixel in the pixmap.
There is little or no performance hit that I can notice, but it would be a
good idea to do some benchmarking. Is is possible to get a frames/s
output?
Patch against CVS head, for the Gtk 2.x client.
Screenshot: http://www.stud.ntnu.no/~andrearo/scr.png
Andreas Røsdal
diff -ruN -X freeciv-cvs-Dec-08/diff_ignore
freeciv-cvs-Dec-08/client/gui-gtk-2.0/mapview.c
freeciv-fow/client/gui-gtk-2.0/mapview.c
--- freeciv-cvs-Dec-08/client/gui-gtk-2.0/mapview.c 2004-12-09
17:06:35.000000000 +0100
+++ freeciv-fow/client/gui-gtk-2.0/mapview.c 2004-12-09 17:05:51.000000000
+0100
@@ -877,22 +877,48 @@
return;
}
- pixmap_put_sprite(pixmap, canvas_x, canvas_y, ssprite,
- 0, 0, ssprite->width, ssprite->height);
-
- /* I imagine this could be done more efficiently. Some pixels We first
- draw from the sprite, and then draw black afterwards. It would be much
- faster to just draw every second pixel black in the first place. */
if (fog) {
+ int x, y;
+ GdkImage* ftile = gdk_drawable_get_image(ssprite->pixmap,
+ 0, 0,
+ ssprite->width,
+ ssprite->height);
+ /* Iterate over all pixels, reducing brightness by 50%. */
+ for (x = 0; x < ssprite->width; x++) {
+ for (y = 0; y < ssprite->height; y++) {
+ guint32 pixel = gdk_image_get_pixel(ftile, x, y);
+
+ guint8 red = (((pixel & ftile->visual->red_mask) <<
+ (32 - ftile->visual->red_shift
+ - ftile->visual->red_prec)) >> 24) / 2;
+ guint8 green = (((pixel & ftile->visual->green_mask) <<
+ (32 - ftile->visual->green_shift
+ - ftile->visual->green_prec)) >> 24) / 2;
+ guint8 blue = (((pixel & ftile->visual->blue_mask) <<
+ (32 - ftile->visual->blue_shift
+ - ftile->visual->blue_prec)) >> 24) / 2;
+ guint32 result = red << ftile->visual->red_shift
+ | green << ftile->visual->green_shift
+ | blue << ftile->visual->blue_shift;
+
+ gdk_image_put_pixel(ftile, x , y, result);
+ }
+ }
+
gdk_gc_set_clip_origin(fill_tile_gc, canvas_x, canvas_y);
gdk_gc_set_clip_mask(fill_tile_gc, ssprite->mask);
- gdk_gc_set_foreground(fill_tile_gc, colors_standard[COLOR_STD_BLACK]);
gdk_gc_set_ts_origin(fill_tile_gc, canvas_x, canvas_y);
- gdk_gc_set_stipple(fill_tile_gc, black50);
- gdk_draw_rectangle(pixmap, fill_tile_gc, TRUE,
- canvas_x, canvas_y, ssprite->width, ssprite->height);
+ gdk_draw_image(pixmap, fill_tile_gc,
+ ftile,
+ 0, 0,
+ canvas_x, canvas_y,
+ ssprite->width, ssprite->height);
gdk_gc_set_clip_mask(fill_tile_gc, NULL);
+
+ } else {
+ pixmap_put_sprite(pixmap, canvas_x, canvas_y, ssprite,
+ 0, 0, ssprite->width, ssprite->height);
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#11433) Fog of War rendering improvement,
Andreas Røsdal <=
|
|