Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
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  
  My code has a LWJGL and Vertex Array problem.  (Read 1955 times)
0 Members and 1 Guest are viewing this topic.
Offline ap_kelly

Junior Devvie




Java rocks!


« Posted 2004-02-26 08:55:04 »

I have the following code in my test app and I can see a square as expected when I run. However when I enable the color array bits, my square disapears, has any got any idea why?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
    float[] lvColours  = {0f, 1f, 0.5f, 1.0f, 0f, 1f, 0.5f, 1.0f, 0f, 1f, 0.5f, 1.0f, 0f, 1f, 0.5f, 1.0f};
    float[] lvVertices = {-150f, -150f, -50f, -150f, 150f, -50f, 150f, 150f, -50f, 150f, -150f, -50f};

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

    GL.glVertexPointer(3, GL.GL_FLOAT, 0, lvVertices);
//    GL.glColorPointer (4, GL.GL_FLOAT, 0, lvColours);

    GL.glDrawArrays(GL.GL_QUADS, 0, lvVertices.length / 3);

    GL.glDisableClientState(GL.GL_VERTEX_ARRAY);
//    GL.glDisableClientState(GL.GL_COLOR_ARRAY);


I read somewhere that the only valid value for the size parameter on the glColorPointer method is 4, but I have also tried it with the value of 3 and removed the alpha values from my colour array, but still nothing.

Thanks,

Andy.

PS: I have some nice wrapper classes that use a scratch buffer so that I can pass float[] to my methods rather than have the buffer conversions all over the place.

Online princec

« JGO Spiffy Duke »


Medals: 421
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-02-26 09:04:17 »

I point the finger of blame here at the wrapper. Let's see it.

Cas Smiley

Offline ap_kelly

Junior Devvie




Java rocks!


« Reply #2 - Posted 2004-02-26 09:16:12 »

I borrowed this code from the forums on the puppygames.net website.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
  private static       ByteBuffer scratch;
  private static final int        FLOAT_SIZE = 4;
  private static final int        BUFFER_SIZE = 8192 * 1024 * FLOAT_SIZE;

  static {
    scratch = ByteBuffer.allocateDirect(BUFFER_SIZE);
    scratch.order( ByteOrder.nativeOrder() );
  }
   
  private static FloatBuffer toBuffer( float[] params ) {
    scratch.clear();
    FloatBuffer buff = scratch.asFloatBuffer();
    buff.put( params );
    buff.flip();
    return buff;
  }
   
  public static void glVertexPointer( int size, int type, int stride, float[] buffer ) {
    glVertexPointer( size, stride, toBuffer( buffer ) );
  }

  public static void glColorPointer( int size, int type, int stride, float[] buffer ) {
    glColorPointer( size, stride, toBuffer( buffer ) );
  }


Any thoughts would be appreciated.

Thanks,

Andy.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online princec

« JGO Spiffy Duke »


Medals: 421
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2004-02-26 10:13:25 »

Duh Smiley You are simply overwriting your vertex data with colour data  Roll Eyes You need another buffer for the colour data. Or to interleave your data.

Cas Smiley

Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #4 - Posted 2004-02-26 12:00:18 »

Yeah, the gl*Pointer methods tell the GL where to find the data when needed, they don't upload it at that time.  When you get to glDrawArrays it then spools all the data from the buffers you mentioned.

Easiest fix, maintain a separate scratch buffer for each data type.

Hellomynameis Charlie Dobbie.
Offline ap_kelly

Junior Devvie




Java rocks!


« Reply #5 - Posted 2004-02-26 20:15:26 »

Thanks for the tip, I had the impression that when I called glVertexPointer and glColorPointer that the data would be referenced and used immidiately, not later when I call glDrawArray.

I guess the clue to the answer for this one could have been in the method names gl*Pointer

Mulitple buffers it is then!

Thanks,

Andy.

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.

xFryIx (58 views)
2014-11-13 12:34:49

digdugdiggy (37 views)
2014-11-12 21:11:50

digdugdiggy (30 views)
2014-11-12 21:10:15

digdugdiggy (24 views)
2014-11-12 21:09:33

kovacsa (48 views)
2014-11-07 19:57:14

TehJavaDev (51 views)
2014-11-03 22:04:50

BurntPizza (51 views)
2014-11-03 18:54:52

moogie (66 views)
2014-11-03 06:22:04

CopyableCougar4 (64 views)
2014-11-01 23:36:41

DarkCart (150 views)
2014-11-01 14:51:03
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!