Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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  
  Is this the best way to work VBOs?  (Read 382 times)
0 Members and 1 Guest are viewing this topic.
Offline DazKins
« Posted 2013-05-12 14:11:53 »

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  
33  
public class RenderEngine {
   private FloatBuffer fb;
   int vch = 1;

public RenderEngine() {
fb = BufferUtils.createFloatBuffer(100 * 10 * 10 * 6 * 4 * 6);

//place stuff in fb

 fb.flip();
}
public void render() {
      if(!bFlipped) {
         fb.flip();
         bFlipped = true;
      }

      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);

      glBindBufferARB(GL_ARRAY_BUFFER_ARB, vch);
      glBufferDataARB(GL_ARRAY_BUFFER_ARB, fb, GL_STATIC_DRAW_ARB);
      glVertexPointer(3, GL_FLOAT, (3 * 2) << 2, 0);
      glColorPointer(3, GL_FLOAT, (3 * 2) * 4, 3 * 4);

      glDrawArrays(GL_QUADS, 0, fb.capacity() / 4);

      glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

      glDisableClientState(GL_COLOR_ARRAY);
      glDisableClientState(GL_VERTEX_ARRAY);
   }
}


This code seems somewhat inefficient to me for a number of reasons:
  • The vch variable is defaulted to 1 and I'm not really 100% sure why this works, I imagine this is used for rendering multiple VBOs
  • Every time I go to render the VBO, i redo the glBufferData() call, I have seen examples where people call this once when they initialise the VBO and not every render cycle

If anyone could give me any pointers on mistakes I have made please let me know.
(please note, this code does work, I just don't see it as very efficient which is why I'm asking)

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline davedes
« Reply #1 - Posted 2013-05-12 14:32:51 »

You should use glGenBuffers to get the VBO handle.

glBufferData uploads the float buffer data to your VBO. You don't need to call it every frame unless your data is changing every frame. In your render function, you just need to enable client states, setup vertex pointers, and draw arrays.

VBOs is core as of GL 1.5 so you really should not be using ARB unless you are targeting computers from the 90s. Tongue

Also I'm not sure why you are flipping buffers like that. You can read more about buffers here:
https://github.com/mattdesl/lwjgl-basics/wiki/Java-NIO-Buffers

Offline DazKins
« Reply #2 - Posted 2013-05-12 17:44:15 »

Ok, thanks I've made some changes now. Thanks for the info about ARB buffers aswell, i thought they were the more modern version of OpenGL.

Thanks a bunch  Grin

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-27 04:03:04

TheDudeFromCI (14 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (85 views)
2014-12-05 12:39:02

SHC (95 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!