lispgames / cl-sdl2

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

sdl2:get-texture-color-mod gives garbage results #118

Open minusmaterial opened 5 years ago

minusmaterial commented 5 years ago

Hello. I've started using cl-sdl2 for a small personal project; for the most part, the experience has been good. Thanks!

However, when I tried to use sdl2:get-texture-color-mod to get the current color mod state of a texture, I got back garbage results; even when I ran a loop, setting the texture color just before printing out the results of ( sdl2:get-texture-color-mod tex ), the values were basically random.

I had a look at the source code, and found this definition-

(defun get-texture-color-mod (texture) "Use this function to get the additional color value multiplied into render copy operations." (c-with ((r :unsigned-short) (g :unsigned-short) (b :unsigned-short)) (check-rc (sdl-get-texture-color-mod texture (r &) (g &) (b &))) (values r g b)))

I replicated it in my code, and found that my problem was fixed by changing the types of r, g, and b to :char rather than :unsigned-short; I'm on a 64-bit machine- I'm guessing there's something going on with discrepancies in the sizes of different types?

For now, my problem is fixed (on my machine...), but I thought I ought to let you know. If you need any more info, just ask.

mfiano commented 5 years ago

Hello, thanks for reporting this. After looking at the SDL2 documentation, I have no idea if things changed or not, or why the previous maintainer used a 2-byte type, when it is marked as Uint8. Would you mind sending that PR over?

Edit: It's been a while since I looked at this code, but that definitely has to be unsigned, which you didn't mention in your fix above. I'm not sure if :char maps to :unsigned-byte, :signed-byte, or what. So that has to be taken into consideration.