basic.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "./common.h"
  2. /* === Resources === */
  3. static R3D_Mesh plane = { 0 };
  4. static R3D_Mesh sphere = { 0 };
  5. static R3D_Material material = { 0 };
  6. static Camera3D camera = { 0 };
  7. /* === Example === */
  8. const char* Init(void)
  9. {
  10. /* --- Initialize R3D with its internal resolution --- */
  11. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  12. SetTargetFPS(60);
  13. /* --- Load gen a plane and sphere meshes and a default material to render them --- */
  14. plane = R3D_GenMeshPlane(1000, 1000, 1, 1);
  15. sphere = R3D_GenMeshSphere(0.5f, 64, 64);
  16. material = R3D_GetDefaultMaterial();
  17. /* --- Setup the scene lighting --- */
  18. R3D_SetAmbientColor((Color) { 10, 10, 10, 255 });
  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. }