我正在尝试将一个 uint 传递给我的着色器,但我一定是做错了什么,因为在着色器中的值是 3212836864 而不是 4294967295。
我有一个顶点数组,在将它们发送到着色器之前,我将每个顶点存储在其中glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex) * 4 * vertexBufferArrayInserts, vertexBufferArray);
这些是我的glVertexAttribPointer
电话:
shaderPosAttrib = glGetAttribLocation(shaderProgram, "position");
glVertexAttribPointer(shaderPosAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
glEnableVertexAttribArray(shaderPosAttrib);
shaderTexCoordAttrib = glGetAttribLocation(shaderProgram, "texCoord");
glVertexAttribPointer(shaderTexCoordAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texCoords));
glEnableVertexAttribArray(shaderTexCoordAttrib);
shaderColorAttrib = glGetAttribLocation(shaderProgram, "color");
glVertexAttribPointer(shaderColorAttrib, 1, GL_UNSIGNED_INT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, color));
glEnableVertexAttribArray(shaderColorAttrib);
这是 Vertex 结构
struct Vertex
{
Vector2<GLfloat> position;
Vector2<GLfloat> texCoords;
GLuint color;
Vertex() {
}
Vertex(Vector2<GLfloat> position, Vector2<GLfloat> texCoords, GLuint color) {
this->position = position;
this->texCoords = texCoords;
this->color = color;
}
};
顶点着色器:
#version 150
in vec2 position;
in vec2 texCoord;
in uint color;
out vec2 TexCoord;
out uint Color;
uniform mat4 projMat;
void main()
{
TexCoord = texCoord;
Color = color;
gl_Position = projMat * vec4(position, 0.0, 1.0);
}
片段着色器:
#version 150
in vec2 TexCoord;
in uint Color;
out vec4 outColor;
uniform sampler2D tex;
void main()
{
float colorr = 0;
if(Color == 3212836864)
colorr = 1;
outColor = texture(tex, TexCoord) * vec4(colorr, colorr, colorr, 1.0);
}
显然我在某处做错了什么,但我看不到它......非常感谢帮助!