resize.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "./common.h"
  2. #include <rlgl.h>
  3. /* === Resources === */
  4. static Model sphere = { 0 };
  5. static Camera3D camera = { 0 };
  6. static Material materials[5] = { 0 };
  7. /* === Examples === */
  8. const char* Init(void)
  9. {
  10. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  11. SetWindowState(FLAG_WINDOW_RESIZABLE);
  12. SetTargetFPS(60);
  13. sphere = LoadModelFromMesh(GenMeshSphere(0.5f, 64, 64));
  14. UnloadMaterial(sphere.materials[0]);
  15. for (int i = 0; i < 5; i++) {
  16. materials[i] = LoadMaterialDefault();
  17. materials[i].maps[MATERIAL_MAP_ALBEDO].color = ColorFromHSV((float)i / 5 * 330, 1.0f, 1.0f);
  18. materials[i].maps[MATERIAL_MAP_OCCLUSION].value = 1;
  19. materials[i].maps[MATERIAL_MAP_ROUGHNESS].value = 1;
  20. materials[i].maps[MATERIAL_MAP_METALNESS].value = 0;
  21. }
  22. camera = (Camera3D){
  23. .position = (Vector3) { 0, 2, 2 },
  24. .target = (Vector3) { 0, 0, 0 },
  25. .up = (Vector3) { 0, 1, 0 },
  26. .fovy = 60,
  27. };
  28. R3D_Light light = R3D_CreateLight(R3D_LIGHT_DIR);
  29. {
  30. R3D_SetLightDirection(light, (Vector3) { 0, 0, -1 });
  31. R3D_SetLightActive(light, true);
  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. rlPushMatrix();
  58. for (int i = 0; i < 5; i++) {
  59. sphere.materials[0] = materials[i];
  60. R3D_DrawModel(sphere, (Vector3) { i - 2, 0, 0 }, 1.0f);
  61. }
  62. rlPopMatrix();
  63. R3D_End();
  64. DrawText(TextFormat("Resize mode: %s", keep ? "KEEP" : "EXPAND"), 10, 10, 20, BLACK);
  65. DrawText(TextFormat("Filter mode: %s", linear ? "LINEAR" : "NEAREST"), 10, 40, 20, BLACK);
  66. }
  67. void Close(void)
  68. {
  69. UnloadModel(sphere);
  70. R3D_Close();
  71. }