render_texture.odin 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. k2.init(1080, 1080, "Karl2D Render Texture Example")
  24. render_texture := k2.create_render_texture(75, 48)
  25. for !k2.shutdown_wanted() {
  26. k2.process_events()
  27. k2.set_render_texture(render_texture)
  28. k2.clear(k2.BLUE)
  29. k2.draw_rect({1, 1, 12, 12}, k2.GREEN)
  30. k2.draw_rect({2, 2, 10, 10}, k2.BLACK)
  31. k2.draw_circle({20, 7}, 6, k2.BLACK)
  32. k2.draw_circle({20, 7}, 5, k2.GREEN)
  33. k2.draw_text("Hellöpe!", {1, 20}, 20, k2.WHITE)
  34. k2.set_render_texture(nil)
  35. k2.clear(k2.BLACK)
  36. rt_size := k2.get_texture_rect(render_texture.texture)
  37. k2.draw_texture_ex(render_texture.texture, rt_size, {0, 0, rt_size.w * 5, rt_size.h * 5}, {}, 0, k2.WHITE)
  38. k2.draw_texture(render_texture.texture, {400, 20}, k2.WHITE)
  39. k2.draw_texture_ex(render_texture.texture, rt_size, {512, 512, rt_size.w * 5, rt_size.h * 5}, {}, 70, k2.WHITE)
  40. k2.present()
  41. free_all(context.temp_allocator)
  42. }
  43. k2.destroy_render_texture(render_texture)
  44. k2.shutdown()
  45. }