minimal.odin 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // A small program that draws some shapes, some texts and a texture.
  2. //
  3. // There is a web version of this example in `../minimal_web` -- Many other examples work on web out
  4. // of the box. But the web support requires slight changes to the structure of the program. Here we
  5. // want to keep things as simple as possible, which is why the `minimal` example has a separate web
  6. // version.
  7. package karl2d_minimal_example
  8. import k2 "../.."
  9. import "core:log"
  10. import "core:math"
  11. import "core:fmt"
  12. main :: proc() {
  13. context.logger = log.create_console_logger()
  14. k2.init(1080, 1080, "Karl2D Minimal Program")
  15. tex := k2.load_texture_from_file("sixten.jpg")
  16. for !k2.shutdown_wanted() {
  17. k2.new_frame()
  18. k2.process_events()
  19. k2.clear(k2.BLUE)
  20. t := k2.get_time()
  21. pos_x := f32(math.sin(t*10)*10)
  22. rot := f32(t*50)
  23. k2.draw_texture_ex(tex, {0, 0, f32(tex.width), f32(tex.height)}, {pos_x + 400, 450, 900, 500}, {450, 250}, rot)
  24. k2.draw_rect({10, 10, 60, 60}, k2.GREEN)
  25. k2.draw_rect({20, 20, 40, 40}, k2.BLACK)
  26. k2.draw_circle({120, 40}, 30, k2.BLACK)
  27. k2.draw_circle({120, 40}, 20, k2.GREEN)
  28. k2.draw_text("Hellöpe!", {10, 100}, 48, k2.WHITE)
  29. msg1 := fmt.tprintf("Time since start: %.3f s", t)
  30. msg2 := fmt.tprintf("Last frame time: %.5f s", k2.get_frame_time())
  31. k2.draw_text(msg1, {10, 148}, 48, k2.WHITE)
  32. k2.draw_text(msg2, {10, 196}, 48, k2.WHITE)
  33. k2.present()
  34. free_all(context.temp_allocator)
  35. }
  36. k2.destroy_texture(tex)
  37. k2.shutdown()
  38. }