So I have an array of Vertex objects, which look like this:
Vertex: {[0.0, 0.0], [1.0, 1.0, 1.0, 1.0], [0.0, 0.0]}
Vertex: {[0.0, 512.0], [1.0, 1.0, 1.0, 1.0], [0.0, 1.0]}
Vertex: {[512.0, 0.0], [1.0, 1.0, 1.0, 1.0], [1.0, 0.0]}
Vertex: {[512.0, 512.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0]}
Where it's organized like this:
{[X, Y], [R, G, B, A], [U, V]}
And I have a shader that accepts these as attributes;
Sprite.vs:
#version 330 core
layout (location = 0) in vec2 vertex;
layout (location = 1) in vec4 color;
layout (location = 2) in vec2 texcoords;
out vec4 SpriteColor;
out vec2 TexCoords;
uniform mat4 gProjection;
void main()
{
SpriteColor = color;
TexCoords = texcoords;
gl_Position = gProjection * vec4(vertex, 0.0, 1.0);
}
Sprite.fs:
#version 330 core
in vec4 SpriteColor;
in vec2 TexCoords;
out vec4 color;
uniform sampler2D gSpriteTexture;
void main()
{
color = SpriteColor * texture(gSpriteTexture, TexCoords);
}
And here's how I'm attaching the attributes:
FloatBuffer vertexBuf = BufferUtils.createFloatBuffer(vertices.length * Vertex.numFields());
for (Vertex v : vertices) {
vertexBuf.put(v.toFloatArray());
}
vertexBuf.flip();
vao = glGenVertexArrays();
int vbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertexBuf, GL_STATIC_DRAW);
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 2, GL_FLOAT, false, Vertex.stride(), 0);
glVertexAttribPointer(1, 4, GL_FLOAT, false, Vertex.stride(), 8);
glVertexAttribPointer(2, 2, GL_FLOAT, false, Vertex.stride(), 24);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
Vertex.numFields is 8, and Vertex.stride() is 32.
My draw function:
@Override
public void draw(RenderTarget rt, RenderStates states) {
...
texture.bind(COLOR_TEXTURE_UNIT);
shader.enable();
shader.setTextureUnit(COLOR_TEXTURE_UNIT_INDEX);
shader.setProjection(getOrthoMatrix(rt.getView()));
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
...
}
I don't think the error is in here, though, as I didn't change the draw function from when it worked (when I was using a uniform variable for the sprite color)
However, nothing is drawing here. What am I messing up?
Even when I don't even use SpriteColor in my color output, it still outputs nothing.