basic.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "./common.h"
  2. #include "r3d.h"
  3. /* === Resources === */
  4. static R3D_Mesh plane = { 0 };
  5. static R3D_Mesh sphere = { 0 };
  6. static R3D_Material material = { 0 };
  7. static Camera3D camera = { 0 };
  8. /* === Example === */
  9. const char* Init(void)
  10. {
  11. /* --- Initialize R3D with its internal resolution --- */
  12. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  13. SetTargetFPS(60);
  14. /* --- Load gen a plane and sphere meshes and a default material to render them --- */
  15. plane = R3D_GenMeshPlane(1000, 1000, 1, 1, true);
  16. sphere = R3D_GenMeshSphere(0.5f, 64, 64, true);
  17. material = R3D_GetDefaultMaterial();
  18. /* --- Setup the scene lighting --- */
  19. R3D_Light light = R3D_CreateLight(R3D_LIGHT_SPOT);
  20. {
  21. R3D_LightLookAt(light, (Vector3) { 0, 10, 5 }, (Vector3) { 0 });
  22. R3D_EnableShadow(light, 4096);
  23. R3D_SetLightActive(light, true);
  24. }
  25. /* --- Setup the camera --- */
  26. camera = (Camera3D) {
  27. .position = (Vector3) { 0, 2, 2 },
  28. .target = (Vector3) { 0, 0, 0 },
  29. .up = (Vector3) { 0, 1, 0 },
  30. .fovy = 60,
  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_DrawMesh(&plane, &material, MatrixTranslate(0, -0.5f, 0));
  42. R3D_DrawMesh(&sphere, &material, MatrixIdentity());
  43. R3D_End();
  44. }
  45. void Close(void)
  46. {
  47. R3D_UnloadMesh(&plane);
  48. R3D_UnloadMesh(&sphere);
  49. R3D_Close();
  50. }