basic.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "./common.h"
  2. /* === Resources === */
  3. static Model plane = { 0 };
  4. static Model sphere = { 0 };
  5. static Camera3D camera = { 0 };
  6. /* === Examples === */
  7. const char* Init(void)
  8. {
  9. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  10. SetTargetFPS(60);
  11. plane = LoadModelFromMesh(GenMeshPlane(1000, 1000, 1, 1));
  12. plane.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1;
  13. plane.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 1;
  14. plane.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0;
  15. sphere = LoadModelFromMesh(GenMeshSphere(0.5f, 64, 64));
  16. sphere.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1;
  17. sphere.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.25;
  18. sphere.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.75;
  19. camera = (Camera3D) {
  20. .position = (Vector3) { 0, 2, 2 },
  21. .target = (Vector3) { 0, 0, 0 },
  22. .up = (Vector3) { 0, 1, 0 },
  23. .fovy = 60,
  24. };
  25. R3D_Light light = R3D_CreateLight(R3D_LIGHT_SPOT);
  26. {
  27. R3D_SetLightPosition(light, (Vector3) { 0, 10, 5 });
  28. R3D_SetLightTarget(light, (Vector3) { 0 });
  29. R3D_SetLightActive(light, true);
  30. R3D_EnableShadow(light, 4096);
  31. }
  32. return "[r3d] - basic example";
  33. }
  34. void Update(float delta)
  35. {
  36. UpdateCamera(&camera, CAMERA_ORBITAL);
  37. }
  38. void Draw(void)
  39. {
  40. R3D_Begin(camera);
  41. R3D_DrawModel(plane, (Vector3) { 0, -0.5f, 0 }, 1.0f);
  42. R3D_DrawModel(sphere, (Vector3) { 0 }, 1.0f);
  43. R3D_End();
  44. }
  45. void Close(void)
  46. {
  47. UnloadModel(plane);
  48. UnloadModel(sphere);
  49. R3D_Close();
  50. }