Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 1 | #include "eglcommon.h" |
| 2 | |
| 3 | #include <VG/openvg.h> |
| 4 | #include <VG/vgu.h> |
| 5 | #include <stdio.h> |
| 6 | #include <math.h> |
| 7 | #include <stdlib.h> |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 8 | #include <string.h> |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 9 | |
| 10 | #include <X11/keysym.h> |
| 11 | |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 12 | #define ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) |
| 13 | |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 14 | struct object { |
| 15 | VGPath path; |
| 16 | VGPaint fill; |
| 17 | VGPaint stroke; |
| 18 | VGint draw_mode; |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 19 | VGfloat matrix[9]; |
| 20 | VGfloat stroke_width; |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | struct character { |
| 24 | struct object objects[32]; |
| 25 | VGint num_objects; |
| 26 | }; |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 27 | VGfloat identity_matrix[] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 28 | |
| 29 | struct character cartman; |
| 30 | |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 31 | static void add_object_fill(const VGubyte *segments, VGint num_segments, |
| 32 | const VGfloat *coords, |
| 33 | VGuint color) |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 34 | { |
| 35 | struct object object; |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 36 | |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 37 | object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, |
| 38 | 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); |
| 39 | vgAppendPathData(object.path, num_segments, segments, coords); |
| 40 | |
| 41 | object.fill = vgCreatePaint(); |
| 42 | vgSetColor(object.fill, color); |
| 43 | memcpy(object.matrix, identity_matrix, 9 * sizeof(VGfloat)); |
| 44 | object.draw_mode = VG_FILL_PATH; |
| 45 | |
| 46 | cartman.objects[cartman.num_objects] = object; |
| 47 | ++cartman.num_objects; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | static void add_object_stroke(const VGubyte *segments, VGint num_segments, |
| 52 | const VGfloat *coords, |
| 53 | VGuint color, VGfloat width) |
| 54 | { |
| 55 | struct object object; |
| 56 | |
| 57 | object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, |
| 58 | 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); |
| 59 | vgAppendPathData(object.path, num_segments, segments, coords); |
| 60 | |
| 61 | object.stroke = vgCreatePaint(); |
| 62 | vgSetColor(object.stroke, color); |
| 63 | memcpy(object.matrix, identity_matrix, 9 * sizeof(VGfloat)); |
| 64 | object.draw_mode = VG_STROKE_PATH; |
| 65 | object.stroke_width = width; |
| 66 | |
| 67 | cartman.objects[cartman.num_objects] = object; |
| 68 | ++cartman.num_objects; |
| 69 | } |
| 70 | |
| 71 | |
| 72 | static void add_object_fillm(const VGubyte *segments, VGint num_segments, |
| 73 | const VGfloat *coords, |
| 74 | VGuint color, |
| 75 | VGfloat *matrix) |
| 76 | { |
| 77 | struct object object; |
| 78 | |
| 79 | object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, |
| 80 | 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); |
| 81 | vgAppendPathData(object.path, num_segments, segments, coords); |
| 82 | |
| 83 | object.fill = vgCreatePaint(); |
| 84 | vgSetColor(object.fill, color); |
| 85 | memcpy(object.matrix, matrix, 9 * sizeof(VGfloat)); |
| 86 | object.draw_mode = VG_FILL_PATH; |
| 87 | |
| 88 | cartman.objects[cartman.num_objects] = object; |
| 89 | ++cartman.num_objects; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | static void add_object_m(const VGubyte *segments, VGint num_segments, |
| 94 | const VGfloat *coords, |
| 95 | VGuint fill_color, |
| 96 | VGuint stroke_color, VGfloat stroke_width, |
| 97 | VGfloat *matrix) |
| 98 | { |
| 99 | struct object object; |
| 100 | |
| 101 | object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, |
| 102 | 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); |
| 103 | vgAppendPathData(object.path, num_segments, segments, coords); |
| 104 | memcpy(object.matrix, matrix, 9 * sizeof(VGfloat)); |
| 105 | |
| 106 | object.fill = vgCreatePaint(); |
| 107 | vgSetColor(object.fill, fill_color); |
| 108 | object.draw_mode = VG_FILL_PATH | VG_STROKE_PATH; |
| 109 | |
| 110 | object.stroke = vgCreatePaint(); |
| 111 | vgSetColor(object.stroke, stroke_color); |
| 112 | object.stroke_width = stroke_width; |
| 113 | |
| 114 | cartman.objects[cartman.num_objects] = object; |
| 115 | ++cartman.num_objects; |
| 116 | } |
| 117 | |
| 118 | static void init_character() |
| 119 | { |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 120 | { |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 121 | const VGubyte segments[] = {VG_MOVE_TO_ABS, |
| 122 | VG_CUBIC_TO_ABS, |
| 123 | VG_CUBIC_TO_ABS, |
| 124 | VG_CUBIC_TO_ABS, |
| 125 | VG_CUBIC_TO_ABS, |
| 126 | VG_CLOSE_PATH}; |
| 127 | const VGfloat coords[] = {181.83267, 102.60408, |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 128 | 181.83267,102.60408, 185.53793,114.5749, 186.5355,115.00243, |
| 129 | 187.53306,115.42996, 286.0073,115.00243, 286.0073,115.00243, |
| 130 | 286.0073,115.00243, 292.70526,103.45914, 290.85263,101.03648, |
| 131 | 289.00001,98.61381, 181.54765,102.31906, 181.83267,102.60408 |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 132 | }; |
| 133 | VGuint color = 0x7c4e32ff; |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 134 | add_object_fill(segments, ELEMENTS(segments), |
| 135 | coords, color); |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 136 | } |
| 137 | { |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 138 | const VGubyte segments[] = { |
| 139 | VG_MOVE_TO_ABS, |
| 140 | VG_CUBIC_TO_ABS, |
| 141 | VG_CUBIC_TO_ABS, |
| 142 | VG_LINE_TO_ABS, |
| 143 | VG_CUBIC_TO_ABS, |
| 144 | VG_CUBIC_TO_ABS, |
| 145 | VG_CUBIC_TO_ABS, |
| 146 | VG_CUBIC_TO_ABS, |
| 147 | VG_CUBIC_TO_ABS, |
| 148 | VG_CUBIC_TO_ABS, |
| 149 | VG_CLOSE_PATH |
| 150 | }; |
| 151 | const VGfloat coords[] = {188.62208,50.604156, |
| 152 | 188.62208,50.604156, 176.73127,60.479579, 170.68509,69.548844, |
| 153 | 164.63892,78.618109, 175.11895,79.827344, 175.11895,79.827344, |
| 154 | 176.52973,98.368952, |
| 155 | 176.52973,98.368952, 189.83131,110.05823, 208.97754,110.25976, |
| 156 | 228.12377,110.46131, 244.24691,111.67054, 247.06846,110.25976, |
| 157 | 249.89,108.849, 258.95927,106.8336, 260.16851,105.01975, |
| 158 | 261.37774,103.2059, 296.84865,106.43053, 297.05019,91.919698, |
| 159 | 297.25172,77.408874, 306.11945,64.308824, 282.13628,51.611853, |
| 160 | 258.15311,38.914882, 189.2267,49.999539, 188.62208,50.604156 |
| 161 | }; |
| 162 | |
| 163 | VGuint color = 0xe30000ff; |
| 164 | add_object_fill(segments, ELEMENTS(segments), |
| 165 | coords, color); |
| 166 | } |
| 167 | { |
| 168 | const VGubyte segments[] = { |
| 169 | VG_MOVE_TO_ABS, |
| 170 | VG_CUBIC_TO_ABS, |
| 171 | VG_CUBIC_TO_ABS, |
| 172 | VG_CUBIC_TO_ABS, |
| 173 | VG_CUBIC_TO_ABS, |
| 174 | VG_CLOSE_PATH |
| 175 | }; |
| 176 | const VGfloat coords[] = { |
| 177 | 68.25, 78.875, |
| 178 | 68.25,93.296, 54.642,105, 37.875,105, |
| 179 | 21.108,105, 7.5,93.296, 7.5,78.875, |
| 180 | 7.5,64.454, 21.108,52.75, 37.875,52.75, |
| 181 | 54.642,52.75, 68.25,64.454, 68.25,78.875 |
| 182 | }; |
| 183 | |
| 184 | VGuint color = 0xffe1c4ff; |
| 185 | VGfloat matrix[] = { |
| 186 | 1.6529, 0, 0, |
| 187 | 0, 1.582037, 0, |
| 188 | 172.9649,-90.0116, 1 |
| 189 | }; |
| 190 | add_object_fillm(segments, ELEMENTS(segments), |
| 191 | coords, color, matrix); |
| 192 | } |
| 193 | { |
| 194 | const VGubyte segments[] = { |
| 195 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 196 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH |
| 197 | }; |
| 198 | const VGfloat coords[] = { |
| 199 | 170.14687,71.536958, |
| 200 | 173.53626,68.814326, 176.70232,68.971782, 180.55009,71.679467, |
| 201 | 184.39785,74.387153, 199.19294,80.036105, 191.52334,86.500482, |
| 202 | 189.02942,88.6025, 183.97032,85.787933, 180.26507,86.928011, |
| 203 | 178.8737,87.356121, 174.71827,89.783259, 171.8028,87.494856, |
| 204 | 166.95426,83.689139, 163.51779,76.861986, 170.14687,71.536958 |
| 205 | }; |
| 206 | |
| 207 | VGuint color = 0xfff200ff; |
| 208 | add_object_fill(segments, ELEMENTS(segments), |
| 209 | coords, color); |
| 210 | } |
| 211 | { |
| 212 | const VGubyte segments[] = { |
| 213 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 214 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 215 | VG_CUBIC_TO_ABS, VG_CLOSE_PATH |
| 216 | }; |
| 217 | const VGfloat coords[] = { |
| 218 | 299.83075,66.834136, |
| 219 | 299.83075,66.834136, 287.85993,64.69649, 284.15467,72.962055, |
| 220 | 280.44942,81.227621, 280.1644,78.234916, 280.1644,79.374994, |
| 221 | 280.1644,80.515072, 278.16927,84.077816, 284.86722,83.792796, |
| 222 | 291.56518,83.507777, 291.99271,86.785501, 294.84291,86.642991, |
| 223 | 297.6931,86.500482, 303.536,85.645423, 303.67851,80.657582, |
| 224 | 303.82102,75.66974, 302.68094,65.551548, 299.83075,66.834136 |
| 225 | }; |
| 226 | |
| 227 | VGuint color = 0xfff200ff; |
| 228 | add_object_fill(segments, ELEMENTS(segments), |
| 229 | coords, color); |
| 230 | } |
| 231 | { |
| 232 | const VGubyte segments[] = { |
| 233 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS |
| 234 | }; |
| 235 | const VGfloat coords[] = { |
| 236 | 240.83171,75.81225, |
| 237 | 240.83171,75.81225, 241.54426,88.495618, 242.25681,91.488323, |
| 238 | 242.96936,94.481028, 240.6892,108.01945, 240.83171,110.01459, |
| 239 | 240.97422,112.00973, 240.97422,111.01216, 240.97422,111.01216 |
| 240 | }; |
| 241 | VGuint color = 0x000000ff; |
| 242 | VGfloat swidth = 1.14007807; |
| 243 | add_object_stroke(segments, ELEMENTS(segments), coords, color, swidth); |
| 244 | } |
| 245 | { |
| 246 | const VGubyte segments[] = { |
| 247 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 248 | VG_CUBIC_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH |
| 249 | }; |
| 250 | const VGfloat coords[] = { |
| 251 | 83.375, 95.5, |
| 252 | 83.375,96.121, 83.067,96.625, 82.6875,96.625, |
| 253 | 82.308,96.625, 82,96.121, 82,95.5, |
| 254 | 82,94.879, 82.308,94.375, 82.6875,94.375, |
| 255 | 83.066677,94.375, 83.374492,94.878024, 83.374999,95.498494, |
| 256 | 82.6875,95.5, |
| 257 | 83.375,95.5 |
| 258 | }; |
| 259 | VGuint fill_color = 0x000000ff; |
| 260 | VGuint stroke_color = 0x000000ff; |
| 261 | VGfloat swidth = 0.60000002; |
| 262 | VGfloat matrix1[] = { |
| 263 | 1.140078, 0, 0, |
| 264 | 0, 1.140078, 0, |
| 265 | 145.4927, -15.10897, 1 |
| 266 | }; |
| 267 | VGfloat matrix2[] = { |
| 268 | 1.140078,0, 0, |
| 269 | 0,1.140078, 0, |
| 270 | 144.2814,-27.93485, 1 |
| 271 | }; |
| 272 | VGfloat matrix3[] = { |
| 273 | 1.140078,0, 0, |
| 274 | 0,1.140078, 0, |
| 275 | 144.1388,-3.70819, 1 |
| 276 | }; |
| 277 | add_object_m(segments, ELEMENTS(segments), coords, |
| 278 | fill_color, stroke_color, swidth, matrix1); |
| 279 | add_object_m(segments, ELEMENTS(segments), coords, |
| 280 | fill_color, stroke_color, swidth, matrix2); |
| 281 | add_object_m(segments, ELEMENTS(segments), coords, |
| 282 | fill_color, stroke_color, swidth, matrix3); |
| 283 | } |
| 284 | { |
| 285 | const VGubyte segments[] = { |
| 286 | VG_MOVE_TO_ABS, |
| 287 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 288 | VG_LINE_TO_ABS, VG_CLOSE_PATH |
| 289 | }; |
| 290 | const VGfloat coords[] = { |
| 291 | 179.41001,115.28745, |
| 292 | 179.41001,115.28745, 207.48443,109.30204, 236.84144,115.14494, |
| 293 | 236.84144,115.14494, 274.74903,109.87208, 291.8502,115.42996, |
| 294 | 179.41001,115.28745 |
| 295 | }; |
| 296 | |
| 297 | VGuint color = 0x000000ff; |
| 298 | add_object_fill(segments, ELEMENTS(segments), |
| 299 | coords, color); |
| 300 | } |
| 301 | { |
| 302 | const VGubyte segments[] = { |
| 303 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 304 | VG_CUBIC_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH |
| 305 | }; |
| 306 | const VGfloat coords[] = { |
| 307 | 83.792156,68.157364, |
| 308 | 83.792156,69.669865, 82.72301,70.897403, 81.40567,70.897403, |
| 309 | 80.08833,70.897403, 79.019185,69.669865, 79.019185,68.157364, |
| 310 | 79.019185,66.644862, 80.08833,65.417325, 81.40567,65.417325, |
| 311 | 82.721887,65.417325, 83.790391,66.642485, 83.792153,68.153696, |
| 312 | 81.40567,68.157364, |
| 313 | 83.792156,68.157364 |
| 314 | }; |
| 315 | VGuint fill_color = 0x000000ff; |
| 316 | VGuint stroke_color = 0x000000ff; |
| 317 | VGfloat swidth = 0.52891117; |
| 318 | VGfloat matrix1[] = { |
| 319 | 1.140078,0, 0, |
| 320 | 0,1.140078, 0, |
| 321 | 145.2489,-15.58714, 1 |
| 322 | }; |
| 323 | add_object_m(segments, ELEMENTS(segments), coords, |
| 324 | fill_color, stroke_color, swidth, matrix1); |
| 325 | } |
| 326 | { |
| 327 | const VGubyte segments[] = { |
| 328 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS |
| 329 | }; |
| 330 | const VGfloat coords[] = { |
| 331 | 232.28113,66.976646, |
| 332 | 232.28113,66.976646, 237.98152,70.539389, 245.39202,66.549116 |
| 333 | }; |
| 334 | VGuint color = 0x000000ff; |
| 335 | VGfloat swidth = 0.60299999; |
| 336 | add_object_stroke(segments, ELEMENTS(segments), coords, color, swidth); |
| 337 | } |
| 338 | { |
| 339 | const VGubyte segments[] = { |
| 340 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 341 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH |
| 342 | }; |
| 343 | const VGfloat coords[] = { |
| 344 | 185.96908,30.061986, |
| 345 | 185.96908,30.061986, 187.76995,14.508377, 203.23909,3.7427917, |
| 346 | 209.95028,-0.92779696, 219.37764,-4.9841866, 232.1078,-6.00046, |
| 347 | 246.13578,-7.1203411, 256.92106,-2.8560739, 264.81774,1.9451947, |
| 348 | 280.60485,11.543934, 284.31582,25.937274, 284.08015,26.526452, |
| 349 | 283.7266,27.410336, 240.83461,1.9346323, 185.96908,30.061986 |
| 350 | }; |
| 351 | VGuint color = 0x8ed8f8ff; |
| 352 | add_object_fill(segments, ELEMENTS(segments), coords, color); |
| 353 | } |
| 354 | { |
| 355 | const VGubyte segments[] = { |
| 356 | VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_CUBIC_TO_ABS, |
| 357 | VG_LINE_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH |
| 358 | }; |
| 359 | const VGfloat coords[] = { |
| 360 | 185.39542,32.061757, |
| 361 | 185.82295,29.211562, |
| 362 | 185.82295,29.211562, 234.70379,2.277219, 284.01217,25.078779, |
| 363 | 284.86722,27.643954, |
| 364 | 284.86722,27.643954, 236.69893,4.5573746, 185.39542,32.061757 |
| 365 | }; |
| 366 | VGuint color = 0xfff200ff; |
| 367 | add_object_fill(segments, ELEMENTS(segments), coords, color); |
| 368 | } |
| 369 | |
| 370 | { |
| 371 | const VGubyte segments[] = { |
| 372 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 373 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 374 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 375 | VG_CUBIC_TO_ABS, VG_CLOSE_PATH |
| 376 | }; |
| 377 | const VGfloat coords[] = { |
| 378 | 219.74027,-5.917093, |
| 379 | 220.49206,-8.44929, 225.15564,-10.904934, 230.21473,-11.189954, |
| 380 | 235.27383,-11.474973, 243.27521,-13.287236, 249.21385,-5.724198, |
| 381 | 249.89961,-4.850868, 249.28247,-4.332166, 248.62298,-3.971398, |
| 382 | 247.79117,-3.516361, 247.13703,-3.392737, 246.16222,-3.408047, |
| 383 | 243.63973,-3.447664, 242.54183,-3.850701, 242.54183,-3.850701, |
| 384 | 242.54183,-3.850701, 238.78367,-1.737343, 236.20014,-3.565682, |
| 385 | 233.88436,-5.204544, 234.27626,-4.56325, 234.27626,-4.56325, |
| 386 | 234.27626,-4.56325, 232.33303,-2.975658, 230.85603,-2.995643, |
| 387 | 228.59433,-3.025282, 227.73672,-4.501857, 227.21966,-4.93027, |
| 388 | 226.76318,-4.932008, 226.50948,-4.491995, 226.50948,-4.491995, |
| 389 | 226.50948,-4.491995, 224.53199,-2.085883, 222.51431,-2.467064, |
| 390 | 221.48814,-2.66093, 218.91968,-3.15318, 219.74027,-5.917093 |
| 391 | }; |
| 392 | VGuint color = 0xfff200ff; |
| 393 | add_object_fill(segments, ELEMENTS(segments), coords, color); |
| 394 | } |
| 395 | { |
| 396 | const VGubyte segments[] = { |
| 397 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 398 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH |
| 399 | }; |
| 400 | const VGfloat coords[] = { |
| 401 | 178.97347,166.06432, |
| 402 | 178.97347,181.2154, 168.0245,193.51193, 154.53381,193.51193, |
| 403 | 141.04312,193.51193, 130.09416,181.2154, 130.09416,166.06432, |
| 404 | 130.09416,150.91323, 141.04312,138.6167, 154.53381,138.6167, |
| 405 | 168.0245,138.6167, 178.97347,150.91323, 178.97347,166.06432 |
| 406 | }; |
| 407 | VGuint color = 0xffffffff; |
| 408 | VGfloat matrix1[] = { |
| 409 | 0.466614,-0.23492, 0, |
| 410 | 0.108683,0.436638, 0, |
| 411 | 134.5504,-0.901632, 1 |
| 412 | }; |
| 413 | VGfloat matrix2[] = { |
| 414 | -0.466614,-0.23492, 0, |
| 415 | -0.108683,0.436638, 0, |
| 416 | 338.4496,-0.512182, 1 |
| 417 | }; |
| 418 | add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix1); |
| 419 | add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix2); |
| 420 | } |
| 421 | { |
| 422 | const VGubyte segments[] = { |
| 423 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, |
| 424 | VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH |
| 425 | }; |
| 426 | const VGfloat coords[] = { |
| 427 | 123.82758,165.06168, |
| 428 | 123.82758,166.79125, 122.59232,168.19497, 121.07029,168.19497, |
| 429 | 119.54826,168.19497, 118.313,166.79125, 118.313,165.06168, |
| 430 | 118.313,163.3321, 119.54826,161.92839, 121.07029,161.92839, |
| 431 | 122.59232,161.92839, 123.82758,163.3321, 123.82758,165.06168 |
| 432 | }; |
| 433 | VGuint color = 0x000000ff; |
| 434 | VGfloat matrix1[] = { |
| 435 | 0.525719,0, 0, |
| 436 | 0,0.479931, 0, |
| 437 | 178.9702,-43.3532, 1 |
| 438 | }; |
| 439 | VGfloat matrix2[] = { |
| 440 | 0.525719,0, 0, |
| 441 | 0,0.479931, 0, |
| 442 | 165.258,-43.46162, 1 |
| 443 | }; |
| 444 | add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix1); |
| 445 | add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix2); |
| 446 | } |
| 447 | { |
| 448 | const VGubyte segments[] = { |
| 449 | VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS |
| 450 | }; |
| 451 | const VGfloat coords[] = { |
| 452 | 197.25,54.5, |
| 453 | 197.25,54.5, 211.75,71.5, 229.25,71.5, |
| 454 | 246.75,71.5, 261.74147,71.132714, 277.75,50.75 |
| 455 | }; |
| 456 | VGuint color = 0x000000ff; |
| 457 | VGfloat swidth = 0.60299999; |
| 458 | add_object_stroke(segments, ELEMENTS(segments), coords, color, swidth); |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | |
| 463 | static void |
| 464 | init(void) |
| 465 | { |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 466 | float clear_color[4] = {1.0, 1.0, 1.0, 1.0}; |
| 467 | vgSetfv(VG_CLEAR_COLOR, 4, clear_color); |
| 468 | |
| 469 | init_character(); |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /* new window size or exposure */ |
| 473 | static void |
| 474 | reshape(int w, int h) |
| 475 | { |
| 476 | } |
| 477 | |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 478 | static int |
| 479 | key_press(unsigned key) |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 480 | { |
| 481 | switch(key) { |
| 482 | case XK_Right: |
| 483 | |
| 484 | break; |
| 485 | case XK_Left: |
| 486 | break; |
| 487 | case XK_Up: |
| 488 | break; |
| 489 | case XK_Down: |
| 490 | break; |
| 491 | case 'a': |
| 492 | break; |
| 493 | case 's': |
| 494 | break; |
| 495 | default: |
| 496 | break; |
| 497 | } |
| 498 | return VG_FALSE; |
| 499 | } |
| 500 | |
| 501 | static void |
| 502 | draw(void) |
| 503 | { |
Zack Rusin | 54324d9 | 2009-05-01 19:08:32 -0400 | [diff] [blame] | 504 | VGint i; |
| 505 | VGfloat save_matrix[9]; |
| 506 | |
| 507 | vgClear(0, 0, window_width(), window_height()); |
| 508 | |
| 509 | vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); |
| 510 | vgLoadIdentity(); |
| 511 | vgScale(2, 2); |
| 512 | vgTranslate(160, 60); |
| 513 | vgRotate(180); |
| 514 | vgTranslate(-160, -100); |
| 515 | vgGetMatrix(save_matrix); |
| 516 | for (i = 0; i < cartman.num_objects; ++i) { |
| 517 | struct object object = cartman.objects[i]; |
| 518 | if ((object.draw_mode & VG_STROKE_PATH)) { |
| 519 | vgSetf(VG_STROKE_LINE_WIDTH, object.stroke_width); |
| 520 | vgSetPaint(object.stroke, VG_STROKE_PATH); |
| 521 | } |
| 522 | if ((object.draw_mode & VG_FILL_PATH)) |
| 523 | vgSetPaint(object.fill, VG_FILL_PATH); |
| 524 | vgMultMatrix(object.matrix); |
| 525 | vgDrawPath(object.path, object.draw_mode); |
| 526 | vgLoadMatrix(save_matrix); |
| 527 | } |
| 528 | |
| 529 | vgFlush(); |
Zack Rusin | 544dd4b | 2009-05-01 12:41:38 -0400 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | |
| 533 | int main(int argc, char **argv) |
| 534 | { |
| 535 | set_window_size(400, 400); |
| 536 | return run(argc, argv, init, reshape, draw, key_press); |
| 537 | } |