1#include "eglcommon.h"
2
3#include <VG/openvg.h>
4
5#include <stdio.h>
6#include <string.h>
7
8static const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0};
9
10static VGPath path;
11static VGPaint fill;
12
13
14VGfloat centeredGradient[5] = {200.0f, 200.0f, 200.0f, 200.0f, 100};
15VGfloat noncenteredGradient[5] = {200.0f, 200.0f, 250.0f, 250.0f, 100};
16VGfloat *radialGradient = centeredGradient;
17
18VGColorRampSpreadMode spread = VG_COLOR_RAMP_SPREAD_PAD;
19
20static void
21init(void)
22{
23   static const VGubyte sqrCmds[5] = {VG_MOVE_TO_ABS, VG_HLINE_TO_ABS, VG_VLINE_TO_ABS, VG_HLINE_TO_ABS, VG_CLOSE_PATH};
24   static const VGfloat sqrCoords[5]   = {0.0f, 0.0f, 400.0f, 400.0f, 0.0f};
25
26   VGfloat rampStop[] = {0.00f, 1.0f, 1.0f, 1.0f, 1.0f,
27                         0.33f, 1.0f, 0.0f, 0.0f, 1.0f,
28                         0.66f, 0.0f, 1.0f, 0.0f, 1.0f,
29                         1.00f, 0.0f, 0.0f,  1.0f, 1.0f};
30
31   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
32                       VG_PATH_CAPABILITY_APPEND_TO);
33   vgAppendPathData(path, 5, sqrCmds, sqrCoords);
34
35   fill = vgCreatePaint();
36   vgSetPaint(fill, VG_FILL_PATH);
37
38   vgSetParameteri(fill, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
39   vgSetParameteri(fill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, spread);
40   vgSetParameterfv(fill, VG_PAINT_RADIAL_GRADIENT, 5, radialGradient);
41   vgSetParameterfv(fill, VG_PAINT_COLOR_RAMP_STOPS, 20, rampStop);
42
43   vgSetfv(VG_CLEAR_COLOR, 4, white_color);
44}
45
46/* new window size or exposure */
47static void
48reshape(int w, int h)
49{
50   vgLoadIdentity();
51}
52
53static void
54draw(void)
55{
56   vgClear(0, 0, window_width(), window_height());
57
58   vgDrawPath(path, VG_FILL_PATH);
59
60   vgFlush();
61}
62
63
64int main(int argc, char **argv)
65{
66   VGint i;
67   for (i = 1; i < argc; ++i) {
68      const char *arg = argv[i];
69      if (!strcmp("-pad", arg))
70         spread = VG_COLOR_RAMP_SPREAD_PAD;
71      else if (!strcmp("-repeat", arg))
72         spread = VG_COLOR_RAMP_SPREAD_REPEAT;
73      else if (!strcmp("-reflect", arg))
74         spread = VG_COLOR_RAMP_SPREAD_REFLECT;
75      else if (!strcmp("-center", arg)) {
76         printf("Centered radial gradient\n");
77         radialGradient = centeredGradient;
78      } else if (!strcmp("-noncenter", arg)) {
79         printf("Non centered radial gradient\n");
80         radialGradient = noncenteredGradient;
81      }
82   }
83
84   switch(spread) {
85   case VG_COLOR_RAMP_SPREAD_PAD:
86      printf("Using spread mode: pad\n");
87      break;
88   case VG_COLOR_RAMP_SPREAD_REPEAT:
89      printf("Using spread mode: repeat\n");
90      break;
91   case VG_COLOR_RAMP_SPREAD_REFLECT:
92      printf("Using spread mode: reflect\n");
93   }
94
95   set_window_size(400, 400);
96
97   return run(argc, argv, init, reshape,
98              draw, 0);
99}
100