1#include "eglcommon.h" 2 3#include <VG/openvg.h> 4 5const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; 6const VGfloat green_color[4] = {0.0, 1.0, 0.0, 0.8}; 7const VGfloat black_color[4] = {0.0, 0.0, 0.0, 1.0}; 8 9VGPath path; 10VGPaint fill; 11 12 13static void draw_point(VGfloat x, VGfloat y) 14{ 15 16 static const VGubyte cmds[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, 17 VG_LINE_TO_ABS, VG_CLOSE_PATH}; 18 const VGfloat coords[] = { x - 2, y - 2, 19 x + 2, y - 2, 20 x + 2, y + 2, 21 x - 2, y + 2}; 22 VGPath path; 23 VGPaint fill; 24 25 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, 26 VG_PATH_CAPABILITY_ALL); 27 vgAppendPathData(path, 5, cmds, coords); 28 29 fill = vgCreatePaint(); 30 vgSetParameterfv(fill, VG_PAINT_COLOR, 4, black_color); 31 vgSetPaint(fill, VG_FILL_PATH); 32 33 vgDrawPath(path, VG_FILL_PATH); 34 35 vgDestroyPath(path); 36 vgDestroyPaint(fill); 37} 38 39static void draw_marks(VGPath path) 40{ 41 VGfloat point[2], tangent[2]; 42 int i = 0; 43 44 for (i = 0; i < 1300; i += 50) { 45 vgPointAlongPath(path, 0, 6, i, 46 point + 0, point + 1, 47 tangent + 0, tangent + 1); 48 draw_point(point[0], point[1]); 49 } 50} 51 52static void 53init(void) 54{ 55 static const VGubyte cmds[6] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, 56 VG_LINE_TO_ABS, VG_CLOSE_PATH}; 57 static const VGfloat coords[] = { 0, 200, 58 300, 200, 59 50, 0, 60 150, 300, 61 250, 0}; 62 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, 63 VG_PATH_CAPABILITY_ALL); 64 vgAppendPathData(path, 6, cmds, coords); 65 66 fill = vgCreatePaint(); 67 vgSetParameterfv(fill, VG_PAINT_COLOR, 4, green_color); 68 vgSetPaint(fill, VG_FILL_PATH); 69 70 vgSetfv(VG_CLEAR_COLOR, 4, white_color); 71} 72 73/* new window size or exposure */ 74static void 75reshape(int w, int h) 76{ 77 vgLoadIdentity(); 78} 79 80static void 81draw(void) 82{ 83 VGfloat point[2], tangent[2]; 84 int i = 0; 85 86 vgClear(0, 0, window_width(), window_height()); 87 88 vgSetPaint(fill, VG_FILL_PATH); 89 vgDrawPath(path, VG_FILL_PATH); 90 91 draw_marks(path); 92 93 94 vgFlush(); 95} 96 97 98int main(int argc, char **argv) 99{ 100 return run(argc, argv, init, reshape, 101 draw, 0); 102} 103