summaryrefslogtreecommitdiff
path: root/progs/egl/openvg/trivial/star-oddeven.c
blob: 17311cf720aab756c67211e4abd52bae5be1314e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "eglcommon.h"

#include <VG/openvg.h>

const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0};
const VGfloat green_color[4] = {0.0, 1.0, 0.0, 0.8};
const VGfloat black_color[4] = {0.0, 0.0, 0.0, 1.0};

VGPath path;
VGPaint fill;


static void draw_point(VGfloat x, VGfloat y)
{

   static const VGubyte cmds[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS,
                                  VG_LINE_TO_ABS, VG_CLOSE_PATH};
   const VGfloat coords[]   = {  x - 2,  y - 2,
                                 x + 2,  y - 2,
                                 x + 2,  y + 2,
                                 x - 2,  y + 2};
   VGPath path;
   VGPaint fill;

   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
                       VG_PATH_CAPABILITY_ALL);
   vgAppendPathData(path, 5, cmds, coords);

   fill = vgCreatePaint();
   vgSetParameterfv(fill, VG_PAINT_COLOR, 4, black_color);
   vgSetPaint(fill, VG_FILL_PATH);

   vgDrawPath(path, VG_FILL_PATH);

   vgDestroyPath(path);
   vgDestroyPaint(fill);
}

static void draw_marks(VGPath path)
{
    VGfloat point[2], tangent[2];
    int i = 0;

    for (i = 0; i < 1300; i += 50) {
        vgPointAlongPath(path, 0, 6, i,
                         point + 0, point + 1,
                         tangent + 0, tangent + 1);
        draw_point(point[0], point[1]);
    }
}

static void
init(void)
{
   static const VGubyte cmds[6] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS,
                                   VG_LINE_TO_ABS, VG_CLOSE_PATH};
   static const VGfloat coords[]   = {  0,  200,
                                        300,  200,
                                        50,   0,
                                        150, 300,
                                        250,   0};
   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
                       VG_PATH_CAPABILITY_ALL);
   vgAppendPathData(path, 6, cmds, coords);

   fill = vgCreatePaint();
   vgSetParameterfv(fill, VG_PAINT_COLOR, 4, green_color);
   vgSetPaint(fill, VG_FILL_PATH);

   vgSetfv(VG_CLEAR_COLOR, 4, white_color);
}

/* new window size or exposure */
static void
reshape(int w, int h)
{
   vgLoadIdentity();
}

static void
draw(void)
{
    VGfloat point[2], tangent[2];
    int i = 0;

    vgClear(0, 0, window_width(), window_height());

    vgSetPaint(fill, VG_FILL_PATH);
    vgDrawPath(path, VG_FILL_PATH);

    draw_marks(path);


    vgFlush();
}


int main(int argc, char **argv)
{
   return run(argc, argv, init, reshape,
              draw, 0);
}