Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  [LWJGL] VBO and glDrawRangeElements (SOLVED)  (Read 1549 times)
0 Members and 1 Guest are viewing this topic.
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Posted 2013-02-11 08:08:39 »

Hi,

I have a bit difficulty to use glDrawRangeElements with VBO in LWJGL so I want to double check the use of :

1  
GL12.glDrawRangeElements(int mode, int start, int end, int indices_count, int type, long indices_buffer_offset)


I have created a VBO with several 3d model in it. I have checked the data that I parse to the GPU and they seems to be correct. When I draw the 1srt object, I have no problem. But when I want to draw the others, it is messed up. I think I have miss understand the meaning of the parameters of glDrawRangeElements :

1  
2  
3  
4  
5  
6  
7  
8  
ref.start = number of the first index
ref.size = number of index need to draw the model
GL12.glDrawRangeElements(GL11.GL_TRIANGLES ,
                                      ref.start,
                                      ref.start+ref.size,
                                      ref.size,
                                      GL11.GL_SHORT,
                                      0)
Offline StrideColossus
« Reply #1 - Posted 2013-02-11 09:54:10 »

A quick search seems to indicate that this is quite a common problem, the meaning of the parameters is not obvious (frankly it bamboozled me!) and I've never used this method or seen any tutorials/examples/demos that use it.

From what I've read it looks to me like the version you were trying to use is really aimed at vertex arrays anyway rather than VBOs per se (it was introduced into the 1.2 API), the parameters are odd because the OpenGL is attempting to optimise fetches of indices from memory to the GPU - not an issue if you're using VBOs and not vertex arrays.

Might have got the wrong end of the stick but that's what it looks like to me - any wiser souls know better?

As you're using LWJGL so can I suggest using one of the glDrawRangeElements(mode, start, end, index-buffer) methods which (if I understand what you're trying to achieve) will do what you want.

- stride
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #2 - Posted 2013-02-11 10:30:09 »

Thanks for the reply.

The problem with GL12.glDrawRangeElements(mode, start, end, index-buffer) is that it send the index buffer each time you call it. While GL12.glDrawRangeElements(int mode, int start, int end, int indices_count, int type, long indices_buffer_offset), the index buffer is send only once (at the loading of the models).

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StrideColossus
« Reply #3 - Posted 2013-02-11 11:15:38 »

The problem with GL12.glDrawRangeElements(mode, start, end, index-buffer) is that it send the index buffer each time you call it. While GL12.glDrawRangeElements(int mode, int start, int end, int indices_count, int type, long indices_buffer_offset), the index buffer is send only once (at the loading of the models).

Assuming you are using a index buffer (as opposed to a vertex array) for your indices they will only be uploaded once when you call glBufferData(), that's the whole point of VBOs - or am I missing the point?
Online theagentd
« Reply #4 - Posted 2013-02-11 13:38:09 »

Assuming you are using a index buffer (as opposed to a vertex array) for your indices they will only be uploaded once when you call glBufferData(), that's the whole point of VBOs - or am I missing the point?

I can confirm this. Now to work around the 90% quote limitation...

Myomyomyo.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2013-02-11 13:46:26 »

Please read the spec very carefully:
http://www.opengl.org/sdk/docs/man/xhtml/glDrawRangeElements.xml

You're doing it wrong Smiley

The parameters start and end contain the min and max values in the indices array.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #6 - Posted 2013-02-11 16:38:41 »

Darmn...
min = min of the whole indexes != min of the model indexes...
max = max of the whole indexes != max of the model indexes...

1  
2  
3  
4  
5  
6  
GL12.glDrawRangeElements(GL11.GL_TRIANGLES ,
                                      0,
                                      nbTotalVertex-1,
                                      ref.size,
                                      GL11.GL_UNSIGNED_SHORT,
                                      ref.start * 2) // * 2 since it is GL_UNSIGNED_SHORT


It work better now Cheesy thanks
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.

TehJavaDev (13 views)
2014-08-28 18:26:30

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

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

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

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

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

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

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

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

BurntPizza (34 views)
2014-08-08 02:01:56
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!