我正在尝试使用 pyglet 和 OpenGL 4 样式着色器(即:不使用任何矩阵运算,使用 (layout=...) 等...)
我有一个基本的顶点着色器,它是:
#version 400
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform vec2 offset;
varying vec4 vertex_color;
layout(location=0) in vec4 inVert;
layout(location=1) in vec4 inColor;
void main() {
gl_Position = projectionMatrix * ( modelviewMatrix * ( inVert + vec4(offset.x, offset.y, 0, 0) ) );
vertex_color = gl_Color;
}
和一个基本的片段着色器:
#version 400
varying vec4 vertex_color;
out vec4 outColor;
void main(){
outColor = vertex_color;
}
我用
a = pyglet.graphics.vertex_list(num*3, ('v4f', vs), ('c4f', color))
定义我的抽奖列表并使用
a.draw()
在 on_draw(GL_TRIANGLES) 函数中。
照原样,这工作正常,它正确地绘制顶点,偏移它们,并且它们具有正确的颜色。
但是,我想使用 layout(location=1)... 行来获取颜色,而不是使用 gl_Color。我会想如果对 glVertexAttribPointer 和 glEnableVertexAttribArray 的调用是以我可以想象的方式对颜色属性进行的,如果我手动进行调用,那么我所拥有的就会起作用。
我看到来电
glVertexAttribPointer(self.index, self.count, self.gl_type,
self.normalized, self.stride,
self.offset + pointer)
在 pyglet 的 vertexattribute.py 中,所以也许我以某种方式滥用了“布局”