resize.odin 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package resize
  2. import rl "vendor:raylib"
  3. import "core:fmt"
  4. import r3d "../r3d"
  5. get_aspect_mode_name :: proc(mode: r3d.AspectMode) -> cstring {
  6. switch mode {
  7. case .EXPAND: return "EXPAND"
  8. case .KEEP: return "KEEP"
  9. }
  10. return "UNKNOWN"
  11. }
  12. get_upscale_mode_name :: proc(mode: r3d.UpscaleMode) -> cstring {
  13. switch mode {
  14. case .NEAREST: return "NEAREST"
  15. case .LINEAR: return "LINEAR"
  16. case .BICUBIC: return "BICUBIC"
  17. case .LANCZOS: return "LANCZOS"
  18. }
  19. return "UNKNOWN"
  20. }
  21. main :: proc() {
  22. // Initialize window
  23. rl.InitWindow(800, 450, "[r3d] - Resize example")
  24. defer rl.CloseWindow()
  25. rl.SetWindowState({.WINDOW_RESIZABLE})
  26. rl.SetTargetFPS(60)
  27. // Initialize R3D
  28. r3d.Init(rl.GetScreenWidth(), rl.GetScreenHeight())
  29. defer r3d.Close()
  30. // Create sphere mesh and materials
  31. sphere := r3d.GenMeshSphere(0.5, 64, 64)
  32. defer r3d.UnloadMesh(sphere)
  33. materials: [5]r3d.Material
  34. for i in 0..<5 {
  35. materials[i] = r3d.GetDefaultMaterial()
  36. materials[i].albedo.color = rl.ColorFromHSV(f32(i) / 5 * 330, 1.0, 1.0)
  37. }
  38. // Setup directional light
  39. light := r3d.CreateLight(.DIR)
  40. r3d.SetLightDirection(light, {0, 0, -1})
  41. r3d.SetLightActive(light, true)
  42. // Setup camera
  43. camera: rl.Camera3D = {
  44. position = {0, 2, 2},
  45. target = {0, 0, 0},
  46. up = {0, 1, 0},
  47. fovy = 60,
  48. }
  49. // Current blit state
  50. aspect: r3d.AspectMode = .EXPAND
  51. upscale: r3d.UpscaleMode = .NEAREST
  52. // Main loop
  53. for !rl.WindowShouldClose()
  54. {
  55. rl.UpdateCamera(&camera, rl.CameraMode.ORBITAL)
  56. // Toggle aspect keep
  57. if rl.IsKeyPressed(.R) {
  58. aspect = r3d.AspectMode((int(aspect) + 1) % 2)
  59. r3d.SetAspectMode(aspect)
  60. }
  61. // Toggle linear filtering
  62. if rl.IsKeyPressed(.F) {
  63. upscale = r3d.UpscaleMode((int(upscale) + 1) % 4)
  64. r3d.SetUpscaleMode(upscale)
  65. }
  66. rl.BeginDrawing()
  67. rl.ClearBackground(rl.BLACK)
  68. // Draw spheres
  69. r3d.Begin(camera)
  70. for i in 0..<5 {
  71. r3d.DrawMesh(sphere, materials[i], {f32(i) - 2, 0, 0}, 1.0)
  72. }
  73. r3d.End()
  74. // Draw info
  75. rl.DrawText(
  76. fmt.ctprintf("Resize mode: %s", get_aspect_mode_name(aspect)),
  77. 10, 10, 20, rl.RAYWHITE,
  78. )
  79. rl.DrawText(
  80. fmt.ctprintf("Filter mode: %s", get_upscale_mode_name(upscale)),
  81. 10, 40, 20, rl.RAYWHITE,
  82. )
  83. rl.EndDrawing()
  84. }
  85. }