electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

pyray.set_shader_value doesn't work #57

Closed JackWitherell closed 2 years ago

JackWitherell commented 2 years ago

Setting the uniform of a shader doesn't work in pyray as early as 4.0.0.2, still fails in 4.0.0.3 Platform - Windows (this issue is likely platform independent)

Issue - Following the example causes an error TypeError: expected a cdata struct/union/array object Example:

import pyray as pr

pr.init_window(1280, 720, "any")

shader = pr.load_shader(b"", b"shader.fs")
time = pr.ffi.new("float *", 0.0)
timeLoc = pr.get_shader_location(shader, b"uTime")
pr.set_shader_value(shader, timeLoc, time, pr.SHADER_UNIFORM_FLOAT) # <<failure on this line
electronstudio commented 2 years ago

the issue is we added auto pointerization to pyray, so if the C function takes a pointer the python argument gets automatically turned into a pointer. in this case it's already a pointer, so we shouldn't do pointerization.

i guess i will have to add a special case for when it's already a pointer. Ideally python programmers wouldn't have to use ffi.new and would just supply a python float, but I don't know how that could be done automatically.

JackWitherell commented 2 years ago

Good call, but changing that float pointer to a float causes it to fail as well. This is specific to pyray. raylib as rl works as intended with code like what's above (but of course with the non-pythonic API)

image

electronstudio commented 2 years ago

Yeah, problem is we can't pointerize a python float, it's not the same thing as a C float.

You can mix raylib/pyray code in same program to get round this until it's fixed.

electronstudio commented 2 years ago

Please update to raylib-4.0.0.4 and test. Both of your examples, the one with the float* and the one with 0.0 should now work.