Merge remote branch 'origin/7.8'
[mesa.git] / progs / egl / openvg / trivial / stroke2.c
1 #include "eglcommon.h"
2
3 #include <VG/openvg.h>
4 #include <X11/keysym.h>
5 #include <stdio.h>
6
7 VGPaint stroke;
8 VGPath target;
9 VGPath lines;
10
11 VGfloat xform[9];
12 VGfloat color1[4];
13 VGfloat color2[4];
14 VGfloat bgCol[4];
15
16 static void
17 init(void)
18 {
19 VGubyte lineCmds[6];
20 VGfloat lineCoords[8];
21 VGfloat arcCoords[5];
22 VGubyte sccCmd[1];
23 VGubyte scCmd[1];
24 VGubyte lccCmd[1];
25 VGubyte lcCmd[1];
26 VGubyte moveCmd[1];
27 VGfloat moveCoords[2];
28 VGint i;
29
30 bgCol[0] = 1.0f;
31 bgCol[1] = 1.0f;
32 bgCol[2] = 1.0f;
33 bgCol[3] = 1.0f;
34
35 vgSetfv(VG_CLEAR_COLOR, 4, bgCol);
36 vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);
37
38 stroke = vgCreatePaint();
39 /* Red */
40 color1[0] = 1.0f;
41 color1[1] = 0.0f;
42 color1[2] = 0.0f;
43 color1[3] = 1.0f;
44
45 /* Orange */
46 color2[0] = 1.0000f;
47 color2[1] = 1.0f;
48 color2[2] = 0.0f;
49 color2[3] = 1.0f;
50 vgSetPaint(stroke, VG_STROKE_PATH);
51
52 vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE);
53
54 {
55 VGfloat temp[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
56 for (i = 0; i < 9; i++)
57 {
58 xform[i] = temp[i];
59 }
60 }
61 vgGetMatrix(xform);
62
63 target = vgCreatePath(VG_PATH_FORMAT_STANDARD,
64 VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_TRANSFORM_TO);
65
66 #if 0
67 /* Line path */
68 {
69 VGubyte temp[6] = {VG_MOVE_TO_ABS, VG_VLINE_TO_REL,
70 VG_MOVE_TO_ABS, VG_VLINE_TO_REL,
71 VG_HLINE_TO_REL, VG_VLINE_TO_REL};
72 for (i = 0; i < 6; i++)
73 {
74 lineCmds[i] = temp[i];
75 }
76 }
77 {
78 VGfloat temp[8] = {0.5f, 0.8f, -0.6f, 0.28f, 0.6f, -0.4f, 0.44f, 0.4f};
79 for (i = 0; i < 8; i++)
80 {
81 lineCoords[i] = temp[i] * window_width();
82 }
83 }
84 #else
85 {
86 VGfloat temp[5] = {0.35f, 0.15f, 29, 0.3f, 0.4f};
87 for (i = 0; i < 5; i++)
88 {
89 arcCoords[i] = temp[i] * window_width();
90 }
91 arcCoords[2] = 29;
92 }
93
94 {
95 VGubyte temp[1] = {VG_SCCWARC_TO_ABS};
96 for (i = 0; i < 1; i++)
97 {
98 sccCmd[i] = temp[i];
99 }
100 }
101 {
102 VGubyte temp[1] = {VG_SCWARC_TO_ABS};
103 for (i = 0; i < 1; i++)
104 {
105 scCmd[i] = temp[i];
106 }
107 }
108 {
109 VGubyte temp[1] = {VG_LCCWARC_TO_ABS};
110 for (i = 0; i < 1; i++)
111 {
112 lccCmd[i] = temp[i];
113 }
114 }
115 {
116 VGubyte temp[1] = {VG_LCWARC_TO_ABS};
117 for (i = 0; i < 1; i++)
118 {
119 lcCmd[i] = temp[i];
120 }
121 }
122
123 {
124 VGubyte temp[1] = {VG_MOVE_TO_ABS};
125 for (i = 0; i < 1; i++)
126 {
127 moveCmd[i] = temp[i];
128 }
129 }
130 {
131 VGfloat temp[2] = {0.7f, 0.6f};
132 for (i = 0; i < 2; i++)
133 {
134 moveCoords[i] = temp[i] * window_width();
135 }
136 }
137 #endif
138
139 lines = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1,
140 0, 0, 0,
141 VG_PATH_CAPABILITY_APPEND_TO|
142 VG_PATH_CAPABILITY_TRANSFORM_FROM);
143 #if 0
144 vgAppendPathData(lines, 6, lineCmds, lineCoords);
145 #else
146 vgAppendPathData(lines, 1, moveCmd, moveCoords);
147 vgAppendPathData(lines, 1, sccCmd, arcCoords);
148 vgAppendPathData(lines, 1, moveCmd, moveCoords);
149 vgAppendPathData(lines, 1, scCmd, arcCoords);
150 vgAppendPathData(lines, 1, moveCmd, moveCoords);
151 vgAppendPathData(lines, 1, lccCmd, arcCoords);
152 vgAppendPathData(lines, 1, moveCmd, moveCoords);
153 vgAppendPathData(lines, 1, lcCmd, arcCoords);
154 #endif
155
156 vgLoadIdentity();
157 vgTranslate(0.25f * window_width(), 0.25f * window_height());
158 vgRotate(30);
159 vgTranslate(-0.25f * window_width(), -0.25f * window_height());
160 vgTransformPath(target, lines);}
161
162 /* new window size or exposure */
163 static void
164 reshape(int w, int h)
165 {
166 }
167
168 static void
169 draw(void)
170 {
171 vgClear(0, 0, window_width(), window_height());
172 vgLoadMatrix(xform);
173 vgLoadIdentity();
174 vgTranslate(0.25f * window_width(), 0.25f * window_height());
175 vgRotate(30);
176 vgTranslate(-0.25f * window_width(), -0.25f * window_height());
177 vgSetf(VG_STROKE_LINE_WIDTH, 7);
178 vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color1);
179 vgDrawPath(lines, VG_STROKE_PATH);
180
181 vgLoadMatrix(xform);
182 vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color2);
183 vgSetf(VG_STROKE_LINE_WIDTH, 3);
184 vgDrawPath(target, VG_STROKE_PATH);
185 }
186
187 static int key_press(unsigned key)
188 {
189 switch(key) {
190 case XK_c:
191 case XK_C:
192 break;
193 case XK_j:
194 case XK_J:
195 break;
196 default:
197 break;
198 }
199
200 return VG_TRUE;
201 }
202
203 int main(int argc, char **argv)
204 {
205 return run(argc, argv, init, reshape,
206 draw, key_press);
207 }