I am working on a problem where I need to draw a progressbar and need to calculate the length of the bar so as to display the progress on it. I am using OpenGL to draw my progressbar texture.
Can someone tell me how do I calculate the total length used by the drawing vertex buffer? Please guide.
I have my vertex buffer as following.
private float vertices[] = {
-1.5f, -0.20f, 0.0f, // V1 - bottom left
-1.5f, 0.20f, 0.0f, // V2 - top left
1.5f, -0.20f, 0.0f, // V3 - bottom right
1.5f, 0.20f, 0.0f // V4 - top right
};
In this case my texture loads inside this matrix. Can you explain how can I use calulations in my code to get width of this texture. What i’m trying to achieve here is to manipulate the vertex buffer for a progress bar on which I can show progress depending upon current value of data.
You put the data in the buffer, so you should know what’s in it. OpenGL has no concept of “object” or “width” or anything of that nature. All it knows is that you sent it some triangles to draw.
If you want to know the “width” of the output triangles, then you’re going to have to do the transformations yourself on the CPU. Don’t read it back from the buffer object; just keep a copy manually.