コード例 #1
0
ファイル: render.cpp プロジェクト: mk219533/tesseract-ocr
/**********************************************************************
 * display_blob
 *
 * Macro to display blob in a window.
 **********************************************************************/
void display_blob(TBLOB *blob, C_COL color) {
  /* Size of drawable */
  if (blob_window == NULL) {
    blob_window = c_create_window ("Blobs", 520, 10,
      500, 256, -1000.0, 1000.0, 0.0, 256.0);
  }
  else {
    c_clear_window(blob_window);
  }

  render_blob(blob_window, blob, color);
}
コード例 #2
0
ファイル: parabolik.c プロジェクト: crtc-demos/wobble
int
main (int argc, char* argv[])
{
  int cable_type, quit = 0;
  float rot1 = 0.0, rot2 = 0.0, rot3 = 0.0;
  kos_img_t front_txr, back_txr, tmp_img;
  pvr_ptr_t texaddr;
  GLuint texture[8];
  int blendfunc = 2;
  float eye_rot = 0;

  cable_type = vid_check_cable ();
  
  if (cable_type == CT_VGA)
    vid_init (DM_640x480_VGA, PM_RGB565);
  else
    vid_init (DM_640x480_PAL_IL, PM_RGB565);
  
  init_pvr ();

  glKosInit ();

  sphere = mkspheredata (3, &nstrip, &stripl);

  glGenTextures (8, &texture[0]);

#if 1
  kmg_to_img ("/rd/sky1.kmg", &front_txr);
  texaddr = pvr_mem_malloc (front_txr.byte_count);
  pvr_txr_load_kimg (&front_txr, texaddr, PVR_TXRFMT_VQ_ENABLE);
  kos_img_free (&front_txr, 0);
  
  glBindTexture (GL_TEXTURE_2D, texture[0]);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, front_txr.w, front_txr.h,
	      texaddr);

  kmg_to_img ("/rd/sky2o.kmg", &back_txr);
  texaddr = pvr_mem_malloc (back_txr.byte_count);
  pvr_txr_load_kimg (&back_txr, texaddr, PVR_TXRFMT_VQ_ENABLE);
  kos_img_free (&back_txr, 0);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  glBindTexture (GL_TEXTURE_2D, texture[1]);
  glKosTex2D (GL_ARGB4444_TWID | GL_VQ_ENABLE, back_txr.w, back_txr.h, texaddr);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  
  glBindTexture (GL_TEXTURE_2D, texture[2]);
  kmg_to_img ("/rd/sky3.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[3]);
  kmg_to_img ("/rd/sky4.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[4]);
  kmg_to_img ("/rd/sky5.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[5]);
  kmg_to_img ("/rd/sky6.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[6]);
  kmg_to_img ("/rd/sky7.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[7]);
  kmg_to_img ("/rd/sky8.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

#else  
  png_to_img ("/rd/sky1.png", PNG_MASK_ALPHA, &front_txr);
  texaddr = pvr_mem_malloc (front_txr.w * front_txr.h * 2);
  pvr_txr_load_kimg (&front_txr, texaddr, PVR_TXRLOAD_INVERT_Y);
  kos_img_free (&front_txr, 0);
  
  glBindTexture (GL_TEXTURE_2D, texture[0]);
  glKosTex2D (GL_ARGB1555_TWID, front_txr.w, front_txr.h, texaddr);

  png_to_img ("/rd/sky2o.png", PNG_MASK_ALPHA, &back_txr);
  texaddr = pvr_mem_malloc (back_txr.w * back_txr.h * 2);
  pvr_txr_load_kimg (&back_txr, texaddr, PVR_TXRLOAD_INVERT_Y);
  kos_img_free (&back_txr, 0);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  glBindTexture (GL_TEXTURE_2D, texture[1]);
  glKosTex2D (GL_ARGB1555_TWID, back_txr.w, back_txr.h, texaddr);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  
  glBindTexture (GL_TEXTURE_2D, texture[2]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky3.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[3]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky4.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[4]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky5.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[5]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky6.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[6]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky7.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[7]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky8.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);
#endif
  
  glEnable (GL_DEPTH_TEST);
  glEnable (GL_CULL_FACE);
  glEnable (GL_TEXTURE_2D);
  glShadeModel (GL_SMOOTH);
  glClearDepth (1.0f);
  glDepthFunc (GL_LEQUAL);
  
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  gluPerspective (60.0,			/* Field of view in degrees.  */
		  640.0 / 480.0,	/* Aspect ratio.  */
		  1.0,			/* Z near.  */
		  50.0);		/* Z far.  */

  glMatrixMode (GL_MODELVIEW);
  
  while (!quit)
    {
      MAPLE_FOREACH_BEGIN (MAPLE_FUNC_CONTROLLER, cont_state_t, st)
        {
	  if (st->buttons & CONT_START)
	    quit = 1;
	  
	  eye_pos[0] = st->joyx / 25.0;
	  eye_pos[1] = st->joyy / 25.0;
	  eye_pos[2] = 5 * sin (eye_rot);
	  
	  if (st->buttons & CONT_A)
	    blendfunc = 0;
	  else if (st->buttons & CONT_B)
	    blendfunc = 1;
	  else if (st->buttons & CONT_X)
	    blendfunc = 2;
	}
      MAPLE_FOREACH_END ()
      
      draw_vectors = 10;
      
      glLoadIdentity ();
      gluLookAt (eye_pos[0], eye_pos[1], eye_pos[2],	/* Eye position.  */
		 0.0,   0.0,   0.0,			/* Centre.  */
		 0.0,   1.0,   0.0);			/* Up.  */

      glGetFloatv (GL_MODELVIEW_MATRIX, &camera[0][0]);

      invcamera[0][0] = camera[0][0];
      invcamera[0][1] = camera[1][0];
      invcamera[0][2] = camera[2][0];
      invcamera[0][3] = 0.0;

      invcamera[1][0] = camera[0][1];
      invcamera[1][1] = camera[1][1];
      invcamera[1][2] = camera[2][1];
      invcamera[1][3] = 0.0;

      invcamera[2][0] = camera[0][2];
      invcamera[2][1] = camera[1][2];
      invcamera[2][2] = camera[2][2];
      invcamera[2][3] = 0.0;

      invcamera[3][0] = 0.0;
      invcamera[3][1] = 0.0;
      invcamera[3][2] = 0.0;
      invcamera[3][3] = 1.0;

      /*dbgio_printf ("inverted camera orthogonality: %f %f %f\n",
		    (double) vec_dot (invcamera[0], invcamera[1]),
		    (double) vec_dot (invcamera[1], invcamera[2]),
		    (double) vec_dot (invcamera[2], invcamera[0]));*/

      /*dbgio_printf ("Inverted camera matrix:\n");
      for (i = 0; i < 4; i++)
	{
	  dbgio_printf ("[ %f %f %f %f ]\n",
                	(double) invcamera[0][i], (double) invcamera[1][i],
	        	(double) invcamera[2][i], (double) invcamera[3][i]);
	}*/

      glKosBeginFrame ();

      /*glPushMatrix ();
      glTranslatef (-camera[3][0], -camera[3][1], -camera[3][2]);*/
      render_cube (&texture[2]);
      /*glPopMatrix ();*/
      
      glPushMatrix ();
      
      #if 1
      glRotatef (rot1, 0.0, 1.0, 0.0);
      rot1 += 0.7;
      glRotatef (rot2, 1.0, 0.0, 0.0);
      rot2 += 0.29;
      #else
      glRotatef (rot1, 0.0, 0.0, 1.0);
      rot1 += 0.7;
      #endif
      
      if (rot1 >= 360)
        rot1 -= 360;

      if (rot2 >= 360)
        rot2 -= 360;
      
      eye_rot += 0.05;
      if (eye_rot >= 2 * M_PI)
        eye_rot -= 2 * M_PI;
      
      blob_phase += 0.05;
      if (blob_phase >= 24 * M_PI)
        blob_phase -= 24 * M_PI;
      
      /* Render front.  */
      glBindTexture (GL_TEXTURE_2D, texture[0]);
      glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);

      #if 1
      render_blob (sphere, nstrip, stripl, 1);
      #else
      render_torus (1.0, 0.6, 1);
      #endif
            
      glPushMatrix ();
      glRotatef (rot3, 1.0, 0.0, 0.0);
      glTranslatef (2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 1);
      glPopMatrix ();
      glPushMatrix ();
      glRotatef (-rot3, 1.0, 0.0, 0.0);
      glTranslatef (-2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 1);
      glPopMatrix ();
      
      glKosFinishList ();

      /* Render back.  */
      glBindTexture (GL_TEXTURE_2D, texture[1]);
      glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      if (blendfunc == 0)
        glBlendFunc (GL_SRC_ALPHA, GL_ZERO);
      else if (blendfunc == 1)
        glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
      else
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
      #if 1
      //glDisable (GL_TEXTURE_2D);
      render_blob (sphere, nstrip, stripl, 0);
      //glEnable (GL_TEXTURE_2D);
      #else
      render_torus (1.0, 0.6, 0);
      #endif

      glPushMatrix ();
      glRotatef (rot3, 1.0, 0.0, 0.0);
      glTranslatef (2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 0);
      glPopMatrix ();
      glPushMatrix ();
      glRotatef (-rot3, 1.0, 0.0, 0.0);
      glTranslatef (-2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 0);
      glPopMatrix ();

      rot3 += 1;
      if (rot3 >= 360)
        rot3 -= 360;

      glPopMatrix ();
      
      glKosFinishFrame ();
    }
  
  glKosShutdown ();
  
  pvr_shutdown ();
  
  vid_shutdown ();
  /* Make dc-load look nicer.  */
  vid_init (DM_640x480_PAL_IL, PM_RGB565);

  return 0;
}
コード例 #3
0
ファイル: gimpink.c プロジェクト: DevMaggio/gimp
static void
gimp_ink_motion (GimpPaintCore    *paint_core,
                 GimpDrawable     *drawable,
                 GimpPaintOptions *paint_options,
                 const GimpCoords *coords,
                 guint32           time)
{
  GimpInk        *ink        = GIMP_INK (paint_core);
  GimpInkOptions *options    = GIMP_INK_OPTIONS (paint_options);
  GimpContext    *context    = GIMP_CONTEXT (paint_options);
  GimpBlob       *blob_union = NULL;
  GimpBlob       *blob_to_render;
  GeglBuffer     *paint_buffer;
  gint            paint_buffer_x;
  gint            paint_buffer_y;
  GimpRGB         foreground;
  GeglColor      *color;

  if (! ink->last_blob)
    {
      ink->last_blob = ink_pen_ellipse (options,
                                        coords->x,
                                        coords->y,
                                        coords->pressure,
                                        coords->xtilt,
                                        coords->ytilt,
                                        100);

      if (ink->start_blob)
        g_free (ink->start_blob);

      ink->start_blob = gimp_blob_duplicate (ink->last_blob);

      blob_to_render = ink->last_blob;
    }
  else
    {
      GimpBlob *blob = ink_pen_ellipse (options,
                                        coords->x,
                                        coords->y,
                                        coords->pressure,
                                        coords->xtilt,
                                        coords->ytilt,
                                        coords->velocity * 100);

      blob_union = gimp_blob_convex_union (ink->last_blob, blob);

      g_free (ink->last_blob);
      ink->last_blob = blob;

      blob_to_render = blob_union;
    }

  /* Get the buffer */
  ink->cur_blob = blob_to_render;
  paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable,
                                                   paint_options, coords,
                                                   &paint_buffer_x,
                                                   &paint_buffer_y);
  ink->cur_blob = NULL;

  if (! paint_buffer)
    return;

  gimp_context_get_foreground (context, &foreground);
  color = gimp_gegl_color_new (&foreground);

  gegl_buffer_set_color (paint_buffer, NULL, color);
  g_object_unref (color);

  /*  draw the blob directly to the canvas_buffer  */
  render_blob (paint_core->canvas_buffer,
               GEGL_RECTANGLE (paint_core->paint_buffer_x,
                               paint_core->paint_buffer_y,
                               gegl_buffer_get_width  (paint_core->paint_buffer),
                               gegl_buffer_get_height (paint_core->paint_buffer)),
               blob_to_render);

  /*  draw the paint_area using the just rendered canvas_buffer as mask */
  gimp_paint_core_paste (paint_core,
                         paint_core->canvas_buffer,
                         GEGL_RECTANGLE (paint_core->paint_buffer_x,
                                         paint_core->paint_buffer_y,
                                         gegl_buffer_get_width  (paint_core->paint_buffer),
                                         gegl_buffer_get_height (paint_core->paint_buffer)),
                         drawable,
                         GIMP_OPACITY_OPAQUE,
                         gimp_context_get_opacity (context),
                         gimp_context_get_paint_mode (context),
                         GIMP_PAINT_CONSTANT);

  if (blob_union)
    g_free (blob_union);
}
コード例 #4
0
ファイル: gimpink.c プロジェクト: MichaelMure/Gimp-Cage-Tool
static void
gimp_ink_motion (GimpPaintCore    *paint_core,
                 GimpDrawable     *drawable,
                 GimpPaintOptions *paint_options,
                 const GimpCoords *coords,
                 guint32           time)
{
  GimpInk        *ink     = GIMP_INK (paint_core);
  GimpInkOptions *options = GIMP_INK_OPTIONS (paint_options);
  GimpContext    *context = GIMP_CONTEXT (paint_options);
  GimpImage      *image;
  GimpBlob       *blob_union = NULL;
  GimpBlob       *blob_to_render;
  TempBuf        *area;
  guchar          col[MAX_CHANNELS];
  PixelRegion     blob_maskPR;

  image = gimp_item_get_image (GIMP_ITEM (drawable));

  if (! ink->last_blob)
    {
      ink->last_blob = ink_pen_ellipse (options,
                                        coords->x,
                                        coords->y,
                                        coords->pressure,
                                        coords->xtilt,
                                        coords->ytilt,
                                        100);

      if (ink->start_blob)
        g_free (ink->start_blob);

      ink->start_blob = gimp_blob_duplicate (ink->last_blob);

      blob_to_render = ink->last_blob;
    }
  else
    {
      GimpBlob *blob = ink_pen_ellipse (options,
                                        coords->x,
                                        coords->y,
                                        coords->pressure,
                                        coords->xtilt,
                                        coords->ytilt,
                                        coords->velocity * 100);

      blob_union = gimp_blob_convex_union (ink->last_blob, blob);

      g_free (ink->last_blob);
      ink->last_blob = blob;

      blob_to_render = blob_union;
    }

  /* Get the buffer */
  ink->cur_blob = blob_to_render;
  area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
                                         coords);
  ink->cur_blob = NULL;

  if (! area)
    return;

  gimp_image_get_foreground (image, context, gimp_drawable_type (drawable),
                             col);

  /*  set the alpha channel  */
  col[paint_core->canvas_buf->bytes - 1] = OPAQUE_OPACITY;

  /*  color the pixels  */
  color_pixels (temp_buf_get_data (paint_core->canvas_buf), col,
                area->width * area->height, area->bytes);

  gimp_paint_core_validate_canvas_tiles (paint_core,
                                         paint_core->canvas_buf->x,
                                         paint_core->canvas_buf->y,
                                         paint_core->canvas_buf->width,
                                         paint_core->canvas_buf->height);

  /*  draw the blob directly to the canvas_tiles  */
  pixel_region_init (&blob_maskPR, paint_core->canvas_tiles,
                     paint_core->canvas_buf->x,
                     paint_core->canvas_buf->y,
                     paint_core->canvas_buf->width,
                     paint_core->canvas_buf->height,
                     TRUE);

  render_blob (blob_to_render, &blob_maskPR);

  /*  draw the canvas_buf using the just rendered canvas_tiles as mask */
  pixel_region_init (&blob_maskPR, paint_core->canvas_tiles,
                     paint_core->canvas_buf->x,
                     paint_core->canvas_buf->y,
                     paint_core->canvas_buf->width,
                     paint_core->canvas_buf->height,
                     FALSE);

  gimp_paint_core_paste (paint_core, &blob_maskPR, drawable,
                         GIMP_OPACITY_OPAQUE,
                         gimp_context_get_opacity (context),
                         gimp_context_get_paint_mode (context),
                         GIMP_PAINT_CONSTANT);

  if (blob_union)
    g_free (blob_union);
}