minimal.odin 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package karl2d_minimal_example
  2. import k2 "../.."
  3. import "core:mem"
  4. import "core:log"
  5. import "core:fmt"
  6. import "base:runtime"
  7. _ :: fmt
  8. _ :: mem
  9. tex: k2.Texture
  10. default_context: runtime.Context
  11. track: mem.Tracking_Allocator
  12. main :: proc() {
  13. when ODIN_DEBUG {
  14. mem.tracking_allocator_init(&track, context.allocator)
  15. context.allocator = mem.tracking_allocator(&track)
  16. }
  17. context.logger = log.create_console_logger()
  18. default_context = context
  19. k2.init(1080, 1080, "Karl2D Minimal Program")
  20. k2.set_window_position(300, 100)
  21. tex = k2.load_texture_from_file("sixten.jpg")
  22. when ODIN_OS != .JS {
  23. for !k2.shutdown_wanted() {
  24. step(0)
  25. }
  26. k2.destroy_texture(tex)
  27. k2.shutdown()
  28. }
  29. }
  30. shutdown :: proc() {
  31. if len(track.allocation_map) > 0 {
  32. for _, entry in track.allocation_map {
  33. fmt.eprintf("%v leaked: %v bytes\n", entry.location, entry.size)
  34. }
  35. }
  36. mem.tracking_allocator_destroy(&track)
  37. }
  38. @export
  39. step :: proc(dt: f64) {
  40. context = default_context
  41. k2.process_events()
  42. k2.clear(k2.BLUE)
  43. k2.draw_rect({10, 10, 60, 60}, k2.GREEN)
  44. k2.draw_rect({20, 20, 40, 40}, k2.BLACK)
  45. k2.draw_circle({120, 40}, 30, k2.BLACK)
  46. k2.draw_circle({120, 40}, 20, k2.GREEN)
  47. k2.draw_text("Hellöpe!", {10, 100}, 64, k2.WHITE)
  48. k2.draw_texture_ex(tex, {0, 0, f32(tex.width), f32(tex.height)}, {10, 200, 900, 500}, {}, 0)
  49. k2.present()
  50. free_all(context.temp_allocator)
  51. }