premultiplied_alpha.odin 776 B

1234567891011121314151617181920212223242526272829303132
  1. package karl2d_example_premultiplied_alpha
  2. import k2 "../.."
  3. import "core:log"
  4. main :: proc() {
  5. context.logger = log.create_console_logger()
  6. k2.init(1080, 1080, "Karl2D Premultiplied Alpha")
  7. k2.set_window_position(300, 100)
  8. // Load a texture and premultiply the alpha while loading it.
  9. tex := k2.load_texture_from_file("plop.png", options = { .Premultiply_Alpha })
  10. // Set the rendering to use premultiplied alpha when blending.
  11. k2.set_blend_mode(.Premultiplied_Alpha)
  12. for !k2.shutdown_wanted() {
  13. k2.process_events()
  14. k2.clear(k2.BLUE)
  15. src := k2.get_texture_rect(tex)
  16. dst := k2.Rect { 20, 100, src.w*20, src.h*20}
  17. k2.draw_texture_ex(tex, src, dst, {}, 0)
  18. k2.present()
  19. free_all(context.temp_allocator)
  20. }
  21. k2.destroy_texture(tex)
  22. k2.shutdown()
  23. }