resize.c 2.2 KB

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