2
0

basic.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <r3d/r3d.h>
  2. #include <raymath.h>
  3. int main(void)
  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, (Vector3){0, 10, 5}, (Vector3){0});
  19. R3D_EnableShadow(light);
  20. R3D_SetLightActive(light, true);
  21. // Setup camera
  22. Camera3D camera = {
  23. .position = {0, 2, 2},
  24. .target = {0, 0, 0},
  25. .up = {0, 1, 0},
  26. .fovy = 60
  27. };
  28. // Main loop
  29. while (!WindowShouldClose())
  30. {
  31. UpdateCamera(&camera, CAMERA_ORBITAL);
  32. BeginDrawing();
  33. ClearBackground(RAYWHITE);
  34. R3D_Begin(camera);
  35. R3D_DrawMesh(plane, material, (Vector3) {0, -0.5f, 0}, 1.0f);
  36. R3D_DrawMesh(sphere, material, Vector3Zero(), 1.0f);
  37. R3D_End();
  38. EndDrawing();
  39. }
  40. // Cleanup
  41. R3D_UnloadMesh(sphere);
  42. R3D_UnloadMesh(plane);
  43. R3D_Close();
  44. CloseWindow();
  45. return 0;
  46. }