resize.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <r3d/r3d.h>
  2. #include <raymath.h>
  3. int main(void)
  4. {
  5. // Initialize window
  6. InitWindow(800, 450, "[r3d] - Resize example");
  7. SetWindowState(FLAG_WINDOW_RESIZABLE);
  8. SetTargetFPS(60);
  9. // Initialize R3D
  10. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  11. // Create sphere mesh and materials
  12. R3D_Mesh sphere = R3D_GenMeshSphere(0.5f, 64, 64);
  13. R3D_Material materials[5];
  14. for (int i = 0; i < 5; i++)
  15. {
  16. materials[i] = R3D_GetDefaultMaterial();
  17. materials[i].albedo.color = ColorFromHSV((float)i / 5 * 330, 1.0f, 1.0f);
  18. }
  19. // Setup directional light
  20. R3D_Light light = R3D_CreateLight(R3D_LIGHT_DIR);
  21. R3D_SetLightDirection(light, (Vector3){0, 0, -1});
  22. R3D_SetLightActive(light, true);
  23. // Setup camera
  24. Camera3D camera = {
  25. .position = {0, 2, 2},
  26. .target = {0, 0, 0},
  27. .up = {0, 1, 0},
  28. .fovy = 60
  29. };
  30. // Main loop
  31. while (!WindowShouldClose())
  32. {
  33. UpdateCamera(&camera, CAMERA_ORBITAL);
  34. // Toggle aspect keep
  35. if (IsKeyPressed(KEY_R)) {
  36. if (R3D_HasState(R3D_FLAG_ASPECT_KEEP)) R3D_ClearState(R3D_FLAG_ASPECT_KEEP);
  37. else R3D_SetState(R3D_FLAG_ASPECT_KEEP);
  38. }
  39. // Toggle linear filtering
  40. if (IsKeyPressed(KEY_F)) {
  41. if (R3D_HasState(R3D_FLAG_BLIT_LINEAR)) R3D_ClearState(R3D_FLAG_BLIT_LINEAR);
  42. else R3D_SetState(R3D_FLAG_BLIT_LINEAR);
  43. }
  44. BeginDrawing();
  45. ClearBackground(BLACK);
  46. // Draw spheres
  47. R3D_Begin(camera);
  48. for (int i = 0; i < 5; i++) {
  49. R3D_DrawMesh(&sphere, &materials[i], MatrixTranslate((float)i - 2, 0, 0));
  50. }
  51. R3D_End();
  52. // Draw info
  53. bool keep = R3D_HasState(R3D_FLAG_ASPECT_KEEP);
  54. bool linear = R3D_HasState(R3D_FLAG_BLIT_LINEAR);
  55. DrawText(TextFormat("Resize mode: %s", keep ? "KEEP" : "EXPAND"), 10, 10, 20, RAYWHITE);
  56. DrawText(TextFormat("Filter mode: %s", linear ? "LINEAR" : "NEAREST"), 10, 40, 20, RAYWHITE);
  57. EndDrawing();
  58. }
  59. // Cleanup
  60. R3D_UnloadMesh(&sphere);
  61. R3D_Close();
  62. CloseWindow();
  63. return 0;
  64. }