changeset 2081:9084e2e05f4a

lulz.
author William Pitcock <nenolod@atheme.org>
date Tue, 16 Oct 2007 02:06:46 -0500
parents f915d43db0dc
children cf87d00b86b9 2f0a350c0f78
files src/paranormal-ng/Makefile src/paranormal-ng/builtins.c src/paranormal-ng/general.c src/paranormal-ng/paranormal.c src/paranormal-ng/xform.c
diffstat 5 files changed, 69 insertions(+), 473 deletions(-) [+]
line wrap: on
line diff
--- a/src/paranormal-ng/Makefile	Mon Oct 15 06:51:29 2007 -0500
+++ b/src/paranormal-ng/Makefile	Tue Oct 16 02:06:46 2007 -0500
@@ -30,4 +30,4 @@
 
 CFLAGS += ${PLUGIN_CFLAGS}
 CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} ${XML_CPPFLAGS} ${SDL_CFLAGS} -I../../intl -I../.. -I.
-LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${XML_LIBS} ${SDL_LIBS} -lGL
+LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${XML_LIBS} ${SDL_LIBS} -lGL -lGLU
--- a/src/paranormal-ng/builtins.c	Mon Oct 15 06:51:29 2007 -0500
+++ b/src/paranormal-ng/builtins.c	Tue Oct 16 02:06:46 2007 -0500
@@ -66,12 +66,7 @@
 DECLARE_ACTUATOR (wave_scope);
 
 /* **************** xform **************** */
-DECLARE_ACTUATOR (xform_spin);
-DECLARE_ACTUATOR (xform_ripple);
-DECLARE_ACTUATOR (xform_bump_spin);
-DECLARE_ACTUATOR (xform_halfrender);
-DECLARE_ACTUATOR (xform_movement);
-DECLARE_ACTUATOR (xform_dynmovement);
+DECLARE_ACTUATOR (xform_adjust);
 
 /* **************** builtin_table **************** */
 struct pn_actuator_desc *builtin_table[] =
@@ -112,12 +107,7 @@
   &builtin_wave_radial,
   &builtin_wave_scope,
   /* **************** xform **************** */
-  &builtin_xform_spin,
-  &builtin_xform_ripple,
-  &builtin_xform_bump_spin,
-  &builtin_xform_halfrender,
-  &builtin_xform_movement,
-  &builtin_xform_dynmovement,
+  &builtin_xform_adjust,
   /* **************** the end! **************** */
   NULL
 };
--- a/src/paranormal-ng/general.c	Mon Oct 15 06:51:29 2007 -0500
+++ b/src/paranormal-ng/general.c	Tue Oct 16 02:06:46 2007 -0500
@@ -56,58 +56,63 @@
   NULL, NULL, general_fade_exec
 };
 
+/* thanks to feelgood_ICBM @ freenode for this */
+#define glError() { GLenum err; for(err = glGetError(); err; err = glGetError()) { fprintf(stderr, "glError: %s caught at %s:%u\n", \
+	(GLchar*)gluErrorString(err), __FILE__, __LINE__); } }
+
 /* **************** general_blur **************** */
-/* FIXME: add a variable radius */
-/* FIXME: SPEEEED */
 static void
 general_blur_exec (const struct pn_actuator_option *opts,
 	   gpointer data)
 {
-  int i,j;
-  register guchar *srcptr = pn_image_data->surface[0];
-  register guchar *destptr = pn_image_data->surface[1];
-  register int sum;
+  GLuint texture_id;
+
+  glGenTextures(1, &texture_id);
+  glBindTexture(GL_TEXTURE_2D, texture_id);
+
+  glError();
+
+  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_BYTE, NULL);
+
+  glError();
 
-  for (j=0; j<pn_image_data->height; j++)
-    for (i=0; i<pn_image_data->width; i++)
-      {
-	sum = *(srcptr)<<2;
+  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, -1, -1, 1, 1, 0);
+
+  glError();
+
+  glBindTexture(GL_TEXTURE_2D, 0);
+
+  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+  glBindTexture(GL_TEXTURE_2D, texture_id);
 
-	/* top */
-	if (j > 0)
-	  {
-	    sum += *(srcptr-pn_image_data->width)<<1;
-	    if (i > 0)
-	      sum += *(srcptr-pn_image_data->width-1);
-	    if (i < pn_image_data->width-1)
-	      sum += *(srcptr-pn_image_data->width+1);
-	  }
-	/* bottom */
-	if (j < pn_image_data->height-1)
-	  {
-	    sum += *(srcptr+pn_image_data->width)<<1;
-	    if (i > 0)
-	      sum += *(srcptr+pn_image_data->width-1);
-	    if (i < pn_image_data->width-1)
-	      sum += *(srcptr+pn_image_data->width+1);
-	  }
-	/* left */
-	if (i > 0)
-	  sum += *(srcptr-1)<<1;
-	/* right */
-	if (i < pn_image_data->width-1)
-	  sum += *(srcptr+1)<<1;
+  glError();
+
+  glBegin(GL_QUADS);
+
+  glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
+  glTexCoord2f(0, 1);
+  glVertex2i(-1, -1);
+  glVertex2i(-1, 1);
+  glVertex2i(1, 1);
+  glVertex2i(1, -1);
 
-	*destptr++ = (guchar)(sum >> 4);
-	srcptr++;
-      }
+  glEnd();
+  glBindTexture(GL_TEXTURE_2D, 0);
+
+  glError();
 
-  pn_swap_surfaces ();
+  glDeleteTextures(1, &texture_id);
+
+  glFlush();
+
+  glError();
 }
 
 struct pn_actuator_desc builtin_general_blur = 
 {
-  "general_blur", "Blur", "A simple 1 pixel radius blur",
+  "general_blur", "Blur", "A simple radial blur",
   0, NULL,
   NULL, NULL, general_blur_exec
 };
--- a/src/paranormal-ng/paranormal.c	Mon Oct 15 06:51:29 2007 -0500
+++ b/src/paranormal-ng/paranormal.c	Tue Oct 16 02:06:46 2007 -0500
@@ -51,7 +51,6 @@
 static void
 blit_to_screen (void)
 {
-  SDL_GL_SwapBuffers();
 }
 
 static void
@@ -203,8 +202,15 @@
 
   if (pn_rc->actuator)
     {
+      // set the viewport to a texture size
+      glViewport(0, 0, 128, 128);
+
+      // run actuators
       exec_actuator (pn_rc->actuator);
-      blit_to_screen ();
+
+      // reset the viewport to window size and draw
+      glViewport(0, 0, pn_image_data->width, pn_image_data->height);
+      SDL_GL_SwapBuffers();
     }
 }
 
--- a/src/paranormal-ng/xform.c	Mon Oct 15 06:51:29 2007 -0500
+++ b/src/paranormal-ng/xform.c	Tue Oct 16 02:06:46 2007 -0500
@@ -34,437 +34,31 @@
 
 #include "libcalc/calc.h"
 
-struct xform_vector
-{
-  gint32 offset; /* the offset of the top left pixel */
-  guint16 w; /* 4:4:4:4 NE, NW, SE, SW pixel weights
-		  The total should be 16 */
-
-  /* if offset < 0 then w is the color index to
-     which the pixel will be set */
-};
-
-static void
-xfvec (float x, float y, struct xform_vector *v)
-{
-  float xd, yd;
-  int weight[4];
-
-  if (x >= pn_image_data->width-1 || y >= pn_image_data->height-1
-      || x < 0 || y < 0)
-    {
-      v->offset = -1;
-      v->w = 0;
-      return;
-    }
-
-  v->offset = PN_IMG_INDEX (floor(x), floor(y));
-
-  xd = x - floor (x);
-  yd = y - floor (y);
-
-  weight[3] = xd * yd * 16;
-  weight[2] = (1-xd) * yd * 16;
-  weight[1] = xd * (1-yd) * 16;
-  weight[0] = 16 - weight[3] - weight[2] - weight[1]; /* just in case */
-
-  v->w = (weight[0]<<12) | (weight[1]<<8) | (weight[2]<<4) | weight[3];
-}
-
-static void
-apply_xform (struct xform_vector *vfield)
-{
-  int i;
-  struct xform_vector *v;
-  register guchar *srcptr;
-  register guchar *destptr;
-  register int color;
-
-  if (vfield == NULL)
-      return;
-
-  for (i=0, v=vfield, destptr=pn_image_data->surface[1];
-       i<pn_image_data->width*pn_image_data->height;
-       i++, v++, destptr++)
-    {
-      /* off the screen */
-      if (v->offset < 0)
-	{
-	  *destptr = (guchar)v->w;
-	  continue;
-	}
-
-      srcptr = pn_image_data->surface[0] + v->offset;
-
-      /* exactly on the pixel */
-      if (v->w == 0)
-	  *destptr = *srcptr;
-      
-      /* gotta blend the points */
-      else
-	{
-	  color =  *srcptr * (v->w>>12);
-	  color += *++srcptr * ((v->w>>8) & 0x0f);
-	  color += *(srcptr+=pn_image_data->width) * (v->w & 0x0f);
-	  color += *(--srcptr) * ((v->w>>4) & 0x0f);
-	  color >>= 4;
-	  *destptr = (guchar)color;
-	}
-    }
-}
-
-/* **************** xform_spin **************** */
-/* FIXME: Describe these better, how they are backwards */
-/* FIXME: better name? */
-struct pn_actuator_option_desc xform_spin_opts[] =
-{
-  { "angle", "The angle of rotation", OPT_TYPE_FLOAT, { fval: -8.0 } },
-  { "r_add", "The number of pixels by which the r coordinate will be "
-    "increased (before scaling)", OPT_TYPE_FLOAT, { fval: 0.0 } },
-  { "r_scale", "The amount by which the r coordinate of each pixel will "
-    "be scaled", OPT_TYPE_FLOAT, { fval: 1.0 } },
-  { NULL }
-};
-
-struct xform_spin_data
-{
-  int width, height;
-  struct xform_vector *vfield;
-};
-
-static void
-xform_spin_init (gpointer *data)
-{
-  *data = g_new0 (struct xform_spin_data, 1);
-}
-
-static void
-xform_spin_cleanup (gpointer data)
-{
-  struct xform_spin_data *d = (struct xform_spin_data *) data;
-
-  
-  if (d)
-    {
-      if (d->vfield)
-	g_free (d->vfield);
-      g_free (d);
-    }
-}
-
-static void
-xform_spin_exec (const struct pn_actuator_option *opts,
-		 gpointer data)
-{
-  struct xform_spin_data *d = (struct xform_spin_data*)data;
-  float i, j;
-
-  if (d->width != pn_image_data->width
-      || d->height != pn_image_data->height)
-    {
-      d->width = pn_image_data->width;
-      d->height = pn_image_data->height;
-
-      if (d->vfield)
-	g_free (d->vfield);
-
-      d->vfield = g_malloc0 (sizeof(struct xform_vector)
-			    * d->width * d->height);
-
-      for (j=-(pn_image_data->height>>1)+1; j<=pn_image_data->height>>1; j++)
-	for (i=-(pn_image_data->width>>1); i<pn_image_data->width>>1; i++)
-	  {
-	    float r, t = 0;
-	    float x, y;
-
-	    r = sqrt (i*i + j*j);
-	    if (r)
-	      t = asin (j/r);
-	    if (i < 0)
-	      t = M_PI - t;
-
-	    t += opts[0].val.fval * M_PI/180.0; 
-	    r += opts[1].val.fval;
-	    r *= opts[2].val.fval;
-
-	    x = (r * cos (t)) + (pn_image_data->width>>1);
-	    y = (pn_image_data->height>>1) - (r * sin (t));
-
-	    xfvec (x, y, &d->vfield
-		   [PN_IMG_INDEX ((pn_image_data->width>>1)+(int)rint(i),
-				  ((pn_image_data->height>>1)-(int)rint(j)))]);
-	  }
-    }
-
-  apply_xform (d->vfield);
-  pn_swap_surfaces ();
-}
-
-struct pn_actuator_desc builtin_xform_spin =
-{
-  "xform_spin", "Spin Transform", 
-  "Rotates and radially scales the image",
-  0, xform_spin_opts,
-  xform_spin_init, xform_spin_cleanup, xform_spin_exec
-};
-
-/* **************** xform_ripple **************** */
-struct pn_actuator_option_desc xform_ripple_opts[] =
-{
-  { "angle", "The angle of rotation", OPT_TYPE_FLOAT, { fval: 0 } },
-  { "ripples", "The number of ripples that fit on the screen "
-    "(horizontally)", OPT_TYPE_FLOAT, { fval: 8 } },
-  { "base_speed", "The minimum number of pixels to move each pixel",
-    OPT_TYPE_FLOAT, { fval: 1 } },
-  { "mod_speed", "The maximum number of pixels by which base_speed"
-    " will be modified", OPT_TYPE_FLOAT, { fval: 1 } },
-  { NULL }
-};
-
-struct xform_ripple_data
+/* **************** xform_adjust **************** */
+struct pn_actuator_option_desc xform_adjust_opts[] =
 {
-  int width, height;
-  struct xform_vector *vfield;
-};
-
-static void
-xform_ripple_init (gpointer *data)
-{
-  *data = g_new0 (struct xform_ripple_data, 1);
-}
-
-static void
-xform_ripple_cleanup (gpointer data)
-{
-  struct xform_ripple_data *d = (struct xform_ripple_data*) data;
-
-  if (d)
-    {
-      if (d->vfield)
-	g_free (d->vfield);
-      g_free (d);
-    }
-}
-
-static void
-xform_ripple_exec (const struct pn_actuator_option *opts,
-		 gpointer data)
-{
-  struct xform_ripple_data *d = (struct xform_ripple_data*)data;
-  float i, j;
-
-  if (d->width != pn_image_data->width
-      || d->height != pn_image_data->height)
-    {
-      d->width = pn_image_data->width;
-      d->height = pn_image_data->height;
-
-      if (d->vfield)
-	g_free (d->vfield);
-
-      d->vfield = g_malloc (sizeof(struct xform_vector)
-			    * d->width * d->height);
-
-      for (j=-(pn_image_data->height>>1)+1; j<=pn_image_data->height>>1; j++)
-	for (i=-(pn_image_data->width>>1); i<pn_image_data->width>>1; i++)
-	  {
-	    float r, t = 0;
-	    float x, y;
-
-	    r = sqrt (i*i + j*j);
-	    if (r)
-	      t = asin (j/r);
-	    if (i < 0)
-	      t = M_PI - t;
-
-	    t += opts[0].val.fval * M_PI/180.0; 
-
-	    if (r > 4)//(pn_image_data->width/(2*opts[1].val.fval)))
-	      r -=  opts[2].val.fval + (opts[3].val.fval/2) *
-		(1 + sin ((r/(pn_image_data->width/(2*opts[1].val.fval)))*M_PI));
-/*  	    else if (r > 4) */
-/*  	      r *= r/(pn_image_data->width/opts[1].val.fval); */
-	    else /* don't let it explode */
-	      r = 1000000;
-
-
-	    x = (r * cos (t)) + (pn_image_data->width>>1);
-	    y = (pn_image_data->height>>1) - (r * sin (t));
-
-	    xfvec (x, y, &d->vfield
-		   [PN_IMG_INDEX ((pn_image_data->width>>1)+(int)rint(i),
-				  ((pn_image_data->height>>1)-(int)rint(j)))]);
-	  }
-    }
-
-  apply_xform (d->vfield);
-  pn_swap_surfaces ();
-}
-
-struct pn_actuator_desc builtin_xform_ripple =
-{
-  "xform_ripple", "Ripple Transform", "Creates an ripple effect",
-  0, xform_ripple_opts,
-  xform_ripple_init, xform_ripple_cleanup, xform_ripple_exec
-};
-
-/* **************** xform_bump_spin **************** */
-struct pn_actuator_option_desc xform_bump_spin_opts[] =
-{
-  { "angle", "The angle of rotation", OPT_TYPE_FLOAT, { fval: 0 } },
-  { "bumps", "The number of bumps that on the image",
-    OPT_TYPE_FLOAT, { fval: 8 } },
-  { "base_scale", "The base radial scale",
-    OPT_TYPE_FLOAT, { fval: 0.95 } },
-  { "mod_scale", "The maximum amount that should be "
-    "added to the base_scale to create the 'bump' effect",
-    OPT_TYPE_FLOAT, { fval: .1 } },
-  { NULL }
-};
-
-struct xform_bump_spin_data
-{
-  int width, height;
-  struct xform_vector *vfield;
-};
-
-static void
-xform_bump_spin_init (gpointer *data)
-{
-  *data = g_new0 (struct xform_bump_spin_data, 1);
-}
-
-static void
-xform_bump_spin_cleanup (gpointer data)
-{
-  struct xform_bump_spin_data *d = (struct xform_bump_spin_data*) data;
-
-  if (d)
-    {
-      if (d->vfield)
-	g_free (d->vfield);
-      g_free (d);
-    }
-}
-
-static void
-xform_bump_spin_exec (const struct pn_actuator_option *opts,
-		 gpointer data)
-{
-  struct xform_bump_spin_data *d = (struct xform_bump_spin_data*)data;
-  float i, j;
-
-  if (d->width != pn_image_data->width
-      || d->height != pn_image_data->height)
-    {
-      d->width = pn_image_data->width;
-      d->height = pn_image_data->height;
-
-      if (d->vfield)
-	g_free (d->vfield);
-
-      d->vfield = g_malloc (sizeof(struct xform_vector)
-			    * d->width * d->height);
-
-      for (j=-(pn_image_data->height>>1)+1; j<=pn_image_data->height>>1; j++)
-	for (i=-(pn_image_data->width>>1); i<pn_image_data->width>>1; i++)
-	  {
-	    float r, t = 0;
-	    float x, y;
-
-	    r = sqrt (i*i + j*j);
-	    if (r)
-	      t = asin (j/r);
-	    if (i < 0)
-	      t = M_PI - t;
-
-	    t += opts[0].val.fval * M_PI/180.0;
-
-	    r *=  opts[2].val.fval + opts[3].val.fval
-	      * (1 + sin (t*opts[1].val.fval));
-
-	    x = (r * cos (t)) + (pn_image_data->width>>1);
-	    y = (pn_image_data->height>>1) - (r * sin (t));
-
-	    xfvec (x, y, &d->vfield
-		   [PN_IMG_INDEX ((pn_image_data->width>>1)+(int)rint(i),
-				  ((pn_image_data->height>>1)-(int)rint(j)))]);
-	  }
-    }
-
-  apply_xform (d->vfield);
-  pn_swap_surfaces ();
-}
-
-struct pn_actuator_desc builtin_xform_bump_spin =
-{
-  "xform_bump_spin", "Bump Transform", 
-  "Rotate the image at a varying speed to create "
-  "the illusion of bumps",
-  0, xform_bump_spin_opts,
-  xform_bump_spin_init, xform_bump_spin_cleanup, xform_bump_spin_exec
-};
-
-/* **************** xform_halfrender **************** */
-struct pn_actuator_option_desc xform_halfrender_opts[] =
-{
-  { "direction", "Negative is horizontal, positive is vertical.", 
-    OPT_TYPE_INT, { ival: 1 } },
-  { "render_twice", "Render the second image.",
-    OPT_TYPE_BOOLEAN, { bval: TRUE } },
+  { "x", "adjustment to x", OPT_TYPE_FLOAT, { fval: 1.0 } },
+  { "y", "adjustment to y", OPT_TYPE_FLOAT, { fval: 1.0 } },
+  { "z", "adjustment to z", OPT_TYPE_FLOAT, { fval: 1.0 } },
   { NULL }
 };
 
 static void
-xform_halfrender_exec (const struct pn_actuator_option *opts,
+xform_adjust_exec (const struct pn_actuator_option *opts,
 		 gpointer data)
 {
-  gint x, y;
-
-  if (opts[0].val.ival < 0)
-    {
-       for (y = 0; y < pn_image_data->height; y += 2)
-         {
-            for (x = 0; x < pn_image_data->width; x++)
-              {
-                 pn_image_data->surface[1][PN_IMG_INDEX(x, y / 2)] =
-                   pn_image_data->surface[0][PN_IMG_INDEX(x, y)];
-	         if (opts[1].val.bval)
-                   {
-                     pn_image_data->surface[1][PN_IMG_INDEX(x, (y / 2) + (pn_image_data->height / 2))] =
-                       pn_image_data->surface[0][PN_IMG_INDEX(x, y)];
-                   }
-              }
-         }
-    }
-  else
-    {
-       for (y = 0; y < pn_image_data->height; y++)
-         {
-            for (x = 0; x < pn_image_data->width; x += 2)
-              {
-                 pn_image_data->surface[1][PN_IMG_INDEX(x / 2, y)] =
-                   pn_image_data->surface[0][PN_IMG_INDEX(x, y)];
-                 if (opts[1].val.bval)
-                   {
-                     pn_image_data->surface[1][PN_IMG_INDEX((x / 2) + (pn_image_data->width / 2), y)] =
-                       pn_image_data->surface[0][PN_IMG_INDEX(x, y)];
-                   }
-              }
-         }
-    }
-
-    pn_swap_surfaces ();
+  glTranslatef(opts[0].val.fval, opts[1].val.fval, opts[2].val.fval);
 }
 
-struct pn_actuator_desc builtin_xform_halfrender =
+struct pn_actuator_desc builtin_xform_adjust =
 {
-  "xform_halfrender", "Halfrender Transform",
-  "Divides the surface in half and renders it twice.",
-  0, xform_halfrender_opts,
-  NULL, NULL, xform_halfrender_exec
+  "xform_adjust", "Adjust", 
+  "Rotates and radially scales the image",
+  0, xform_adjust_opts,
+  NULL, NULL, xform_adjust_exec
 };
 
+#if 0
 /* **************** xform_movement **************** */
 struct pn_actuator_option_desc xform_movement_opts[] =
 {
@@ -779,3 +373,4 @@
   0, xform_dynmovement_opts,
   xform_dynmovement_init, xform_dynmovement_cleanup, xform_dynmovement_exec
 };
+#endif