skybox.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "./common.h"
  2. /* === Resources === */
  3. static Mesh sphere = { 0 };
  4. static R3D_Skybox skybox = { 0 };
  5. static Camera3D camera = { 0 };
  6. static Material materials[7 * 7] = { 0 };
  7. /* === Examples === */
  8. const char* Init(void)
  9. {
  10. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  11. SetTargetFPS(60);
  12. sphere = GenMeshSphere(0.5f, 64, 64);
  13. for (int x = 0; x < 7; x++) {
  14. for (int y = 0; y < 7; y++) {
  15. int i = y * 7 + x;
  16. materials[i] = LoadMaterialDefault();
  17. R3D_SetMaterialOcclusion(&materials[i], NULL, 1.0f);
  18. R3D_SetMaterialMetalness(&materials[i], NULL, (float)x / 7);
  19. R3D_SetMaterialRoughness(&materials[i], NULL, (float)y / 7);
  20. R3D_SetMaterialAlbedo(&materials[i], NULL, 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. for (int i = 0; i < 7 * 7; i++) {
  51. RL_FREE(materials[i].maps);
  52. }
  53. UnloadMesh(sphere);
  54. R3D_UnloadSkybox(skybox);
  55. R3D_Close();
  56. }