triangleTex.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "vc.c"
  2. #include "assets/tsodinPog.c"
  3. #define WIDTH 960
  4. #define HEIGHT 720
  5. #define BACKGROUND_COLOR 0xFF181818
  6. static uint32_t pixels[WIDTH*HEIGHT];
  7. static float triangle_angle = 0;
  8. float sqrtf(float x);
  9. float atan2f(float y, float x);
  10. float sinf(float x);
  11. float cosf(float x);
  12. #define PI 3.14159265359
  13. Olivec_Canvas vc_render(float dt)
  14. {
  15. Olivec_Canvas oc = olivec_canvas(pixels, WIDTH, HEIGHT, WIDTH);
  16. Olivec_Canvas tsodinPog = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
  17. olivec_fill(oc, BACKGROUND_COLOR);
  18. // Triangle
  19. {
  20. triangle_angle += 0.5f*PI*dt;
  21. float ps[4][2];
  22. float uvs[4][2] = {
  23. {0, 0},
  24. {1, 0},
  25. {1, 1},
  26. {0, 1},
  27. };
  28. float len = WIDTH/4;
  29. for (size_t i = 0; i < 4; ++i) {
  30. ps[i][0] = WIDTH/2 + cosf(PI/2*i + triangle_angle)*len;
  31. ps[i][1] = HEIGHT/2 + sinf(PI/2*i + triangle_angle)*len;
  32. }
  33. for (size_t i = 0; i < 2; ++i) {
  34. int i1 = (i*2 + 0)%4;
  35. int i2 = (i*2 + 1)%4;
  36. int i3 = (i*2 + 2)%4;
  37. olivec_triangle3uv_bilinear(
  38. oc,
  39. ps[i1][0], ps[i1][1],
  40. ps[i2][0], ps[i2][1],
  41. ps[i3][0], ps[i3][1],
  42. uvs[i1][0], uvs[i1][1],
  43. uvs[i2][0], uvs[i2][1],
  44. uvs[i3][0], uvs[i3][1],
  45. 1, 1, 1,
  46. tsodinPog
  47. );
  48. }
  49. }
  50. return oc;
  51. }