glsl pyOpenGL 数组传递
我目前正在玩 glsl。为此,我需要将一个数组从 opengl 代码传递到 gsls,然后 gsls 从数组中计算出新的颜色。但不知怎的,这对我不起作用。我总是只保留第一个条目,而不是获取整个数组。 你能帮我说一下我做错了什么吗?
import numpy as np
\\...
array = np.array([1.2,2.5,3.8,4.3,5.6, #....])
location = glGetUniformLocation(program,"arrayInShader")
glUniform1fv(location,1,array)
在着色器中:
uniform float arrayInShader[5];
varying vec3 color;
void main()
{
color.r=arrayInShader[0]+arrayInShader[1];
color.g=arrayInShader[2];
color.b=arrayInShader[3]+arrayInShader[4];
}
非常感谢大家!
I'm currently playing around with glsl. For that purpose i need to pass an array from the opengl code to the gsls, which then in return calculates a new color out of the array. But somehow this doesn't work for me. Instead of getting the whole array I'm always stuck with only the first entry.
Could you help me by saying what I'm doing wrong?
import numpy as np
\\...
array = np.array([1.2,2.5,3.8,4.3,5.6, #....])
location = glGetUniformLocation(program,"arrayInShader")
glUniform1fv(location,1,array)
and in the shader:
uniform float arrayInShader[5];
varying vec3 color;
void main()
{
color.r=arrayInShader[0]+arrayInShader[1];
color.g=arrayInShader[2];
color.b=arrayInShader[3]+arrayInShader[4];
}
Thanks a lot guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
glUniform*v
的第二个参数是count。要上传的元素数量。你说你只加载 1 个浮点数到数组中,所以 OpenGL 只加载 1 个浮点数到数组中。The second parameter of
glUniform*v
is the count. The number of elements to upload. You say that you're only loading 1 float into the array, so OpenGL only loads one float into the array.