Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Draw between 2 layers of the same VBO  (Read 893 times)
0 Members and 1 Guest are viewing this topic.
Offline vastrolorde

Junior Member





« Posted 2014-04-12 07:39:24 »

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.
Offline quew8

JGO Coder


Medals: 29



« Reply #1 - Posted 2014-04-12 13:29:09 »

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.
Offline vastrolorde

Junior Member





« Reply #2 - Posted 2014-04-12 15:35:32 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline quew8

JGO Coder


Medals: 29



« Reply #3 - Posted 2014-04-12 16:23:48 »

So disable depth testing. Draw the background, draw the foreground, draw the frame.
Offline vastrolorde

Junior Member





« Reply #4 - Posted 2014-04-14 14:18:19 »

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.
Offline quew8

JGO Coder


Medals: 29



« Reply #5 - Posted 2014-04-15 15:02:20 »

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.
Offline vastrolorde

Junior Member





« Reply #6 - Posted 2014-04-15 15:42:49 »

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.
Offline quew8

JGO Coder


Medals: 29



« Reply #7 - Posted 2014-04-15 16:46:45 »

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.
Offline vastrolorde

Junior Member





« Reply #8 - Posted 2014-04-16 10:40:19 »

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
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],
                  });
               }
            }
         }
      }      
   }
Offline quew8

JGO Coder


Medals: 29



« Reply #9 - Posted 2014-04-16 18:02:51 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vastrolorde

Junior Member





« Reply #10 - Posted 2014-04-18 11:39:48 »

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.
Offline quew8

JGO Coder


Medals: 29



« Reply #11 - Posted 2014-04-18 12:39:54 »

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.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!