blender.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // blender support
  2. package al
  3. /*
  4. #include <stdlib.h>
  5. #include <allegro5/allegro.h>
  6. #include "helpers.h"
  7. #include "callbacks.h"
  8. */
  9. import "C"
  10. // import "runtime"
  11. // import "unsafe"
  12. type BlendMode C.enum_ALLEGRO_BLEND_MODE
  13. /*
  14. * Blending modes
  15. */
  16. const (
  17. ZERO = BlendMode(C.ALLEGRO_ZERO)
  18. ONE = BlendMode(C.ALLEGRO_ONE)
  19. ALPHA = BlendMode(C.ALLEGRO_ALPHA)
  20. INVERSE_ALPHA = BlendMode(C.ALLEGRO_INVERSE_ALPHA)
  21. SRC_COLOR = BlendMode(C.ALLEGRO_SRC_COLOR)
  22. DEST_COLOR = BlendMode(C.ALLEGRO_DEST_COLOR)
  23. INVERSE_SRC_COLOR = BlendMode(C.ALLEGRO_INVERSE_SRC_COLOR)
  24. INVERSE_DEST_COLOR = BlendMode(C.ALLEGRO_INVERSE_DEST_COLOR)
  25. CONST_COLOR = BlendMode(C.ALLEGRO_CONST_COLOR)
  26. INVERSE_CONST_COLOR= BlendMode(C.ALLEGRO_INVERSE_CONST_COLOR)
  27. NUM_BLEND_MODES = BlendMode(C.ALLEGRO_NUM_BLEND_MODES)
  28. )
  29. func (bm BlendMode) toC() C.enum_ALLEGRO_BLEND_MODE {
  30. return C.enum_ALLEGRO_BLEND_MODE(bm)
  31. }
  32. type BlendOperations C.enum_ALLEGRO_BLEND_OPERATIONS
  33. func (bo BlendOperations) toC() C.enum_ALLEGRO_BLEND_MODE {
  34. return C.enum_ALLEGRO_BLEND_OPERATIONS(bo)
  35. }
  36. const(
  37. ADD = BlendOperations(C.ALLEGRO_ADD)
  38. SRC_MINUS_DEST = BlendOperations(C.ALLEGRO_SRC_MINUS_DEST)
  39. DEST_MINUS_SRC = BlendOperations(C.ALLEGRO_DEST_MINUS_SRC)
  40. NUM_BLEND_OPERATIONS = BlendOperations(C.ALLEGRO_NUM_BLEND_OPERATIONS)
  41. )
  42. func SetBlender(op BlendOperations, src, dest BlendMode) {
  43. C.al_set_blender(C.int(op), C.int(src), C.int(dest))
  44. }
  45. func SetBlendColor(color Color) {
  46. C.al_set_blend_color(color.toC())
  47. }
  48. func GetBlender() (op BlendOperations, src, dest BlendMode) {
  49. var cop, csrc, cdest C.int
  50. C.al_get_blender(&cop, &csrc, &cdest)
  51. op = BlendOperations(cop)
  52. src = BlendMode(csrc)
  53. dest = BlendMode(cdest)
  54. return op, src, dest
  55. }
  56. func GetBlendColor() Color {
  57. return wrapColor(C.al_get_blend_color())
  58. }
  59. func SetSeparateBlender(op BlendOperations, src, dest BlendMode,
  60. alpha_op BlendOperations, alpha_src, alpha_dest BlendMode) {
  61. C.al_set_separate_blender(C.int(op), C.int(src), C.int(dest),
  62. C.int(alpha_op), C.int(alpha_src), C.int(alpha_dest))
  63. }
  64. func GetSeparateBlender() (op BlendOperations, src, dest BlendMode,
  65. alpha_op BlendOperations, alpha_src, alpha_dest BlendMode) {
  66. var cop, csrc, cdest, calpha_op, calpha_src, calpha_dest C.int
  67. C.al_get_separate_blender(&cop, &csrc, &cdest,
  68. &calpha_op, &calpha_src, &calpha_dest)
  69. op = BlendOperations(cop)
  70. src = BlendMode(csrc)
  71. dest = BlendMode(cdest)
  72. alpha_op = BlendOperations(calpha_op)
  73. alpha_src = BlendMode(calpha_src)
  74. alpha_dest = BlendMode(calpha_dest)
  75. return op, src, dest, alpha_op, alpha_src, alpha_dest
  76. }