skybox.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "./common.h"
  2. #include "r3d.h"
  3. /* === Resources === */
  4. static R3D_Mesh sphere = { 0 };
  5. static R3D_Skybox skybox = { 0 };
  6. static Camera3D camera = { 0 };
  7. static R3D_Material materials[7 * 7] = { 0 };
  8. /* === Examples === */
  9. const char* Init(void)
  10. {
  11. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  12. SetTargetFPS(60);
  13. sphere = R3D_GenMeshSphere(0.5f, 64, 64, true);
  14. for (int x = 0; x < 7; x++) {
  15. for (int y = 0; y < 7; y++) {
  16. int i = y * 7 + x;
  17. materials[i] = R3D_GetDefaultMaterial();
  18. materials[i].orm.metalness = (float)x / 7;
  19. materials[i].orm.roughness = (float)y / 7;
  20. materials[i].albedo.color = ColorFromHSV(((float)x/7) * 360, 1, 1);
  21. }
  22. }
  23. skybox = R3D_LoadSkybox(RESOURCES_PATH "sky/skybox1.png", CUBEMAP_LAYOUT_AUTO_DETECT);
  24. R3D_EnableSkybox(skybox);
  25. camera = (Camera3D){
  26. .position = (Vector3) { 0, 0, 5 },
  27. .target = (Vector3) { 0, 0, 0 },
  28. .up = (Vector3) { 0, 1, 0 },
  29. .fovy = 60,
  30. };
  31. DisableCursor();
  32. return "[r3d] - Skybox example";
  33. }
  34. void Update(float delta)
  35. {
  36. UpdateCamera(&camera, CAMERA_FREE);
  37. }
  38. void Draw(void)
  39. {
  40. R3D_Begin(camera);
  41. for (int x = 0; x < 7; x++) {
  42. for (int y = 0; y < 7; y++) {
  43. R3D_DrawMesh(&sphere, &materials[y * 7 + x], MatrixTranslate(x - 3, y - 3, 0.0f));
  44. }
  45. }
  46. R3D_End();
  47. }
  48. void Close(void)
  49. {
  50. R3D_UnloadMesh(&sphere);
  51. R3D_UnloadSkybox(skybox);
  52. R3D_Close();
  53. }