minimal.odin 1.7 KB

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