basic.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <r3d/r3d.h>
  2. #include <raymath.h>
  3. int main()
  4. {
  5. // Initialize window
  6. InitWindow(800, 450, "[r3d] - Basic example");
  7. SetTargetFPS(60);
  8. // Initialize R3D
  9. R3D_Init(GetScreenWidth(), GetScreenHeight());
  10. // Create meshes
  11. R3D_Mesh plane = R3D_GenMeshPlane(1000, 1000, 1, 1);
  12. R3D_Mesh sphere = R3D_GenMeshSphere(0.5f, 64, 64);
  13. R3D_Material material = R3D_GetDefaultMaterial();
  14. // Setup environment
  15. R3D_ENVIRONMENT_SET(ambient.color, Color{10, 10, 10, 255});
  16. // Create light
  17. R3D_Light light = R3D_CreateLight(R3D_LIGHT_SPOT);
  18. R3D_LightLookAt(light, {0, 10, 5}, {});
  19. R3D_EnableShadow(light);
  20. R3D_SetLightActive(light, true);
  21. // Setup camera
  22. Camera3D camera = {};
  23. camera.position = {0, 2, 2};
  24. camera.target = {0, 0, 0};
  25. camera.up = {0, 1, 0};
  26. camera.fovy = 60;
  27. // Main loop
  28. while (!WindowShouldClose())
  29. {
  30. UpdateCamera(&camera, CAMERA_ORBITAL);
  31. BeginDrawing();
  32. ClearBackground(RAYWHITE);
  33. R3D_Begin(camera);
  34. R3D_DrawMesh(plane, material, {0, -0.5f, 0}, 1.0f);
  35. R3D_DrawMesh(sphere, material, {}, 1.0f);
  36. R3D_End();
  37. EndDrawing();
  38. }
  39. // Cleanup
  40. R3D_UnloadMesh(sphere);
  41. R3D_UnloadMesh(plane);
  42. R3D_Close();
  43. CloseWindow();
  44. return 0;
  45. }