Is there a way to add objects to VBO that werent there before? Im trying to create a minimap. Black backround and then objects in the space are shows as arrows or squares or whatever shapes.
If the VBO is large enough then yes, you can use any of a couple of functions to change the data in the VBO.
glBufferSubData(): http://www.opengl.org/sdk/docs/man2/xhtml/glBufferSubData.xml
glMapBuffer(): http://www.opengl.org/sdk/docs/man2/xhtml/glMapBuffer.xml
If the VBO is no big enough then no you can’t. But all you have to do is create a VBO big enough for whatever you might need in the future. Anything you aren’t using you can just leave empty.
A little LWJGL tutorial here on glBufferSubData: http://lwjgl.org/wiki/index.php?title=The_Quad_updating_a_VBO_with_BufferSubData. It’s part of a series but you can take a look at the source code at the end for a summary.
I have used BufferSubData before. But how can i draw between the 2 layer of VBO. I have the black background and the frame that goes over it. And the part i want to add must be above the background but below the frame.
So disable depth testing. Draw the background, draw the foreground, draw the frame.
BufferSubData doesent add data to buffer, it only changes them. But how can i add data to buffer that wasnt there before. I have 16 entrys to the buffer. But now i would add another 40 entryes to the top of the 16 that are already there. And it would be nice also if i could use the same metohd to delete entryes that are no longer needed.
You need to change the way you think about VBOs. A VBO is just a list of numbers, think of it as an array on the GPU.
So if you have an array of data in Java and you wanted to add more data to it, how would you do it? You can’t, you would have to reinitialize the array with a larger size and copy all of the original data into it and then put the new data in as well. Exactly the same with a VBO in OpenGL. If you want to add more entries, delete the VBO and create a new VBO with enough space.
And you can always create a VBO larger than you need at that moment. Leave the bits you aren’t using empty and don’t draw them.
So essentially what you need is a system to manage each VBO. It needs to remember what bits of the VBO are being used and which bits are not. When you want to “delete” an entry, mark it as not being used and don’t draw it. When you want to “add” an entry, overwrite a section that isn’t being used. If there are no sections that aren’t being used then you have to reinitialize the VBO with more space or use a different VBO.
I have initialized a VBO large enoug to fit 50 object. At first only 2 are inserted and drawn. Then with the first update, a separate buffer is written which has 20-30 object coordinates in it. Now i would like to add the second buffer to the first one. But for somereason it is not happening. If lucky i get only 1 object in. So something somewhere is wrong.
I agree but without code, I can’t help diagnose bugs. If I were you, I would look at the contents of the VBO before adding the extra data versus after adding (you can use the glGetBufferSubData() function) for debugging purposes. It can be extremely tedious but often will reveal the pattern which will let you solve the bug.
I have found the location of my problem, but i cant understand why it does that.
The buffer that holds the new data hold data only for 1 element. althoufgh there are 42 elements worth of data.
public void update(float dt) {
if(render){
Entitys = world.getVisualEntities();
PLoc = player.getPosition();
for(VisualEntity e: Entitys){
System.out.println(e);
if(e instanceof StaticEntity){
Vector3f pos = e.getPosition();
if(Entitydistance(PLoc, pos) < 1800){
pos.set(width/2 + (PLoc.x - pos.x)/5, heigth/2 + (PLoc.y - pos.y)/5, 0);
verticesChange.put(new float[]{
pos.x, pos.y - 2.5F,
pos.x - 2.5F, pos.y + 2.5F,
pos.x + 2.5F, pos.y + 2.5F,
pos.x, pos.y - 2.5F
});
texVerticesChange.put(new float[]{
RenderThread.spritesheet.getUpLeftCoordNormal(51)[0],
RenderThread.spritesheet.getUpLeftCoordNormal(51)[1],
RenderThread.spritesheet.getBottomLeftCoordNormal(51)[0],
RenderThread.spritesheet.getBottomLeftCoordNormal(51)[1],
RenderThread.spritesheet.getBottomRightCoordNormal(51)[0],
RenderThread.spritesheet.getBottomRightCoordNormal(51)[1],
RenderThread.spritesheet.getUpRightCoordNormal(51)[0],
RenderThread.spritesheet.getUpRightCoordNormal(51)[1],
});
}
}
}
}
}
I can’t see any problems. All I would say is check the position of “verticesChange” and “texVerticesChange” before each “put.” That’s generally the cause of problems but I can’t see any reason it wouldn’t work here.
I found the problem. My teamate, had made a hes own buffersubdata class. It uses the original stuff, but the methods you get to use are a bit different. He made it so that when you but data into buffer, then it automatically rewinds it. So i modified it so that it would rewind only when i order it to rewind.
Well my advice is in the future always document your code, especially when it has some unpredictable behaviour like that. It is very useful when working alone but when in a team it is, as you have just found at, a necessity. For most methods it is obvious what they do so just a note of any odd behaviour is needed, not the essays you find in the standard library.