132001f49Smrg#include "eglcommon.h"
232001f49Smrg
332001f49Smrg#include <VG/openvg.h>
432001f49Smrg#include <math.h>
532001f49Smrg
632001f49Smrgconst VGfloat clear_color[4] = {1.0, 1.0, 1.0, 1.0};
732001f49Smrgconst VGfloat color[4] = {1.0, 1.0, 1.0, 0.5};
832001f49Smrg
932001f49SmrgVGPath vgPath;
1032001f49Smrg
1132001f49Smrgstatic void ellipse(VGPath vgPath, VGfloat rx, VGfloat ry, VGfloat angle)
1232001f49Smrg{
1332001f49Smrg    static const VGubyte cmd[] =
1432001f49Smrg    { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH };
1532001f49Smrg
1632001f49Smrg    VGfloat val[12];
1732001f49Smrg    VGfloat c = cos(angle) * rx;
1832001f49Smrg    VGfloat s = sin(angle) * rx;
1932001f49Smrg
2032001f49Smrg    val[0] = c;
2132001f49Smrg    val[1] = s;
2232001f49Smrg    val[2] = rx;
2332001f49Smrg    val[3] = ry;
2432001f49Smrg    val[4] = angle;
2532001f49Smrg    val[5] = -2.0f * c;
2632001f49Smrg    val[6] = -2.0f * s;
2732001f49Smrg    val[7] = rx;
2832001f49Smrg    val[8] = ry;
2932001f49Smrg    val[9] = angle;
3032001f49Smrg    val[10] = 2.0f * c;
3132001f49Smrg    val[11] = 2.0f * s;
3232001f49Smrg
3332001f49Smrg    vgClearPath(vgPath, VG_PATH_CAPABILITY_ALL);
3432001f49Smrg    vgAppendPathData(vgPath, sizeof(cmd), cmd, val);
3532001f49Smrg    vgDrawPath(vgPath, VG_FILL_PATH | VG_STROKE_PATH);
3632001f49Smrg}
3732001f49Smrg
3832001f49Smrgstatic void
3932001f49Smrginit(void)
4032001f49Smrg{
4132001f49Smrg    VGPaint vgPaint;
4232001f49Smrg
4332001f49Smrg    vgSetfv(VG_CLEAR_COLOR, 4, clear_color);
4432001f49Smrg    vgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
4532001f49Smrg                          VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0,
4632001f49Smrg                          VG_PATH_CAPABILITY_ALL);
4732001f49Smrg
4832001f49Smrg    vgPaint = vgCreatePaint();
4932001f49Smrg    vgSetParameteri(vgPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
5032001f49Smrg    vgSetColor(vgPaint, 0x00ff00ff);
5132001f49Smrg    vgSetPaint(vgPaint, VG_FILL_PATH);
5232001f49Smrg
5332001f49Smrg    vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);
5432001f49Smrg    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
5532001f49Smrg    vgSetf(VG_STROKE_LINE_WIDTH, 2.0f);
5632001f49Smrg    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE);
5732001f49Smrg    vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_MITER);
5832001f49Smrg    vgSetf(VG_STROKE_MITER_LIMIT, 4.0f);
5932001f49Smrg    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
6032001f49Smrg}
6132001f49Smrg
6232001f49Smrg/* new window size or exposure */
6332001f49Smrgstatic void
6432001f49Smrgreshape(int w, int h)
6532001f49Smrg{
6632001f49Smrg}
6732001f49Smrg
6832001f49Smrgstatic void
6932001f49Smrgdraw(void)
7032001f49Smrg{
7132001f49Smrg    vgClear(0, 0, window_width(), window_height());
7232001f49Smrg
7332001f49Smrg#if 0
7432001f49Smrg    vgLoadIdentity();
7532001f49Smrg    vgTranslate(40.0f, 24.0f);
7632001f49Smrg    vgScale(0.61804f, 0.61804f);
7732001f49Smrg    vgShear(-1.0f, 0.0f);
7832001f49Smrg    vgDrawPath(vgPath, VG_FILL_PATH | VG_STROKE_PATH);
7932001f49Smrg#else
8032001f49Smrg
8132001f49Smrg    /* row 1, col 1: Identity transform. */
8232001f49Smrg
8332001f49Smrg    vgLoadIdentity();
8432001f49Smrg    vgTranslate(8.0f, 8.0f);
8532001f49Smrg    ellipse(vgPath, 4.0f, 4.0f, 0.0f);
8632001f49Smrg
8732001f49Smrg    /* row 1, col 2: 10^3 horizontal squeeze. */
8832001f49Smrg
8932001f49Smrg    vgLoadIdentity();
9032001f49Smrg    vgTranslate(24.0f, 8.0f);
9132001f49Smrg    vgScale(1.0e-3f, 1.0f);
9232001f49Smrg    ellipse(vgPath, 4.0e3f, 4.0f, 0.0f);
9332001f49Smrg
9432001f49Smrg    /* row 1, col 3: 10^6 horizontal squeeze. */
9532001f49Smrg
9632001f49Smrg    vgLoadIdentity();
9732001f49Smrg    vgTranslate(40.0f, 8.0f);
9832001f49Smrg    vgScale(1.0e-6f, 1.0f);
9932001f49Smrg    ellipse(vgPath, 4.0e6f, 4.0f, 0.0f);
10032001f49Smrg
10132001f49Smrg    /* row 1, col 4: 10^9 horizontal squeeze. */
10232001f49Smrg
10332001f49Smrg    vgLoadIdentity();
10432001f49Smrg    vgTranslate(56.0f, 8.0f);
10532001f49Smrg    vgScale(1.0e-9f, 1.0f);
10632001f49Smrg    ellipse(vgPath, 4.0e9f, 4.0f, 0.0f);
10732001f49Smrg
10832001f49Smrg    /* row 2, col 1: 10^3 vertical squeeze. */
10932001f49Smrg
11032001f49Smrg    vgLoadIdentity();
11132001f49Smrg    vgTranslate(8.0f, 24.0f);
11232001f49Smrg    vgScale(1.0f, 1.0e-3f);
11332001f49Smrg    ellipse(vgPath, 4.0f, 4.0e3f, 0.0f);
11432001f49Smrg
11532001f49Smrg    /* row 2, col 2: Shear 0. */
11632001f49Smrg
11732001f49Smrg    vgLoadIdentity();
11832001f49Smrg    vgTranslate(24.0f, 24.0f);
11932001f49Smrg    vgShear(0.0f, 0.0f);
12032001f49Smrg    ellipse(vgPath, 4.0f, 4.0f, 0.0f);
12132001f49Smrg
12232001f49Smrg    /* row 2, col 3: Horizontal shear -1. */
12332001f49Smrg
12432001f49Smrg    vgLoadIdentity();
12532001f49Smrg    vgTranslate(40.0f, 24.0f);
12632001f49Smrg    vgScale(0.61804f, 0.61804f);
12732001f49Smrg    vgShear(-1.0f, 0.0f);
12832001f49Smrg    ellipse(vgPath, 10.47213f, 4.0f, 31.717f);
12932001f49Smrg#endif
13032001f49Smrg    vgFlush();
13132001f49Smrg}
13232001f49Smrg
13332001f49Smrg
13432001f49Smrgint main(int argc, char **argv)
13532001f49Smrg{
13632001f49Smrg    set_window_size(64, 64);
13732001f49Smrg   return run(argc, argv, init, reshape,
13832001f49Smrg              draw, 0);
13932001f49Smrg}
140