I am using core OpenGL to draw fonts. This works when I do just one font set at a time. Now I am trying to use three different sets in an array.
I have this structure:
struct _sdf_Vertex
{
glm::vec2 position;
glm::vec2 textureCoord;
glm::vec4 color;
};
and I use three fonts - so this:
vector<_sdf_Vertex> sdf_vertex[3];
vector<unsigned int> sdf_indexes[3];
I then populate each font type like this ( this works fine - I can see all the data in each element):
void sdf_addVertexInfo(uint whichFont, glm::vec2 position, glm::vec2 textureCoord, glm::vec4 color)
{
_sdf_Vertex sdf_vertexTemp; // Temp to hold vertex info before adding to vector
sdf_vertexTemp.position = position;
sdf_vertexTemp.textureCoord = textureCoord;
sdf_vertexTemp.color = color;
sdf_vertex[whichFont].push_back(sdf_vertexTemp);
}
and then I want to pass one set of font data to the shader:
glBufferData ( GL_ARRAY_BUFFER, sizeof(_sdf_Vertex) * sdf_vertex[whichFont].size(), &sdf_vertex[whichFont], GL_DYNAMIC_DRAW );
glVertexAttribPointer ( shaderProgram[SHADER_TTF_FONT].inVertsID, 2, GL_FLOAT, GL_FALSE, sizeof(_sdf_Vertex), (GLvoid*)offsetof(_sdf_Vertex, position) );
glEnableVertexAttribArray ( shaderProgram[SHADER_TTF_FONT].inVertsID );
//
// Specify the texture info
glVertexAttribPointer ( shaderProgram[SHADER_TTF_FONT].inTextureCoordsID, 2, GL_FLOAT, GL_FALSE, sizeof(_sdf_Vertex), (GLvoid*)offsetof(_sdf_Vertex, textureCoord) );
glEnableVertexAttribArray ( shaderProgram[SHADER_TTF_FONT].inTextureCoordsID );
//
// Specify the color array
glVertexAttribPointer ( shaderProgram[SHADER_TTF_FONT].inColorID, 4, GL_FLOAT, GL_FALSE, sizeof(_sdf_Vertex), (GLvoid*)offsetof(_sdf_Vertex, color) );
glEnableVertexAttribArray ( shaderProgram[SHADER_TTF_FONT].inColorID );
glBufferData ( GL_ELEMENT_ARRAY_BUFFER, sdf_indexes[whichFont].size() * sizeof(unsigned int), &sdf_indexes[whichFont], GL_DYNAMIC_DRAW ) );
glDrawElements ( GL_TRIANGLES, sdf_indexes[whichFont].size(), GL_UNSIGNED_INT, 0 ) );
Checking the vertex shader with renderDoc - I'm not seeing any of the sdf_vertex data coming through, or sometimes it's all scrambled. I think it's got to do with the how I'm trying to point glBufferData to the vector of structs inside an array.
How do I pass the location of the vector inside an array?
Thanks.