1#include "eglcommon.h" 2 3#include <VG/openvg.h> 4 5#include <stdio.h> 6#include <string.h> 7 8static const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; 9 10static VGPath path; 11static VGPaint fill; 12 13VGColorRampSpreadMode spread = VG_COLOR_RAMP_SPREAD_PAD; 14 15static void 16init(void) 17{ 18 static const VGubyte sqrCmds[5] = {VG_MOVE_TO_ABS, VG_HLINE_TO_ABS, VG_VLINE_TO_ABS, VG_HLINE_TO_ABS, VG_CLOSE_PATH}; 19 static const VGfloat sqrCoords[5] = {0.0f, 0.0f, 400.0f, 400.0f, 0.0f}; 20 21 VGfloat rampStop[] = {0.00f, 1.0f, 1.0f, 1.0f, 1.0f, 22 0.33f, 1.0f, 0.0f, 0.0f, 1.0f, 23 0.66f, 0.0f, 1.0f, 0.0f, 1.0f, 24 1.00f, 0.0f, 0.0f, 1.0f, 1.0f}; 25 VGfloat linearGradient[4] = {100.0f, 100.0f, 300.0f, 300.0f}; 26 27 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, 28 VG_PATH_CAPABILITY_APPEND_TO); 29 vgAppendPathData(path, 5, sqrCmds, sqrCoords); 30 31 fill = vgCreatePaint(); 32 vgSetPaint(fill, VG_FILL_PATH); 33 34 vgSetParameteri(fill, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT); 35 vgSetParameteri(fill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, spread); 36 vgSetParameterfv(fill, VG_PAINT_LINEAR_GRADIENT, 4, linearGradient); 37 vgSetParameterfv(fill, VG_PAINT_COLOR_RAMP_STOPS, 20, rampStop); 38 39 vgSetfv(VG_CLEAR_COLOR, 4, white_color); 40} 41 42/* new window size or exposure */ 43static void 44reshape(int w, int h) 45{ 46 vgLoadIdentity(); 47} 48 49static void 50draw(void) 51{ 52 vgClear(0, 0, window_width(), window_height()); 53 54 vgDrawPath(path, VG_FILL_PATH); 55 56 vgFlush(); 57} 58 59 60int main(int argc, char **argv) 61{ 62 if (argc > 1) { 63 const char *arg = argv[1]; 64 if (!strcmp("-pad", arg)) 65 spread = VG_COLOR_RAMP_SPREAD_PAD; 66 else if (!strcmp("-repeat", arg)) 67 spread = VG_COLOR_RAMP_SPREAD_REPEAT; 68 else if (!strcmp("-reflect", arg)) 69 spread = VG_COLOR_RAMP_SPREAD_REFLECT; 70 } 71 72 switch(spread) { 73 case VG_COLOR_RAMP_SPREAD_PAD: 74 printf("Using spread mode: pad\n"); 75 break; 76 case VG_COLOR_RAMP_SPREAD_REPEAT: 77 printf("Using spread mode: repeat\n"); 78 break; 79 case VG_COLOR_RAMP_SPREAD_REFLECT: 80 printf("Using spread mode: reflect\n"); 81 } 82 83 set_window_size(400, 400); 84 85 return run(argc, argv, init, reshape, 86 draw, 0); 87} 88