132001f49Smrg#include "eglcommon.h"
232001f49Smrg
332001f49Smrg#include <VG/openvg.h>
432001f49Smrg#include <X11/keysym.h>
532001f49Smrg#include <stdio.h>
632001f49Smrg
732001f49SmrgVGPaint stroke;
832001f49SmrgVGPath target;
932001f49SmrgVGPath lines;
1032001f49Smrg
1132001f49SmrgVGfloat xform[9];
1232001f49SmrgVGfloat color1[4];
1332001f49SmrgVGfloat color2[4];
1432001f49SmrgVGfloat bgCol[4];
1532001f49Smrg
1632001f49Smrgstatic void
1732001f49Smrginit(void)
1832001f49Smrg{
1932001f49Smrg    VGubyte lineCmds[6];
2032001f49Smrg    VGfloat lineCoords[8];
2132001f49Smrg    VGfloat arcCoords[5];
2232001f49Smrg    VGubyte sccCmd[1];
2332001f49Smrg    VGubyte scCmd[1];
2432001f49Smrg    VGubyte lccCmd[1];
2532001f49Smrg    VGubyte lcCmd[1];
2632001f49Smrg    VGubyte moveCmd[1];
2732001f49Smrg    VGfloat moveCoords[2];
2832001f49Smrg    VGint i;
2932001f49Smrg
3032001f49Smrg    bgCol[0] = 1.0f;
3132001f49Smrg    bgCol[1] = 1.0f;
3232001f49Smrg    bgCol[2] = 1.0f;
3332001f49Smrg    bgCol[3] = 1.0f;
3432001f49Smrg
3532001f49Smrg    vgSetfv(VG_CLEAR_COLOR, 4, bgCol);
3632001f49Smrg    vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);
3732001f49Smrg
3832001f49Smrg    stroke = vgCreatePaint();
3932001f49Smrg    /* Red */
4032001f49Smrg    color1[0] = 1.0f;
4132001f49Smrg    color1[1] = 0.0f;
4232001f49Smrg    color1[2] = 0.0f;
4332001f49Smrg    color1[3] = 1.0f;
4432001f49Smrg
4532001f49Smrg    /* Orange */
4632001f49Smrg    color2[0] = 1.0000f;
4732001f49Smrg    color2[1] = 1.0f;
4832001f49Smrg    color2[2] = 0.0f;
4932001f49Smrg    color2[3] = 1.0f;
5032001f49Smrg    vgSetPaint(stroke, VG_STROKE_PATH);
5132001f49Smrg
5232001f49Smrg    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE);
5332001f49Smrg
5432001f49Smrg    {
5532001f49Smrg        VGfloat temp[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
5632001f49Smrg        for (i = 0; i < 9; i++)
5732001f49Smrg        {
5832001f49Smrg            xform[i] = temp[i];
5932001f49Smrg        }
6032001f49Smrg    }
6132001f49Smrg    vgGetMatrix(xform);
6232001f49Smrg
6332001f49Smrg    target = vgCreatePath(VG_PATH_FORMAT_STANDARD,
6432001f49Smrg                          VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_TRANSFORM_TO);
6532001f49Smrg
6632001f49Smrg#if 0
6732001f49Smrg    /* Line path */
6832001f49Smrg    {
6932001f49Smrg        VGubyte temp[6] = {VG_MOVE_TO_ABS, VG_VLINE_TO_REL,
7032001f49Smrg                           VG_MOVE_TO_ABS, VG_VLINE_TO_REL,
7132001f49Smrg                           VG_HLINE_TO_REL, VG_VLINE_TO_REL};
7232001f49Smrg        for (i = 0; i < 6; i++)
7332001f49Smrg        {
7432001f49Smrg            lineCmds[i] = temp[i];
7532001f49Smrg        }
7632001f49Smrg    }
7732001f49Smrg    {
7832001f49Smrg        VGfloat temp[8] = {0.5f, 0.8f, -0.6f, 0.28f, 0.6f, -0.4f, 0.44f, 0.4f};
7932001f49Smrg        for (i = 0; i < 8; i++)
8032001f49Smrg        {
8132001f49Smrg            lineCoords[i] = temp[i] * window_width();
8232001f49Smrg        }
8332001f49Smrg    }
8432001f49Smrg#else
8532001f49Smrg    {
8632001f49Smrg        VGfloat temp[5] = {0.35f, 0.15f, 29, 0.3f, 0.4f};
8732001f49Smrg        for (i = 0; i < 5; i++)
8832001f49Smrg        {
8932001f49Smrg            arcCoords[i] = temp[i] * window_width();
9032001f49Smrg        }
9132001f49Smrg        arcCoords[2] = 29;
9232001f49Smrg    }
9332001f49Smrg
9432001f49Smrg    {
9532001f49Smrg        VGubyte temp[1] = {VG_SCCWARC_TO_ABS};
9632001f49Smrg        for (i = 0; i < 1; i++)
9732001f49Smrg        {
9832001f49Smrg            sccCmd[i] = temp[i];
9932001f49Smrg        }
10032001f49Smrg    }
10132001f49Smrg    {
10232001f49Smrg        VGubyte temp[1] = {VG_SCWARC_TO_ABS};
10332001f49Smrg        for (i = 0; i < 1; i++)
10432001f49Smrg        {
10532001f49Smrg            scCmd[i] = temp[i];
10632001f49Smrg        }
10732001f49Smrg    }
10832001f49Smrg    {
10932001f49Smrg        VGubyte temp[1] = {VG_LCCWARC_TO_ABS};
11032001f49Smrg        for (i = 0; i < 1; i++)
11132001f49Smrg        {
11232001f49Smrg            lccCmd[i] = temp[i];
11332001f49Smrg        }
11432001f49Smrg    }
11532001f49Smrg    {
11632001f49Smrg        VGubyte temp[1] = {VG_LCWARC_TO_ABS};
11732001f49Smrg        for (i = 0; i < 1; i++)
11832001f49Smrg        {
11932001f49Smrg            lcCmd[i] = temp[i];
12032001f49Smrg        }
12132001f49Smrg    }
12232001f49Smrg
12332001f49Smrg    {
12432001f49Smrg        VGubyte temp[1] = {VG_MOVE_TO_ABS};
12532001f49Smrg        for (i = 0; i < 1; i++)
12632001f49Smrg        {
12732001f49Smrg            moveCmd[i] = temp[i];
12832001f49Smrg        }
12932001f49Smrg    }
13032001f49Smrg    {
13132001f49Smrg        VGfloat temp[2] = {0.7f, 0.6f};
13232001f49Smrg        for (i = 0; i < 2; i++)
13332001f49Smrg        {
13432001f49Smrg            moveCoords[i] = temp[i] * window_width();
13532001f49Smrg        }
13632001f49Smrg    }
13732001f49Smrg#endif
13832001f49Smrg
13932001f49Smrg    lines = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1,
14032001f49Smrg                         0, 0, 0,
14132001f49Smrg                         VG_PATH_CAPABILITY_APPEND_TO|
14232001f49Smrg                         VG_PATH_CAPABILITY_TRANSFORM_FROM);
14332001f49Smrg#if 0
14432001f49Smrg    vgAppendPathData(lines, 6, lineCmds, lineCoords);
14532001f49Smrg#else
14632001f49Smrg    vgAppendPathData(lines, 1, moveCmd, moveCoords);
14732001f49Smrg    vgAppendPathData(lines, 1, sccCmd, arcCoords);
14832001f49Smrg    vgAppendPathData(lines, 1, moveCmd, moveCoords);
14932001f49Smrg    vgAppendPathData(lines, 1, scCmd, arcCoords);
15032001f49Smrg    vgAppendPathData(lines, 1, moveCmd, moveCoords);
15132001f49Smrg    vgAppendPathData(lines, 1, lccCmd, arcCoords);
15232001f49Smrg    vgAppendPathData(lines, 1, moveCmd, moveCoords);
15332001f49Smrg    vgAppendPathData(lines, 1, lcCmd, arcCoords);
15432001f49Smrg#endif
15532001f49Smrg
15632001f49Smrg    vgLoadIdentity();
15732001f49Smrg    vgTranslate(0.25f * window_width(), 0.25f * window_height());
15832001f49Smrg    vgRotate(30);
15932001f49Smrg    vgTranslate(-0.25f * window_width(), -0.25f * window_height());
16032001f49Smrg    vgTransformPath(target, lines);}
16132001f49Smrg
16232001f49Smrg/* new window size or exposure */
16332001f49Smrgstatic void
16432001f49Smrgreshape(int w, int h)
16532001f49Smrg{
16632001f49Smrg}
16732001f49Smrg
16832001f49Smrgstatic void
16932001f49Smrgdraw(void)
17032001f49Smrg{
17132001f49Smrg    vgClear(0, 0, window_width(), window_height());
17232001f49Smrg    vgLoadMatrix(xform);
17332001f49Smrg    vgLoadIdentity();
17432001f49Smrg    vgTranslate(0.25f * window_width(), 0.25f * window_height());
17532001f49Smrg    vgRotate(30);
17632001f49Smrg    vgTranslate(-0.25f * window_width(), -0.25f * window_height());
17732001f49Smrg    vgSetf(VG_STROKE_LINE_WIDTH, 7);
17832001f49Smrg    vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color1);
17932001f49Smrg    vgDrawPath(lines, VG_STROKE_PATH);
18032001f49Smrg
18132001f49Smrg    vgLoadMatrix(xform);
18232001f49Smrg    vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color2);
18332001f49Smrg    vgSetf(VG_STROKE_LINE_WIDTH, 3);
18432001f49Smrg    vgDrawPath(target, VG_STROKE_PATH);
18532001f49Smrg}
18632001f49Smrg
18732001f49Smrgstatic int  key_press(unsigned key)
18832001f49Smrg{
18932001f49Smrg    switch(key) {
19032001f49Smrg    case XK_c:
19132001f49Smrg    case XK_C:
19232001f49Smrg        break;
19332001f49Smrg    case XK_j:
19432001f49Smrg    case XK_J:
19532001f49Smrg        break;
19632001f49Smrg    default:
19732001f49Smrg        break;
19832001f49Smrg    }
19932001f49Smrg
20032001f49Smrg    return VG_TRUE;
20132001f49Smrg}
20232001f49Smrg
20332001f49Smrgint main(int argc, char **argv)
20432001f49Smrg{
20532001f49Smrg   return run(argc, argv, init, reshape,
20632001f49Smrg              draw, key_press);
20732001f49Smrg}
208