resize.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "./common.h"
  2. #include "r3d.h"
  3. #include <rlgl.h>
  4. /* === Resources === */
  5. static Camera3D camera = { 0 };
  6. static R3D_Mesh sphere = { 0 };
  7. static R3D_Material materials[5] = { 0 };
  8. /* === Example === */
  9. const char* Init(void)
  10. {
  11. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  12. SetWindowState(FLAG_WINDOW_RESIZABLE);
  13. SetTargetFPS(60);
  14. sphere = R3D_GenMeshSphere(0.5f, 64, 64, true);
  15. for (int i = 0; i < 5; i++) {
  16. materials[i] = R3D_GetDefaultMaterial();
  17. materials[i].albedo.color = ColorFromHSV((float)i / 5 * 330, 1.0f, 1.0f);
  18. }
  19. camera = (Camera3D){
  20. .position = (Vector3) { 0, 2, 2 },
  21. .target = (Vector3) { 0, 0, 0 },
  22. .up = (Vector3) { 0, 1, 0 },
  23. .fovy = 60,
  24. };
  25. R3D_Light light = R3D_CreateLight(R3D_LIGHT_DIR);
  26. {
  27. R3D_SetLightDirection(light, (Vector3) { 0, 0, -1 });
  28. R3D_SetLightActive(light, true);
  29. }
  30. return "[r3d] - Resize example";
  31. }
  32. void Update(float delta)
  33. {
  34. UpdateCamera(&camera, CAMERA_ORBITAL);
  35. if (IsKeyPressed(KEY_R)) {
  36. bool keep = R3D_HasState(R3D_FLAG_ASPECT_KEEP);
  37. if (keep) R3D_ClearState(R3D_FLAG_ASPECT_KEEP);
  38. else R3D_SetState(R3D_FLAG_ASPECT_KEEP);
  39. }
  40. if (IsKeyPressed(KEY_F)) {
  41. bool linear = R3D_HasState(R3D_FLAG_BLIT_LINEAR);
  42. if (linear) R3D_ClearState(R3D_FLAG_BLIT_LINEAR);
  43. else R3D_SetState(R3D_FLAG_BLIT_LINEAR);
  44. }
  45. }
  46. void Draw(void)
  47. {
  48. bool keep = R3D_HasState(R3D_FLAG_ASPECT_KEEP);
  49. bool linear = R3D_HasState(R3D_FLAG_BLIT_LINEAR);
  50. if (keep) {
  51. ClearBackground(BLACK);
  52. }
  53. R3D_Begin(camera);
  54. rlPushMatrix();
  55. for (int i = 0; i < 5; i++) {
  56. R3D_DrawMesh(&sphere, &materials[i], MatrixTranslate(i - 2, 0, 0));
  57. }
  58. rlPopMatrix();
  59. R3D_End();
  60. DrawText(TextFormat("Resize mode: %s", keep ? "KEEP" : "EXPAND"), 10, 10, 20, BLACK);
  61. DrawText(TextFormat("Filter mode: %s", linear ? "LINEAR" : "NEAREST"), 10, 40, 20, BLACK);
  62. }
  63. void Close(void)
  64. {
  65. R3D_UnloadMesh(&sphere);
  66. R3D_Close();
  67. }