blender.go 2.7 KB

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