basic.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  12. SetTargetFPS(60);
  13. plane = R3D_GenMeshPlane(1000, 1000, 1, 1, true);
  14. sphere = R3D_GenMeshSphere(0.5f, 64, 64, true);
  15. material = R3D_GetDefaultMaterial();
  16. camera = (Camera3D) {
  17. .position = (Vector3) { 0, 2, 2 },
  18. .target = (Vector3) { 0, 0, 0 },
  19. .up = (Vector3) { 0, 1, 0 },
  20. .fovy = 60,
  21. };
  22. R3D_Light light = R3D_CreateLight(R3D_LIGHT_SPOT);
  23. {
  24. R3D_LightLookAt(light, (Vector3) { 0, 10, 5 }, (Vector3) { 0 });
  25. R3D_EnableShadow(light, 4096);
  26. R3D_SetLightActive(light, true);
  27. }
  28. return "[r3d] - Basic example";
  29. }
  30. void Update(float delta)
  31. {
  32. UpdateCamera(&camera, CAMERA_ORBITAL);
  33. }
  34. void Draw(void)
  35. {
  36. R3D_Begin(camera);
  37. R3D_DrawMesh(&plane, &material, MatrixTranslate(0, -0.5f, 0));
  38. R3D_DrawMesh(&sphere, &material, MatrixIdentity());
  39. R3D_End();
  40. }
  41. void Close(void)
  42. {
  43. R3D_UnloadMesh(&plane);
  44. R3D_UnloadMesh(&sphere);
  45. R3D_Close();
  46. }