This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 584ef7b40c75f90ad55347dac6e4fd95a4ff54af (commit) via 565271d45d92a19f90b6f8ec637e8626fe8c1f0f (commit) from 6e4677159b0d9febdd48f359e335277b53991093 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/584ef7b40c75f90ad55347dac6e4fd95a4ff5...
commit 584ef7b40c75f90ad55347dac6e4fd95a4ff54af Author: Cyril Hrubis metan@ucw.cz Date: Sun Feb 12 19:43:18 2012 +0100
demos: Add simple particle demo.
diff --git a/demos/Makefile b/demos/Makefile index eddfa9f..107f998 100644 --- a/demos/Makefile +++ b/demos/Makefile @@ -1,3 +1,3 @@ TOPDIR=.. -SUBDIRS=grinder fbshow +SUBDIRS=grinder fbshow particle include $(TOPDIR)/include.mk diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c index 4615607..5061397 100644 --- a/demos/particle/particle_demo.c +++ b/demos/particle/particle_demo.c @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) { const char *backend_opts = "fb"; int opt; - int pause_flag = 1; + int pause_flag = 0;
while ((opt = getopt(argc, argv, "b:Ii:Ps:r:")) != -1) { switch (opt) { @@ -105,7 +105,8 @@ int main(int argc, char *argv[]) GP_Fill(context, black_pixel); GP_BackendFlip(backend);
- struct space *space = space_create(1000, context->w<<8, context->h<<8); + struct space *space; + space = space_create(1000, 10<<8, 10<<8, (context->w - 10)<<8, (context->h - 10)<<8);
for (;;) { if (backend->Poll) @@ -135,6 +136,12 @@ int main(int argc, char *argv[]) case GP_KEY_P: pause_flag = !pause_flag; break; + case GP_KEY_G: + space->gay = 1; + break; + case GP_KEY_T: + space->gay = 0; + break; } break; } diff --git a/demos/particle/space.c b/demos/particle/space.c index bdf87e0..6a244b7 100644 --- a/demos/particle/space.c +++ b/demos/particle/space.c @@ -22,7 +22,8 @@
#include "space.h"
-struct space *space_create(unsigned int particle_count, int w, int h) +struct space *space_create(unsigned int particle_count, int min_w, int min_h, + int max_w, int max_h) { struct space *new = malloc(sizeof(struct space) + sizeof(struct particle) * particle_count); @@ -31,14 +32,21 @@ struct space *space_create(unsigned int particle_count, int w, int h) return NULL;
new->particle_count = particle_count; - new->w = w; - new->h = h; + new->min_w = min_w; + new->min_h = min_h; + new->max_w = max_w; + new->max_h = max_h; + + new->gax = 0; + new->gay = 0; + + new->elasticity = (1<<8) - (1<<6);
unsigned int i;
for (i = 0; i < particle_count; i++) { - new->particles[i].x = random() % w; - new->particles[i].y = random() % h; + new->particles[i].x = random() % (max_w - min_w) + min_w; + new->particles[i].y = random() % (max_h - min_h) + min_h; new->particles[i].vx = random() % 40 - 20; new->particles[i].vy = random() % 40 - 20; } @@ -63,12 +71,12 @@ void space_draw_particles(GP_Context *context, struct space *space)
static void modify_speeds(struct space *space, int time) { - unsigned int i, j; + unsigned int i;
for (i = 0; i < space->particle_count; i++) { -// space->particles[i].vx += * time; - space->particles[i].vy += time; - } + space->particles[i].vy += space->gax * time; + space->particles[i].vy += space->gay * time; + } }
void space_time_tick(struct space *space, int time) @@ -78,11 +86,14 @@ void space_time_tick(struct space *space, int time) modify_speeds(space, time);
for (i = 0; i < space->particle_count; i++) { - if (space->particles[i].x <= 2 || space->particles[i].x >= space->w - 2) - space->particles[i].vx *= -0.9; + + if ((space->particles[i].x < space->min_w && space->particles[i].vx < 0) || + (space->particles[i].x >= space->max_w && space->particles[i].vx > 0)) + space->particles[i].vx = GP_FP_MUL(space->particles[i].vx, -space->elasticity); - if (space->particles[i].y <= 2 || space->particles[i].y >= space->h - 2) - space->particles[i].vy *= -0.9; + if ((space->particles[i].y < space->min_h && space->particles[i].vy < 0) || + (space->particles[i].y >= space->max_h && space->particles[i].vy > 0)) + space->particles[i].vy = GP_FP_MUL(space->particles[i].vy, -space->elasticity); space->particles[i].x += space->particles[i].vx * time; space->particles[i].y += space->particles[i].vy * time; diff --git a/demos/particle/space.h b/demos/particle/space.h index 0cb7c3f..d4b01a5 100644 --- a/demos/particle/space.h +++ b/demos/particle/space.h @@ -44,13 +44,25 @@ struct particle { struct space { unsigned int particle_count;
- int w; - int h; + /* space is an rectanle */ + int min_w; + int min_h; + + int max_w; + int max_h; + + /* gravitation vector */ + int gax; + int gay; + + /* elasticity at the boudaries */ + int elasticity;
struct particle particles[]; };
-struct space *space_create(unsigned int particle_count, int w, int h); +struct space *space_create(unsigned int particle_count, int min_w, int min_h, + int max_w, int max_h);
void space_destroy(struct space *space);
http://repo.or.cz/w/gfxprim.git/commit/565271d45d92a19f90b6f8ec637e8626fe8c1...
commit 565271d45d92a19f90b6f8ec637e8626fe8c1f0f Author: Cyril Hrubis metan@ucw.cz Date: Sun Feb 12 19:41:53 2012 +0100
gfx: Added PutPixelAA.
diff --git a/demos/particle/Makefile b/demos/particle/Makefile new file mode 100644 index 0000000..9843284 --- /dev/null +++ b/demos/particle/Makefile @@ -0,0 +1,13 @@ +TOPDIR=../.. + +CSOURCES=$(shell echo *.c) + +INCLUDE= +LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/ + +APPS=particle_demo + +$(APPS): space.o + +include $(TOPDIR)/include.mk +include $(TOPDIR)/app.mk diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c new file mode 100644 index 0000000..4615607 --- /dev/null +++ b/demos/particle/particle_demo.c @@ -0,0 +1,153 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + + /* + + Particle demo. + + */ + +#include <signal.h> +#include <string.h> +#include <GP.h> +#include <backends/GP_Backends.h> + +#include "space.h" + +static GP_Pixel black_pixel; +static GP_Pixel white_pixel; + +static GP_Backend *backend = NULL; +static GP_Context *context = NULL; + +static void sighandler(int signo) +{ + if (backend != NULL) + GP_BackendExit(backend); + + fprintf(stderr, "Got signal %in", signo); + + exit(1); +} + +static void init_backend(const char *backend_opts) +{ + if (!strcmp(backend_opts, "fb")) { + fprintf(stderr, "Initalizing framebuffer backendn"); + backend = GP_BackendLinuxFBInit("/dev/fb0"); + } + + if (!strcmp(backend_opts, "SDL")) { + fprintf(stderr, "Initalizing SDL backendn"); + backend = GP_BackendSDLInit(800, 600, 0, 0); + } + + if (!strcmp(backend_opts, "SDL:FS")) { + fprintf(stderr, "Initalizing SDL fullscreenn"); + backend = GP_BackendSDLInit(0, 0, 0, GP_SDL_FULLSCREEN); + } + + if (backend == NULL) { + fprintf(stderr, "Failed to initalize backend '%s'n", backend_opts); + exit(1); + } +} + +int main(int argc, char *argv[]) +{ + const char *backend_opts = "fb"; + int opt; + int pause_flag = 1; + + while ((opt = getopt(argc, argv, "b:Ii:Ps:r:")) != -1) { + switch (opt) { + case 'b': + backend_opts = optarg; + break; + default: + fprintf(stderr, "Invalid paramter '%c'n", opt); + } + } + + GP_SetDebugLevel(10); + + signal(SIGINT, sighandler); + signal(SIGSEGV, sighandler); + signal(SIGBUS, sighandler); + signal(SIGABRT, sighandler); + + init_backend(backend_opts); + + context = backend->context; + + black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); + white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + + GP_Fill(context, black_pixel); + GP_BackendFlip(backend); + + struct space *space = space_create(1000, context->w<<8, context->h<<8); + + for (;;) { + if (backend->Poll) + GP_BackendPoll(backend); + + usleep(5000); + + /* Read and parse events */ + GP_Event ev; + + while (GP_EventGet(&ev)) { + + GP_EventDump(&ev); + + switch (ev.type) { + case GP_EV_KEY: + if (ev.code != GP_EV_KEY_DOWN) + continue; + + switch (ev.val.key.key) { + case GP_KEY_ESC: + case GP_KEY_ENTER: + case GP_KEY_Q: + GP_BackendExit(backend); + return 0; + break; + case GP_KEY_P: + pause_flag = !pause_flag; + break; + } + break; + } + } + + if (!pause_flag) { + space_time_tick(space, 2); + space_draw_particles(context, space); + GP_BackendFlip(backend); + } + } + + GP_BackendExit(backend); + + return 0; +} diff --git a/demos/particle/runtest.sh b/demos/particle/runtest.sh new file mode 100755 index 0000000..0794707 --- /dev/null +++ b/demos/particle/runtest.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# Run dynamically linked test. +# + +PROG="$1" +shift + +LD_LIBRARY_PATH=../../build/ ./$PROG "$@" diff --git a/demos/particle/space.c b/demos/particle/space.c new file mode 100644 index 0000000..bdf87e0 --- /dev/null +++ b/demos/particle/space.c @@ -0,0 +1,90 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include "space.h" + +struct space *space_create(unsigned int particle_count, int w, int h) +{ + struct space *new = malloc(sizeof(struct space) + + sizeof(struct particle) * particle_count); + + if (new == NULL) + return NULL; + + new->particle_count = particle_count; + new->w = w; + new->h = h; + + unsigned int i; + + for (i = 0; i < particle_count; i++) { + new->particles[i].x = random() % w; + new->particles[i].y = random() % h; + new->particles[i].vx = random() % 40 - 20; + new->particles[i].vy = random() % 40 - 20; + } + + return new; +} + +void space_destroy(struct space *space) +{ + free(space); +} + +void space_draw_particles(GP_Context *context, struct space *space) +{ + unsigned int i; + + GP_Fill(context, 0); + + for (i = 0; i < space->particle_count; i++) + GP_PutPixelAA(context, space->particles[i].x, space->particles[i].y, 0xffffff); +} + +static void modify_speeds(struct space *space, int time) +{ + unsigned int i, j; + + for (i = 0; i < space->particle_count; i++) { +// space->particles[i].vx += * time; + space->particles[i].vy += time; + } +} + +void space_time_tick(struct space *space, int time) +{ + unsigned int i; + + modify_speeds(space, time); + + for (i = 0; i < space->particle_count; i++) { + if (space->particles[i].x <= 2 || space->particles[i].x >= space->w - 2) + space->particles[i].vx *= -0.9; + + if (space->particles[i].y <= 2 || space->particles[i].y >= space->h - 2) + space->particles[i].vy *= -0.9; + + space->particles[i].x += space->particles[i].vx * time; + space->particles[i].y += space->particles[i].vy * time; + } +} diff --git a/include/gfx/GP_Gfx.h b/demos/particle/space.h similarity index 64% copy from include/gfx/GP_Gfx.h copy to demos/particle/space.h index 54648a8..0cb7c3f 100644 --- a/include/gfx/GP_Gfx.h +++ b/demos/particle/space.h @@ -16,42 +16,46 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
-/* + /* + + Particle demo. + + */ + +#ifndef PARTICLE_H +#define PARTICLE_H + +#include <GP.h> + +struct particle { + /* fixed point coordinates */ + int x; + int y; + + /* fixed point speed */ + int vx; + int vy; +}; + +struct space { + unsigned int particle_count;
- This is a main header for gfx part. + int w; + int h;
- */ + struct particle particles[]; +};
-#ifndef GP_GFX_H -#define GP_GFX_H +struct space *space_create(unsigned int particle_count, int w, int h);
-/* basic definitions and structures */ -#include "core/GP_Context.h" -#include "core/GP_GetPutPixel.h" -#include "core/GP_WritePixel.h" +void space_destroy(struct space *space);
-/* public drawing API */ -#include "GP_Fill.h" -#include "GP_HLine.h" -#include "GP_VLine.h" -#include "GP_Line.h" -#include "GP_Rect.h" -#include "GP_Triangle.h" -#include "GP_Tetragon.h" -#include "GP_Circle.h" -#include "GP_CircleSeg.h" -#include "GP_Ellipse.h" -#include "GP_Arc.h" -#include "GP_Polygon.h" -#include "GP_Symbol.h" +void space_draw_particles(GP_Context *context, struct space *space);
-#include "GP_RectAA.h" +void space_time_tick(struct space *space, int time);
-#endif /* GP_GFX_H */ +#endif /* PARTICLE_H */ diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h index 54648a8..acc5fd2 100644 --- a/include/gfx/GP_Gfx.h +++ b/include/gfx/GP_Gfx.h @@ -53,5 +53,6 @@ #include "GP_Symbol.h"
#include "GP_RectAA.h" +#include "GP_PutPixelAA.h"
#endif /* GP_GFX_H */ diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_PutPixelAA.h similarity index 65% copy from include/gfx/GP_Gfx.h copy to include/gfx/GP_PutPixelAA.h index 54648a8..7d697c7 100644 --- a/include/gfx/GP_Gfx.h +++ b/include/gfx/GP_PutPixelAA.h @@ -16,42 +16,42 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
/* + + Puts an anti aliased pixel to context.
- This is a main header for gfx part. + The coordinates are in XX.8 fixed point format, see core/GP_FixedPoint.h + for helper macros. + + For RGB contexts gamma correction tables are used to generate correct + intensity for pixels.
*/
-#ifndef GP_GFX_H -#define GP_GFX_H +#ifndef GFX_GP_PUT_PIXEL_AA_H +#define GFX_GP_PUT_PIXEL_AA_H
-/* basic definitions and structures */ #include "core/GP_Context.h" -#include "core/GP_GetPutPixel.h" -#include "core/GP_WritePixel.h" - -/* public drawing API */ -#include "GP_Fill.h" -#include "GP_HLine.h" -#include "GP_VLine.h" -#include "GP_Line.h" -#include "GP_Rect.h" -#include "GP_Triangle.h" -#include "GP_Tetragon.h" -#include "GP_Circle.h" -#include "GP_CircleSeg.h" -#include "GP_Ellipse.h" -#include "GP_Arc.h" -#include "GP_Polygon.h" -#include "GP_Symbol.h" - -#include "GP_RectAA.h" - -#endif /* GP_GFX_H */ + +/* + * Anti Aliased Put Pixel respecting context rotation flags and with clipping. + */ +void GP_PutPixelAA(GP_Context *context, GP_Coord x, GP_Coord y, GP_Pixel pixel); + +/* + * Anti Aliased Put Pixel with clipping. + */ +void GP_PutPixelAA_Raw_Clipped(GP_Context *context, GP_Coord x, GP_Coord y, + GP_Pixel pixel); + +/* + * Raw Put Pixel. + */ +void GP_PutPixelAA_Raw(GP_Context *context, GP_Coord x, GP_Coord y, + GP_Pixel pixel); + +#endif /* GFX_GP_PUT_PIXEL_AA_H */ diff --git a/libs/gfx/GP_PutPixelAA.gen.c.t b/libs/gfx/GP_PutPixelAA.gen.c.t new file mode 100644 index 0000000..625af68 --- /dev/null +++ b/libs/gfx/GP_PutPixelAA.gen.c.t @@ -0,0 +1,53 @@ +%% extends "base.c.t" + +{% block descr %}Anti Aliased Put Pixel{% endblock %} + +%% block body + +#include "core/GP_Context.h" +#include "core/GP_MixPixels.h" +#include "core/GP_FixedPoint.h" +#include "core/GP_GammaCorrection.h" + +#include "gfx/GP_HLine.h" +#include "gfx/GP_VLine.h" + +#define FP_TO_PERC(a) (GP_FP_ROUND_TO_INT((a) * 255)) + +void GP_PutPixelAA_Raw(GP_Context *context, GP_Coord x, GP_Coord y, + GP_Pixel pixel) +{ + GP_Coord int_x = GP_FP_TO_INT(x); + GP_Coord int_y = GP_FP_TO_INT(y); + GP_Coord frac_x = GP_FP_FRAC(x); + GP_Coord frac_y = GP_FP_FRAC(y); + uint8_t perc; + + perc = FP_TO_PERC(GP_FP_MUL(GP_FP_1 - frac_x, GP_FP_1 - frac_y)); + GP_MixPixel_Raw_Clipped(context, int_x, int_y, pixel, perc); + + perc = FP_TO_PERC(GP_FP_MUL(frac_x, GP_FP_1 - frac_y)); + GP_MixPixel_Raw_Clipped(context, int_x + 1, int_y, pixel, perc); + + perc = FP_TO_PERC(GP_FP_MUL(GP_FP_1 - frac_x, frac_y)); + GP_MixPixel_Raw_Clipped(context, int_x, int_y + 1, pixel, perc); + + perc = FP_TO_PERC(GP_FP_MUL(frac_x, frac_y)); + GP_MixPixel_Raw_Clipped(context, int_x + 1, int_y + 1, pixel, perc); +} + +void GP_PutPixelAA_Raw_Clipped(GP_Context *context, GP_Coord x, GP_Coord y, + GP_Pixel pixel) +{ + GP_PutPixelAA_Raw(context, x, y, pixel); +} + +void GP_PutPixelAA(GP_Context *context, GP_Coord x, GP_Coord y, GP_Pixel pixel) +{ + GP_TRANSFORM_POINT_FP(context, x, y); + + GP_PutPixelAA_Raw_Clipped(context, x, y, pixel); +} + + +%% endblock body diff --git a/libs/gfx/Makefile b/libs/gfx/Makefile index 64fd479..3e7cb28 100644 --- a/libs/gfx/Makefile +++ b/libs/gfx/Makefile @@ -1,6 +1,6 @@ TOPDIR=../.. CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) -GENSOURCES=GP_LineAA.gen.c +GENSOURCES=GP_LineAA.gen.c GP_PutPixelAA.gen.c LIBNAME=gfx
include $(TOPDIR)/gen.mk
-----------------------------------------------------------------------
Summary of changes: demos/Makefile | 2 +- {tests/drivers => demos/particle}/Makefile | 5 +- demos/particle/particle_demo.c | 160 +++++++++++++++++++++ demos/{fbshow => particle}/runtest.sh | 0 demos/particle/space.c | 101 +++++++++++++ demos/{fbshow/cpu_timer.h => particle/space.h} | 57 +++++--- include/gfx/GP_Gfx.h | 1 + include/{loaders/GP_JPG.h => gfx/GP_PutPixelAA.h} | 45 +++--- libs/gfx/GP_PutPixelAA.gen.c.t | 53 +++++++ libs/gfx/Makefile | 2 +- 10 files changed, 382 insertions(+), 44 deletions(-) copy {tests/drivers => demos/particle}/Makefile (76%) create mode 100644 demos/particle/particle_demo.c copy demos/{fbshow => particle}/runtest.sh (100%) create mode 100644 demos/particle/space.c copy demos/{fbshow/cpu_timer.h => particle/space.h} (68%) copy include/{loaders/GP_JPG.h => gfx/GP_PutPixelAA.h} (66%) create mode 100644 libs/gfx/GP_PutPixelAA.gen.c.t
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.