1    | /***************************************
2    |   $Header$
3    | 
4    |   This file uses Imlib2 to turn guchar arrays into Imlib images, render sets of
5    |   triangles into those images, and send back the guchar arrays.
6    |   ***************************************/
7    | 
8    | 
9    | #include "illuminator.h"
10   | 
11   | 
12   | #undef __FUNCT__
13   | #define __FUNCT__ "imlib2_render_triangles"
14   | 
15   | /*++++++++++++++++++++++++++++++++++++++
16   |   This simply takes a bunch of triangle vertex and color data and renders it
17   |   into the "data" buffer in RGBA format using Imlib2.
18   | 
19   |   int imlib2_render_triangles It returns zero or an error code.
20   | 
21   |   DATA32 *data The data buffer into which to render with
22   |   +latex+4$\times$width$\times$height
23   |   +html+ 4 x width x height
24   |   bytes.
25   | 
26   |   int width Width of the data buffer in pixels.
27   | 
28   |   int height Height of the data buffer in pixels.
29   | 
30   |   int num_triangles Number of triangles to render.
31   | 
32   |   int *triangle_coords Integer coordinates of the triangles.
33   | 
34   |   PetscScalar *triangle_colors R,G,B,A colors of the triangles between 0 and 1.
35   | 
36   |   int color_skip Number of PetscScalars to skip between color sets.
37   | 
38   |   PetscScalar *triangle_shades Shading of each triangle, zero for black to one
39   |   for normal.
40   | 
41   |   int shade_skip Number of PetscScalars to skip between shades.
42   |   ++++++++++++++++++++++++++++++++++++++*/
43   | 
44   | int imlib2_render_triangles (DATA32 *data, int width, int height,
45   | 			     int num_triangles, int *triangle_coords,
46   | 			     PetscScalar *triangle_colors, int color_skip,
47   | 			     PetscScalar *triangle_shades, int shade_skip)
48   | {
49   |   int i;
50   |   Imlib_Image myimage =
51   |     imlib_create_image_using_data (width, height, data);
52   |   imlib_context_set_image (myimage);
53   | 
54   |   for (i=0; i<num_triangles; i++)
55   |     {
56   |       ImlibPolygon polly = imlib_polygon_new ();
57   |       imlib_polygon_add_point
58   | 	(polly, triangle_coords [6*i], triangle_coords [6*i+1]);
59   |       imlib_polygon_add_point
60   | 	(polly, triangle_coords[6*i+2], triangle_coords[6*i+3]);
61   |       imlib_polygon_add_point
62   | 	(polly, triangle_coords[6*i+4], triangle_coords[6*i+5]);
63   |       imlib_context_set_color (255 * triangle_colors [color_skip*i] *
64   | 			       triangle_shades [shade_skip*i],
65   | 			       255 * triangle_colors [color_skip*i+1] *
66   | 			       triangle_shades [shade_skip*i],
67   | 			       255 * triangle_colors [color_skip*i+2] *
68   | 			       triangle_shades [shade_skip*i],
69   | 			       255 * triangle_colors [color_skip*i+3]);
70   |       imlib_image_fill_polygon (polly);
71   |       imlib_polygon_free (polly);
72   |     }
73   | 
74   |   imlib_free_image ();
75   | }