summaryrefslogtreecommitdiff
path: root/progs/egl/openvg/trivial/stroke2.c
blob: ce950c1886c0410842f98449005e1b84aa91d497 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "eglcommon.h"

#include <VG/openvg.h>
#include <X11/keysym.h>
#include <stdio.h>

VGPaint stroke;
VGPath target;
VGPath lines;

VGfloat xform[9];
VGfloat color1[4];
VGfloat color2[4];
VGfloat bgCol[4];

static void
init(void)
{
    VGubyte lineCmds[6];
    VGfloat lineCoords[8];
    VGfloat arcCoords[5];
    VGubyte sccCmd[1];
    VGubyte scCmd[1];
    VGubyte lccCmd[1];
    VGubyte lcCmd[1];
    VGubyte moveCmd[1];
    VGfloat moveCoords[2];
    VGint i;

    bgCol[0] = 1.0f;
    bgCol[1] = 1.0f;
    bgCol[2] = 1.0f;
    bgCol[3] = 1.0f;

    vgSetfv(VG_CLEAR_COLOR, 4, bgCol);
    vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);

    stroke = vgCreatePaint();
    /* Red */
    color1[0] = 1.0f;
    color1[1] = 0.0f;
    color1[2] = 0.0f;
    color1[3] = 1.0f;

    /* Orange */
    color2[0] = 1.0000f;
    color2[1] = 1.0f;
    color2[2] = 0.0f;
    color2[3] = 1.0f;
    vgSetPaint(stroke, VG_STROKE_PATH);

    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE);

    {
        VGfloat temp[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
        for (i = 0; i < 9; i++)
        {
            xform[i] = temp[i];
        }
    }
    vgGetMatrix(xform);

    target = vgCreatePath(VG_PATH_FORMAT_STANDARD,
                          VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_TRANSFORM_TO);

#if 0
    /* Line path */
    {
        VGubyte temp[6] = {VG_MOVE_TO_ABS, VG_VLINE_TO_REL,
                           VG_MOVE_TO_ABS, VG_VLINE_TO_REL,
                           VG_HLINE_TO_REL, VG_VLINE_TO_REL};
        for (i = 0; i < 6; i++)
        {
            lineCmds[i] = temp[i];
        }
    }
    {
        VGfloat temp[8] = {0.5f, 0.8f, -0.6f, 0.28f, 0.6f, -0.4f, 0.44f, 0.4f};
        for (i = 0; i < 8; i++)
        {
            lineCoords[i] = temp[i] * window_width();
        }
    }
#else
    {
        VGfloat temp[5] = {0.35f, 0.15f, 29, 0.3f, 0.4f};
        for (i = 0; i < 5; i++)
        {
            arcCoords[i] = temp[i] * window_width();
        }
        arcCoords[2] = 29;
    }

    {
        VGubyte temp[1] = {VG_SCCWARC_TO_ABS};
        for (i = 0; i < 1; i++)
        {
            sccCmd[i] = temp[i];
        }
    }
    {
        VGubyte temp[1] = {VG_SCWARC_TO_ABS};
        for (i = 0; i < 1; i++)
        {
            scCmd[i] = temp[i];
        }
    }
    {
        VGubyte temp[1] = {VG_LCCWARC_TO_ABS};
        for (i = 0; i < 1; i++)
        {
            lccCmd[i] = temp[i];
        }
    }
    {
        VGubyte temp[1] = {VG_LCWARC_TO_ABS};
        for (i = 0; i < 1; i++)
        {
            lcCmd[i] = temp[i];
        }
    }

    {
        VGubyte temp[1] = {VG_MOVE_TO_ABS};
        for (i = 0; i < 1; i++)
        {
            moveCmd[i] = temp[i];
        }
    }
    {
        VGfloat temp[2] = {0.7f, 0.6f};
        for (i = 0; i < 2; i++)
        {
            moveCoords[i] = temp[i] * window_width();
        }
    }
#endif

    lines = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1,
                         0, 0, 0,
                         VG_PATH_CAPABILITY_APPEND_TO|
                         VG_PATH_CAPABILITY_TRANSFORM_FROM);
#if 0
    vgAppendPathData(lines, 6, lineCmds, lineCoords);
#else
    vgAppendPathData(lines, 1, moveCmd, moveCoords);
    vgAppendPathData(lines, 1, sccCmd, arcCoords);
    vgAppendPathData(lines, 1, moveCmd, moveCoords);
    vgAppendPathData(lines, 1, scCmd, arcCoords);
    vgAppendPathData(lines, 1, moveCmd, moveCoords);
    vgAppendPathData(lines, 1, lccCmd, arcCoords);
    vgAppendPathData(lines, 1, moveCmd, moveCoords);
    vgAppendPathData(lines, 1, lcCmd, arcCoords);
#endif

    vgLoadIdentity();
    vgTranslate(0.25f * window_width(), 0.25f * window_height());
    vgRotate(30);
    vgTranslate(-0.25f * window_width(), -0.25f * window_height());
    vgTransformPath(target, lines);}

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

static void
draw(void)
{
    vgClear(0, 0, window_width(), window_height());
    vgLoadMatrix(xform);
    vgLoadIdentity();
    vgTranslate(0.25f * window_width(), 0.25f * window_height());
    vgRotate(30);
    vgTranslate(-0.25f * window_width(), -0.25f * window_height());
    vgSetf(VG_STROKE_LINE_WIDTH, 7);
    vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color1);
    vgDrawPath(lines, VG_STROKE_PATH);

    vgLoadMatrix(xform);
    vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color2);
    vgSetf(VG_STROKE_LINE_WIDTH, 3);
    vgDrawPath(target, VG_STROKE_PATH);
}

static int  key_press(unsigned key)
{
    switch(key) {
    case XK_c:
    case XK_C:
        break;
    case XK_j:
    case XK_J:
        break;
    default:
        break;
    }

    return VG_TRUE;
}

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