redonion.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Draws number of really large paths, created by rasterising a photograph
  3. * (using inkscape/potrace, svgconv)
  4. *
  5. */
  6. #include "game.h"
  7. // for readability, the screen and texture sizes are hard-coded
  8. const float SCREEN_WIDTH=640.0f;
  9. const float SCREEN_HEIGHT=360.0f;
  10. const VGfloat backgroundColor[4] = { 0.9f, .83f, 0.76f, 1.0f };
  11. // defines used by svgconv
  12. typedef int HGint32;
  13. typedef unsigned int HGuint32;
  14. typedef short HGint16;
  15. typedef unsigned short HGuint16;
  16. typedef signed char HGint8;
  17. typedef unsigned char HGuint8;
  18. typedef int HGbool;
  19. #define HG_FALSE (0 == 1)
  20. #define HG_TRUE (1 == 1)
  21. #define OVG_RGB(r,g,b) ((b<<8)|(g<<16)|(r<<24)|0xff)
  22. typedef struct
  23. {
  24. const float* floats;
  25. const HGuint8* cmds;
  26. HGint32 nCommands;
  27. HGint32 nFloats;
  28. HGuint32 color;
  29. float transform[9];
  30. } PathData;
  31. #include "redonion_svg.h"
  32. #define NUM_PATHS (sizeof(_paths)/sizeof(PathData))
  33. // runtime path handles
  34. VGPath paths[NUM_PATHS];
  35. VGPaint paint;
  36. /** walltime */
  37. float t;
  38. void game_init()
  39. {
  40. }
  41. void game_destroy()
  42. {
  43. }
  44. void game_prepare()
  45. {
  46. vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_FASTER);
  47. paint = vgCreatePaint();
  48. vgSetPaint(paint, VG_FILL_PATH);
  49. vgSeti(VG_FILL_RULE, VG_NON_ZERO);
  50. for(int i=0;i<NUM_PATHS;i++)
  51. {
  52. paths[i] = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_APPEND_TO);
  53. vgAppendPathData(paths[i], _paths[i].nCommands, (VGubyte*)_paths[i].cmds, _paths[i].floats);
  54. }
  55. }
  56. void game_release()
  57. {
  58. for(int i=0;i<NUM_PATHS;i++)
  59. {
  60. vgDestroyPath(paths[i]);
  61. paths[i]=VG_INVALID_HANDLE;
  62. }
  63. vgDestroyPaint(paint);
  64. paint=VG_INVALID_HANDLE;
  65. }
  66. void game_update(float walltime)
  67. {
  68. t=walltime;
  69. }
  70. void game_render()
  71. {
  72. // clear background using black
  73. vgSetfv(VG_CLEAR_COLOR, 4, backgroundColor);
  74. vgClear(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  75. vgSetPaint(paint, VG_FILL_PATH);
  76. for(int i = 0; i < NUM_PATHS; i++)
  77. {
  78. vgSetColor(paint, _paths[i].color);
  79. vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  80. vgLoadIdentity();
  81. vgRotate(90);
  82. vgTranslate(-130*(1+sin(t*.2)),0);
  83. vgScale(1.0f, -1.0f);
  84. vgMultMatrix(_paths[i].transform);
  85. vgDrawPath(paths[i], VG_FILL_PATH);
  86. }
  87. }
  88. void game_event(int type, float x, float y, float z)
  89. {
  90. }