1#include "eglcommon.h"
2
3#include <VG/openvg.h>
4#include <math.h>
5
6const VGfloat clear_color[4] = {1.0, 1.0, 1.0, 1.0};
7const VGfloat color[4] = {1.0, 1.0, 1.0, 0.5};
8
9VGPath vgPath;
10
11static void ellipse(VGPath vgPath, VGfloat rx, VGfloat ry, VGfloat angle)
12{
13    static const VGubyte cmd[] =
14    { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH };
15
16    VGfloat val[12];
17    VGfloat c = cos(angle) * rx;
18    VGfloat s = sin(angle) * rx;
19
20    val[0] = c;
21    val[1] = s;
22    val[2] = rx;
23    val[3] = ry;
24    val[4] = angle;
25    val[5] = -2.0f * c;
26    val[6] = -2.0f * s;
27    val[7] = rx;
28    val[8] = ry;
29    val[9] = angle;
30    val[10] = 2.0f * c;
31    val[11] = 2.0f * s;
32
33    vgClearPath(vgPath, VG_PATH_CAPABILITY_ALL);
34    vgAppendPathData(vgPath, sizeof(cmd), cmd, val);
35    vgDrawPath(vgPath, VG_FILL_PATH | VG_STROKE_PATH);
36}
37
38static void
39init(void)
40{
41    VGPaint vgPaint;
42
43    vgSetfv(VG_CLEAR_COLOR, 4, clear_color);
44    vgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
45                          VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0,
46                          VG_PATH_CAPABILITY_ALL);
47
48    vgPaint = vgCreatePaint();
49    vgSetParameteri(vgPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
50    vgSetColor(vgPaint, 0x00ff00ff);
51    vgSetPaint(vgPaint, VG_FILL_PATH);
52
53    vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);
54    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
55    vgSetf(VG_STROKE_LINE_WIDTH, 2.0f);
56    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE);
57    vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_MITER);
58    vgSetf(VG_STROKE_MITER_LIMIT, 4.0f);
59    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
60}
61
62/* new window size or exposure */
63static void
64reshape(int w, int h)
65{
66}
67
68static void
69draw(void)
70{
71    vgClear(0, 0, window_width(), window_height());
72
73#if 0
74    vgLoadIdentity();
75    vgTranslate(40.0f, 24.0f);
76    vgScale(0.61804f, 0.61804f);
77    vgShear(-1.0f, 0.0f);
78    vgDrawPath(vgPath, VG_FILL_PATH | VG_STROKE_PATH);
79#else
80
81    /* row 1, col 1: Identity transform. */
82
83    vgLoadIdentity();
84    vgTranslate(8.0f, 8.0f);
85    ellipse(vgPath, 4.0f, 4.0f, 0.0f);
86
87    /* row 1, col 2: 10^3 horizontal squeeze. */
88
89    vgLoadIdentity();
90    vgTranslate(24.0f, 8.0f);
91    vgScale(1.0e-3f, 1.0f);
92    ellipse(vgPath, 4.0e3f, 4.0f, 0.0f);
93
94    /* row 1, col 3: 10^6 horizontal squeeze. */
95
96    vgLoadIdentity();
97    vgTranslate(40.0f, 8.0f);
98    vgScale(1.0e-6f, 1.0f);
99    ellipse(vgPath, 4.0e6f, 4.0f, 0.0f);
100
101    /* row 1, col 4: 10^9 horizontal squeeze. */
102
103    vgLoadIdentity();
104    vgTranslate(56.0f, 8.0f);
105    vgScale(1.0e-9f, 1.0f);
106    ellipse(vgPath, 4.0e9f, 4.0f, 0.0f);
107
108    /* row 2, col 1: 10^3 vertical squeeze. */
109
110    vgLoadIdentity();
111    vgTranslate(8.0f, 24.0f);
112    vgScale(1.0f, 1.0e-3f);
113    ellipse(vgPath, 4.0f, 4.0e3f, 0.0f);
114
115    /* row 2, col 2: Shear 0. */
116
117    vgLoadIdentity();
118    vgTranslate(24.0f, 24.0f);
119    vgShear(0.0f, 0.0f);
120    ellipse(vgPath, 4.0f, 4.0f, 0.0f);
121
122    /* row 2, col 3: Horizontal shear -1. */
123
124    vgLoadIdentity();
125    vgTranslate(40.0f, 24.0f);
126    vgScale(0.61804f, 0.61804f);
127    vgShear(-1.0f, 0.0f);
128    ellipse(vgPath, 10.47213f, 4.0f, 31.717f);
129#endif
130    vgFlush();
131}
132
133
134int main(int argc, char **argv)
135{
136    set_window_size(64, 64);
137   return run(argc, argv, init, reshape,
138              draw, 0);
139}
140