glsl pyOpenGL数组传递 [英] glsl pyOpenGL array passing

查看:106
本文介绍了glsl pyOpenGL数组传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在玩glsl.为此,我需要将一个数组从opengl代码传递到gsls,然后由gsls返回该数组中的新颜色.但是,这对我不起作用.我总是只停留在第一个条目上,而不是获取整个数组. 您能通过说我做错了什么来帮助我吗?

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)

并在着色器中:

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];
}

非常感谢你们!

推荐答案

glUniform*v的第二个参数是 count .要上传的元素数.您说您仅将1个float加载到数组中,因此OpenGL仅将1个float加载到数组中.

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.

这篇关于glsl pyOpenGL数组传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆