render_texture.odin 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. when ODIN_DEBUG {
  11. track: mem.Tracking_Allocator
  12. mem.tracking_allocator_init(&track, context.allocator)
  13. context.allocator = mem.tracking_allocator(&track)
  14. defer {
  15. if len(track.allocation_map) > 0 {
  16. for _, entry in track.allocation_map {
  17. fmt.eprintf("%v leaked: %v bytes\n", entry.location, entry.size)
  18. }
  19. }
  20. mem.tracking_allocator_destroy(&track)
  21. }
  22. }
  23. init()
  24. for !k2.shutdown_wanted() {
  25. if !step(0) {
  26. break
  27. }
  28. }
  29. shutdown()
  30. }
  31. render_texture: k2.Render_Texture
  32. init :: proc() {
  33. k2.init(1080, 1080, "Karl2D Render Texture Example")
  34. render_texture = k2.create_render_texture(75, 48)
  35. }
  36. step :: proc(dt: f32) -> bool {
  37. k2.process_events()
  38. k2.set_render_texture(render_texture)
  39. k2.clear(k2.BLUE)
  40. k2.draw_rect({1, 1, 12, 12}, k2.GREEN)
  41. k2.draw_rect({2, 2, 10, 10}, k2.BLACK)
  42. k2.draw_circle({20, 7}, 6, k2.BLACK)
  43. k2.draw_circle({20, 7}, 5, k2.GREEN)
  44. k2.draw_text("Hellöpe!", {1, 20}, 20, k2.WHITE)
  45. k2.set_render_texture(nil)
  46. k2.clear(k2.WHITE)
  47. rt_size := k2.get_texture_rect(render_texture.texture)
  48. k2.draw_texture_ex(render_texture.texture, rt_size, {0, 0, rt_size.w * 5, rt_size.h * 5}, {}, 0, k2.WHITE)
  49. k2.draw_texture(render_texture.texture, {400, 20}, k2.WHITE)
  50. k2.draw_texture_ex(render_texture.texture, rt_size, {512, 512, rt_size.w * 5, rt_size.h * 5}, {}, 70, k2.WHITE)
  51. k2.present()
  52. free_all(context.temp_allocator)
  53. return true
  54. }
  55. shutdown :: proc() {
  56. k2.destroy_render_texture(render_texture)
  57. k2.shutdown()
  58. }