render_texture.odin 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package karl2d_minimal_example
  2. import k2 "../.."
  3. import "core:mem"
  4. import "core:log"
  5. import "core:fmt"
  6. _ :: fmt
  7. _ :: mem
  8. main :: proc() {
  9. context.logger = log.create_console_logger()
  10. init()
  11. run := true
  12. for run {
  13. run = step()
  14. }
  15. shutdown()
  16. }
  17. render_texture: k2.Render_Texture
  18. init :: proc() {
  19. k2.init(1080, 1080, "Karl2D Render Texture Example")
  20. render_texture = k2.create_render_texture(75, 48)
  21. }
  22. step :: proc() -> bool {
  23. k2.new_frame()
  24. k2.process_events()
  25. k2.set_render_texture(render_texture)
  26. k2.clear(k2.PURPLE)
  27. k2.draw_rect({1, 1, 12, 12}, k2.RED)
  28. k2.draw_rect({2, 2, 10, 10}, k2.LIGHT_RED)
  29. k2.draw_circle({20, 7}, 6, k2.BLUE)
  30. k2.draw_circle({20, 7}, 5, k2.LIGHT_BLUE)
  31. k2.draw_text("Hellöpe!", {1, 20}, 20, k2.WHITE)
  32. k2.set_render_texture(nil)
  33. k2.clear(k2.BLACK)
  34. rt_size := k2.get_texture_rect(render_texture.texture)
  35. k2.draw_texture_ex(render_texture.texture, rt_size, {0, 0, rt_size.w * 5, rt_size.h * 5}, {}, 0)
  36. k2.draw_texture(render_texture.texture, {400, 20})
  37. k2.draw_texture_ex(render_texture.texture, rt_size, {512, 512, rt_size.w * 5, rt_size.h * 5}, {}, 70, k2.WHITE)
  38. k2.present()
  39. free_all(context.temp_allocator)
  40. return !k2.shutdown_wanted()
  41. }
  42. shutdown :: proc() {
  43. k2.destroy_render_texture(render_texture)
  44. k2.shutdown()
  45. }