bollworm.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Simple OpenVG example which renders a bitmap background and a string of spheres following a
  3. * sine curve.
  4. *
  5. * This code runs about 25 fps on Nokia 500 device, 60 fps on Nokia E7 device.
  6. *
  7. */
  8. #include "game.h"
  9. #include <qDebug>
  10. // for readability, the screen and texture sizes are hard-coded
  11. const float BACKGROUND_WIDTH=1024;
  12. const float BALL_WIDTH=128.0f;
  13. const float BALL_HEIGHT=128.0f;
  14. const float SCREEN_WIDTH=640.0f;
  15. const float SCREEN_HEIGHT=360.0f;
  16. const float BACKGROUND_SCROLL_SPEED=50.0f;
  17. const float BALL_PHASE=0.0111f;
  18. const float BALL_SCALE=120.0f;
  19. // image resources
  20. VGImage ball;
  21. VGImage bg;
  22. /** walltime */
  23. float t;
  24. void game_init()
  25. {
  26. }
  27. void game_destroy()
  28. {
  29. }
  30. void game_prepare()
  31. {
  32. vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);
  33. vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_BETTER);
  34. ball = loadVGImage("images/planet.png");
  35. bg = loadVGImage("images/orange_bg_mountain.png");
  36. }
  37. void game_release()
  38. {
  39. vgDestroyImage(ball); ball=VG_INVALID_HANDLE;
  40. vgDestroyImage(bg); bg=VG_INVALID_HANDLE;
  41. }
  42. void game_update(float walltime)
  43. {
  44. t=walltime;
  45. }
  46. void game_render()
  47. {
  48. // clear background using black
  49. VGfloat color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
  50. vgSetfv( VG_CLEAR_COLOR, 4, color );
  51. vgClear( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  52. // render scrolling background bitmap (twice for looping effect)
  53. vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
  54. vgLoadIdentity();
  55. vgTranslate(-fmod(t*BACKGROUND_SCROLL_SPEED,BACKGROUND_WIDTH), 0);
  56. vgDrawImage(bg);
  57. vgTranslate(BACKGROUND_WIDTH, 0);
  58. vgDrawImage(bg);
  59. // render sine spheres
  60. for(int i=-BALL_WIDTH/2;i<SCREEN_WIDTH+BALL_WIDTH/2;i+=BALL_WIDTH/4)
  61. {
  62. vgLoadIdentity();
  63. vgTranslate(i, (SCREEN_HEIGHT-BALL_HEIGHT)/2+sin(t+i*BALL_PHASE)*BALL_SCALE);
  64. vgDrawImage(ball);
  65. }
  66. }
  67. void game_event(int type, float x, float y, float z)
  68. {
  69. }