Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  Revised glDrawRangeElements() question.  (Read 1459 times)
0 Members and 1 Guest are viewing this topic.
zahl2001
Guest
« Posted 2004-01-26 23:32:44 »

Thanks to others advice, I now have my program up and running.  The code excerpts below show (hopefully) the key parts of what I am currently doing, but now I am interested to see if someone can show me a more EFFICIENT way to do the same task.  I read something from Cas talking about the pointers to the vertex arrays working at top efficiency when they have a stride of 32 bytes, but I never got that off the ground.  

So...anyone is welcome to give me some code, OR, to tell me that they think the way I'm doing this is acceptable.

You'll notice I only have vertex data and color data, and this is due to the fact that I am only a beginner, so if someone wants to offer a solution that uses vertex, texture, and normal data that would be great.

This program draws a 3 sided pyramid with no bottom.

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  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
// "global" arrays

float[] vertexArray = {0, 0,  1,
                       1, 0, -1,
                      -1, 0, -1,
                       0, 1,  0};

float[] colorArray = {0, 0, 1,
                      0, 0, 1,
                      0, 0, 1,
                      1, 0, 0};

int[] geometryArray = {3, 0, 1,
                       3, 2, 0,
                       3, 1, 2};

FloatBuffer vertexBuffer;
FloatBuffer colorBuffer;

//-------------------------------------------

public void init (...)
{
    //...

    gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL.GL_COLOR_ARRAY);

    ByteBuffer buffer =
        ByteBuffer.allocateDirect( vertexArray.length * 4) ;
    buffer = buffer.order(ByteOrder.nativeOrder());
    vertexBuffer = buffer.asFloatBuffer();

    buffer =
        ByteBuffer.allocateDirect( colorArray.length * 4) ;

    buffer = buffer.order(ByteOrder.nativeOrder());
    colorBuffer = buffer.asFloatBuffer();

    vertexBuffer.put(vertexArray);
    colorBuffer.put(colorArray);

    vertexBuffer.position(0);
    gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);

    colorBuffer.position(0);
    gl.glColorPointer(3, GL.GL_FLOAT, 0, colorBuffer);
 
//-------------------------------------------

public void display(...)
{
    //...

   gl.glDrawRangeElements(GL.GL_TRIANGLES,
                          0,
                          3,
                          9,
                          GL.GL_UNSIGNED_INT,
                          geometryArray);
  


Thanks much for the help on this and everything else folks...if not for input from Cas and others I would never have gotten even THIS little program off the ground!
Offline HamsterofDeath

Junior Member




Java games rock!


« Reply #1 - Posted 2004-01-27 12:42:55 »

i'm currently working on an allrounder-class for vertex arrays, vertex buffer objects and whatever there is.

so far, it's able to use vertex data, normals, colors, vertex fog, and up to 4 textures, convert it into a static vbo, strip triangles, build an indexed array, and draw everything by using the good old gl*-commands.
it's still a bit buggy, but the vbos are working already.

if someone could explain the difference between vars and vbos (and show me how to use them), i'd maybe implement a vertexarray -> vertex array range conversion.

the only difference i see so far is that i allocate the vbos via glBindBuffer and genBuffer, while zahl2001 is using bytebuffers (where are they stored ? vbos are stored in the grapic cards ram, which makes them faster. does the bytebuffer something similar ?)

i'll post the source somewhere when it's done.
Offline tom
« Reply #2 - Posted 2004-01-27 14:02:35 »

vbos are more efficient than vars. There is a vbo whitepaper on nvidia: http://www.nvidia.com/object/using_VBOs.html

Storing the data in a bytebuffer just means it is on the native side of java. I guess it has to be that way because glVertexPointer creates a real point to the data. And it can't point into the java heap.

Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline HamsterofDeath

Junior Member




Java games rock!


« Reply #3 - Posted 2004-01-27 15:43:03 »

with gl4java, you can use java float arrays...
but i think you're right.

btw i just implemented a gl***-renderer for my vertexarray (to make a conversion into a displaylist possible):
the difference between optimized vbos and unoptimized gl-calls + getting vertex data out of floatbuffers per get() is extremely high.

i didn't measure it excactly, but i'd say vbo's are about 5-6 times faster
Offline tom
« Reply #4 - Posted 2004-01-27 16:51:27 »

What did you compare against? Did you use glVertex3f(), glTexCoord2f() etc, or vertex arrays? Would be interesting to compare it against display lists.

Offline HamsterofDeath

Junior Member




Java games rock!


« Reply #5 - Posted 2004-01-28 09:15:56 »

glvertex, glNormal, gl(multi)Texcoord(arb)
i'll run some benchmarks soon
zahl2001
Guest
« Reply #6 - Posted 2004-01-28 12:32:23 »

Are the VBOs specific to any one type of card?  Or will they work with any modern card?
Offline tom
« Reply #7 - Posted 2004-01-28 13:05:36 »

It's an ARB extension and is not vendor specific. Although I would think new cards will have the extension, you should check for it and provide a fallback.

Offline jeickmann

Senior Newbie




Java games rock!


« Reply #8 - Posted 2004-01-28 15:26:55 »

This page usually helps, if you want to know about extension support in different graphics-cards:

http://www.delphi3d.net/hardware/index.php

Here's the page for the VBO's:
http://www.delphi3d.net/hardware/extsupport.php?extension=GL_ARB_vertex_buffer_object
Offline quintesse

Junior Member




Java games rock!


« Reply #9 - Posted 2004-02-10 13:02:48 »

@HamsterOfDeath: how's the "all-rounder class" coming along? Writing one myself so I'm mighty interested in comparing it to yours Smiley (yours seems to support a lot more functionality so I might prefer using that one over mine anyway)
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline elias

Senior Member





« Reply #10 - Posted 2004-02-10 16:15:16 »

Tom: There's no reason all cards couldn't support VBO, so it's more a question of how recent your drivers are. VBOs work fine on plain old geforce 1, and probably all back to the tnts (but I don't have one of those).

- elias

Offline tom
« Reply #11 - Posted 2004-02-10 17:41:11 »

Yes. I found that out after checking out the excellent delphi3d.net link. According to it the TNT support vbos with new drivers, but a radeon 9500/9700 with old drivers do not have it.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (135 views)
2013-05-17 21:29:12

alaslipknot (144 views)
2013-05-16 21:24:48

gouessej (174 views)
2013-05-16 00:53:38

gouessej (168 views)
2013-05-16 00:17:58

theagentd (178 views)
2013-05-15 15:01:13

theagentd (162 views)
2013-05-15 15:00:54

StreetDoggy (207 views)
2013-05-14 15:56:26

kutucuk (231 views)
2013-05-12 17:10:36

kutucuk (230 views)
2013-05-12 15:36:09

UnluckyDevil (235 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.216 seconds with 25 queries.