basic.odin 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package basic
  2. import rl "vendor:raylib"
  3. import r3d "../r3d"
  4. main :: proc() {
  5. // Initialize window
  6. rl.InitWindow(800, 450, "[r3d] - Basic example")
  7. defer rl.CloseWindow()
  8. rl.SetTargetFPS(60)
  9. // Initialize R3D
  10. r3d.Init(rl.GetScreenWidth(), rl.GetScreenHeight())
  11. defer r3d.Close()
  12. // Create meshes
  13. plane := r3d.GenMeshPlane(1000, 1000, 1, 1)
  14. sphere := r3d.GenMeshSphere(0.5, 64, 64)
  15. material := r3d.GetDefaultMaterial()
  16. // Setup environment
  17. env := r3d.GetEnvironment()
  18. env.ambient.color = {10, 10, 10, 255}
  19. // Create light
  20. light := r3d.CreateLight(.SPOT)
  21. r3d.LightLookAt(light, {0, 10, 5}, {0, 0, 0})
  22. r3d.SetLightActive(light, true)
  23. r3d.EnableShadow(light)
  24. // Setup camera
  25. camera: rl.Camera3D = {
  26. position = {0, 2, 2},
  27. target = {0, 0, 0},
  28. up = {0, 1, 0},
  29. fovy = 60
  30. }
  31. // Main loop
  32. for !rl.WindowShouldClose()
  33. {
  34. rl.UpdateCamera(&camera, rl.CameraMode.ORBITAL)
  35. rl.BeginDrawing()
  36. rl.ClearBackground(rl.RAYWHITE)
  37. r3d.Begin(camera)
  38. r3d.DrawMesh(plane, material, {0, -0.5, 0}, 1.0)
  39. r3d.DrawMesh(sphere, material, {0, 0, 0}, 1.0)
  40. r3d.End()
  41. rl.EndDrawing()
  42. }
  43. // Cleanup
  44. r3d.UnloadMesh(sphere)
  45. r3d.UnloadMesh(plane)
  46. }