Today I started implementing text, but have come across a stumbling block. While most of my code works, I can't ACTUALLY pass letters. If I set the letter in the vertex shader, it works, but passing it as an int VAO doesn't. It appears to receive and infinite number, as when I multiply by zero, it works.
Extracts from my text.cpp
// ...
int *letterType = new (int[text.size()]);
for (int i = 0; i < text.size(); i++) {
letterType[i] = 65;
}
glGenBuffers(1, &billboard_vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, billboard_vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
glGenBuffers(1, &text_position);
glBindBuffer(GL_ARRAY_BUFFER, text_position);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec2) * text.size(), letterPos, GL_STATIC_DRAW);
glGenBuffers(1, &text_letter);
glBindBuffer(GL_ARRAY_BUFFER, text_letter);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLint) * text.size(), letterType, GL_DYNAMIC_DRAW);
// ...
// Drawing
glVertexAttribDivisor(0, 0); // particles vertices : always reuse the same 4 vertices -> 0
glVertexAttribDivisor(1, 1); // positions : one per quad (its center) -> 1
glVertexAttribDivisor(2, 1); // color : one per quad -> 1
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, billboard_vertex_buffer);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, text_position);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, text_letter);
glVertexAttribPointer(2, 1, GL_INT, GL_FALSE, 0, (void*)0);
glVertexAttribDivisor(0, 0); // particles vertices : always reuse the same 4 vertices -> 0
glVertexAttribDivisor(1, 0); // positions : one per quad (its center) -> 1
glVertexAttribDivisor(2, 0); // color : one per quad -> 1
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
VS:
#version 330
layout(location = 0) in vec2 vertexPos;
layout(location = 1) in vec2 letterPos;
layout(location = 2) in int letter;
out vec2 UV;
void main () {
gl_Position = vec4((letterPos * 1.5)/8+vec2(vertexPos.x * 768/1366, vertexPos.y)/8, 0, 1.0);
UV = (vec2(letter%16, 15 - letter/16) + (vertexPos.xy+vec2(1,1))/2.0) / 16;
}
Thanks in Advance!