premultiplied_alpha.odin 1006 B

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