premultiplied_alpha.odin 951 B

12345678910111213141516171819202122232425262728293031323334
  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. // Note: In a real game you might precompute this, the premultiply-on-load will slow the load
  10. // down. However, you can start with doing it on load and precompute it later.
  11. tex := k2.load_texture_from_file("plop.png", options = { .Premultiply_Alpha })
  12. // Set the rendering to use premultiplied alpha when blending.
  13. k2.set_blend_mode(.Premultiplied_Alpha)
  14. for !k2.shutdown_wanted() {
  15. k2.process_events()
  16. k2.clear(k2.BLUE)
  17. src := k2.get_texture_rect(tex)
  18. dst := k2.Rect { 20, 100, src.w*20, src.h*20}
  19. k2.draw_texture_ex(tex, src, dst, {}, 0)
  20. k2.present()
  21. free_all(context.temp_allocator)
  22. }
  23. k2.destroy_texture(tex)
  24. k2.shutdown()
  25. }