lispgames / cl-sdl2

Common Lisp bindings for SDL2 using C2FFI.
MIT License
308 stars 82 forks source link

Blend modes #153

Closed kensanata closed 3 months ago

kensanata commented 2 years ago

When using set-render-draw-blend-mode I need to specify a blend mode. In my own code, I've used the following:

(defconstant blendmode-none sdl2-ffi:+sdl-blendmode-none+
  "No blending.")
(defconstant blendmode-blend sdl2-ffi:+sdl-blendmode-blend+
  "Alpha blending.")
(defconstant blendmode-add sdl2-ffi:+sdl-blendmode-add+
  "Additive blending.")
(defconstant blendmode-mod sdl2-ffi:+sdl-blendmode-mod+
  "Color modulate.")

Well, actually I just used blendmode-blend. That one at least works:

  (sdl2:with-rects
      ((r (- (* *dimension* *scale* (pos-x *pen*))
         (floor *scale* 2))
      (- (* *dimension* *scale* (pos-y *pen*))
         (floor *scale* 2))
      (+ (* *dimension* *scale*)
         *scale*)
      (+ (* *dimension* *scale*)
         *scale*)))
    ;; 20% transparent forestgreen
    (sdl2:set-render-draw-blend-mode renderer blendmode-blend)
    (sdl2:set-render-draw-color renderer #x22 #x8B #x22 #x33)
    (sdl2:render-fill-rect renderer r))

I'm not sure whether these belong to render.lisp, or constants.lisp. We would probably want to mention these in the docstrings of blendmode-blend, and possibly set-texture-blend-mode.

fitzsim commented 3 months ago

Isn't what you have done in your own code sufficient? If I am missing something, then please submit a pull request (or re-open this and paste a patch here) showing what you would like changed.