Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  opengl.util.BufferUtil and VBO  (Read 1407 times)
0 Members and 1 Guest are viewing this topic.
Offline blizzard

JGO n00b
*

Posts: 19



« on: 2011-10-13 04:50:19 »

Hello

I start using VBO´s and saw different ways to initialize the buffers.
One is using the opengl.util.BufferUtil classes.

Is this the best way and where do I get it ?
thanks
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #1 on: 2011-10-13 05:30:16 »

Yes. BufferUtil ensures that the byte buffer created is direct and that the correct byte order (native byte order) is used. It's basically equal to:
1  
ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());

There is no god.
Offline blizzard

JGO n00b
*

Posts: 19



« Reply #2 on: 2011-10-13 06:26:08 »

Ok, thanks

but where can I download it ? It was not in the packages that I have downloaded for using jogl.

Games published by our own members! Go get 'em!
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #3 on: 2011-10-13 09:17:38 »

Ah, you're using JOGL. BufferUtil is part of LWJGL, which is an alternative to JOGL. Personally I prefer LWJGL, but you can just make your own utility class for buffer creation. To create other buffers (FloatBuffer for example) just create a ByteBuffer (with the code I posted) with 4 times the size (as you'll need 4 bytes per float) and use asFloatBuffer().

There is no god.
Offline sproingie

JGO Strike Force
***

Posts: 899
Medals: 55



« Reply #4 on: 2011-10-13 11:56:41 »

If you're using JOGL, you don't use ByteBuffers.  You should be able to use a plain-jane array.

Offline Z-Knight

Full Member
**

Posts: 234



« Reply #5 on: 2011-10-13 12:26:07 »

Ah, you're using JOGL. BufferUtil is part of LWJGL, which is an alternative to JOGL. Personally I prefer LWJGL, but you can just make your own utility class for buffer creation. To create other buffers (FloatBuffer for example) just create a ByteBuffer (with the code I posted) with 4 times the size (as you'll need 4 bytes per float) and use asFloatBuffer().

wait, what?!?  BufferUtil is part of JOGL... it is in: com.sun.opengl.util.BufferUtil

So this is what I usually do:
1  
vertices = ByteBuffer.allocateDirect(totalBuffer * BufferUtil.SIZEOF_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();


You also need to remember to 'rewind' the buffer, I think:

1  
vertices.rewind();
Online ra4king

JGO Kernel
*****

Posts: 3159
Medals: 196


I'm the King!


« Reply #6 on: 2011-10-13 17:35:55 »

No you don't rewind the buffer, you flip it:
1  
vertices.flip();

Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #7 on: 2011-10-13 18:13:04 »

Hi

Ok, thanks

but where can I download it ? It was not in the packages that I have downloaded for using jogl.
I assume you use an obsolete version of JOGL (JOGL 1.1.1a?). In JOGL 2.0, this class has been renamed Buffers:
http://jogamp.org/deployment/jogamp-next/javadoc/gluegen/javadoc/com/jogamp/common/nio/Buffers.html

I'm sorry, I was busy and many people here gave you confusing answers. I advise you to ask questions specific to JOGL on the official JogAmp forum. Best regards.

Julien Gouesse
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #8 on: 2011-10-13 22:17:26 »

Ignore me, listen to the JOGL expert!  Yawn

There is no god.
Offline blizzard

JGO n00b
*

Posts: 19



« Reply #9 on: 2011-10-14 03:23:03 »

Ok I ignore you ;-)

thanks for all your answers
Games published by our own members! Go get 'em!
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #10 on: 2011-10-14 06:08:27 »

Hi

Ignore me, listen to the JOGL expert!  Yawn
Sorry, I didn't want to be harsh with you and the class Buffers from JOGL works like the class used by our competitor you quoted.

blizzard, I hope you now understand that you don't need to download another JAR to use the class Buffers. Actually, I assume you were speaking about com.sun.opengl.utils.BufferUtils which was in JOGL 1.1.1a and renamed com.jogamp.common.nio.Buffers in JOGL 2.0.

Julien Gouesse
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #11 on: 2011-10-14 07:10:49 »

Nonono, I wasn't insulted at all, I just felt a little ashamed because I was talking out of my ass! xD

There is no god.
Offline blizzard

JGO n00b
*

Posts: 19



« Reply #12 on: 2011-10-14 07:46:00 »

Yes I understand, I found everything  and at the moment my first VBO test programms  are running well :-)
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.14 seconds with 21 queries.