gaussian.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Testing OpenVG image filtering with built-in gaussian blur
  3. *
  4. */
  5. #include "game.h"
  6. #include <qDebug>
  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. // image resources
  11. VGImage blurred;
  12. VGImage image;
  13. /** walltime */
  14. float t;
  15. float blurX=4.0f, blurY=4.0f;
  16. void game_init()
  17. {
  18. }
  19. void game_destroy()
  20. {
  21. }
  22. void game_prepare()
  23. {
  24. image = loadVGImage("images/koski.jpg");
  25. blurred = vgCreateImage(VG_lRGBA_8888, SCREEN_WIDTH, SCREEN_HEIGHT, VG_IMAGE_QUALITY_NONANTIALIASED);
  26. }
  27. void game_release()
  28. {
  29. vgDestroyImage(blurred); blurred=VG_INVALID_HANDLE;
  30. vgDestroyImage(image); image=VG_INVALID_HANDLE;
  31. }
  32. void game_update(float walltime)
  33. {
  34. t=walltime;
  35. }
  36. void game_render()
  37. {
  38. // clear background using black
  39. VGfloat color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
  40. vgSetfv( VG_CLEAR_COLOR, 4, color );
  41. vgClear( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  42. vgGaussianBlur(blurred, image, blurX, blurY, VG_TILE_PAD);
  43. vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
  44. vgLoadIdentity();
  45. vgTranslate(0,SCREEN_HEIGHT);
  46. vgScale(1,-1);
  47. vgDrawImage(blurred);
  48. }
  49. void game_event(int type, float x, float y, float z)
  50. {
  51. blurX = x*16.0f/SCREEN_WIDTH;
  52. blurY = y*16.0f/SCREEN_HEIGHT;
  53. qDebug("blur %f, %f", blurX, blurY);
  54. }