shader.c 990 B

123456789101112131415161718192021222324252627282930
  1. #include "tigr.h"
  2. #include "math.h"
  3. const char fxShader[] =
  4. "void fxShader(out vec4 color, in vec2 uv) {"
  5. " vec2 tex_size = vec2(textureSize(image, 0));"
  6. " vec4 c = texture(image, (floor(uv * tex_size) + 0.5 * sin(parameters.x)) / tex_size);"
  7. " color = c;"
  8. "}";
  9. int main(int argc, char* argv[]) {
  10. Tigr* screen = tigrWindow(320, 240, "Shady", 0);
  11. tigrSetPostShader(screen, fxShader, sizeof(fxShader) - 1);
  12. float duration = 1;
  13. float phase = 0;
  14. while (!tigrClosed(screen) && !tigrKeyDown(screen, TK_ESCAPE)) {
  15. phase += tigrTime();
  16. while (phase > duration) {
  17. phase -= duration;
  18. }
  19. float p = 6.28 * phase / duration;
  20. tigrSetPostFX(screen, p, 0, 0, 0);
  21. tigrClear(screen, tigrRGB(0x80, 0x90, 0xa0));
  22. tigrPrint(screen, tfont, 120, 110, tigrRGB(0xff, 0xff, 0xff), "Shady business");
  23. tigrUpdate(screen);
  24. }
  25. tigrFree(screen);
  26. return 0;
  27. }