Hey guys,
I'm currently working on making a text drawing module in my project. It's working for the most part but i'm having some trouble when trying to 'backspace' characters (removing a quad from the back of the buffer).
So at the moment this is how I'm doing things
1. Create a buffer object with a size enough to hold 120 or so characters (a character is a quad made up of 6 vertices)
2. When the user presses a key, add 6 new vertices to the end of the vbo (with correct tex coords for the character) using glBufferSubData
This works fine and I can add those 120 characters by pressing letters on the keyboard (It re-builds the buffer by another 120 characters when you reach the limit)
Now the problem is I want to erase a character when the backspace (39) key is pressed It doesnt visually appear to have an effect until you add another character.
Example use case:
- Press 'a'
- Press 'b'
- Press 'c'
- Press 'd'
My buffer contains 4 quads (each quad is 6 vertices) and on screen it prints "abcd" fine.
Now If i press backspace once it should read - "abc"
but it still reads - "abcd"
However if I add a new character say 'e' (after backspace) the text becomes - "abce". Which leads me to believe it did in fact remove the last quad from the buffer BUT was not updated till more data was written to that area of memory.
So it really did erase that character but it doesnt get updated till you add another quad
This is how I'm updating my buffer after a backspace:
void Text2D::PopLetter()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vbo->vData->m_vboId);
// remove 6 vertices from the end of the vector
m_vbo->vData->vertices.pop_back();
m_vbo->vData->vertices.pop_back();
m_vbo->vData->vertices.pop_back();
m_vbo->vData->vertices.pop_back();
m_vbo->vData->vertices.pop_back();
m_vbo->vData->vertices.pop_back();
int currSize = m_vbo->vData->vertices.size() * sizeof(Vertex);
int amountToOverwrite = sizeof(Vertex) * 6;
glBufferSubData(GL_ARRAY_BUFFER, currSize, amountToOverwrite, nullptr);
}
So after this function call, the last quad is still visible, yet when I add another character the old one is just replaced with the new one if that makes sense.
Is there a better way to do this?
Thanks guys