python中的glCreateProgram()。uniform

时间:2018-11-24 16:46:17

标签: python opengl shader pyopengl

我正在尝试将带有opengl的一些JavaScript代码移植到python。但是无法找出我在翻译prog.uniform[u] = gl.getUniformLocation(prog, u);

时做错了什么

Javascript:

let v = buildShader(vert, gl.VERTEX_SHADER);
let f = buildShader(frag, gl.FRAGMENT_SHADER);
let prog = gl.createProgram();
gl.attachShader(prog, v);
gl.attachShader(prog, f);
gl.linkProgram(prog);
prog.uniform = {};
u = ['model','bounds','frac','aspect'];
_.each(u, function(u){ prog.uniform[u] = gl.getUniformLocation(prog, u); });

Python3 / PyOpenGl:

v = self.buildShader(vert, GL_VERTEX_SHADER)
f = self.buildShader(frag, GL_FRAGMENT_SHADER)
prog = glCreateProgram()
glAttachShader(prog, v)
glAttachShader(prog, f)
glLinkProgram(prog)
for u in ['model','bounds','frac','aspect']:
  loc = glGetUniformLocations(prog,u)
  glProgramUniform(prog,loc,u)

1 个答案:

答案 0 :(得分:3)

glProgramUniform为统一设置一个值,其中第三个参数是该值。

glProgramUniform(prog,loc,u)毫无意义,当u是字符串(这是制服的名称)时。

您必须创建一个字典,其中包含每个姓名的制服位置:

uniform = {}
for u in ['model','bounds','frac','aspect']:
    uniform[u] = glGetUniformLocation(prog, u)

或者简单地

uniform = { u : glGetUniformLocation(prog, u) for u in ['model','bounds','frac','aspect'] }