LWJGL Forum

Programming => OpenGL => Topic started by: DustWorm2 on June 05, 2005, 14:25:15

Title: glVertexPointer and FloatBuffer error
Post by: DustWorm2 on June 05, 2005, 14:25:15
Hi There
I am trying to use glVertexPointer ( and all those Pointers ), however. I get an error with a FloatBuffer (one of the arguments required ). Oh, and I do not know exactlly how to use FloatBuffer. Please help me to point out the err in my logic.

I am tyring to draw simple quad in here

declaration
private final float quadVertices[] =  { 1f,  1f, -5,
                  -1f, -1f, -5,
                    1f, -1f, -5,
                   1f,  1f, -5 };



and in the create mode

GL11.glVertexPointer( 3, GL11.GL_FLOAT,  FloatBuffer.wrap( quadVertices ));


error

java.lang.IllegalArgumentException: FloatBuffer is not direct

Again, as in my GLUT topic I am just trying to follow my new OpenGL book and this time it seems that the technique is cool but a shame is I cannot port it into Java.

Regards
:D
Title: glVertexPointer and FloatBuffer error
Post by: Matzon on June 05, 2005, 14:47:45
You need to create a direct float buffer.
You could use BufferUtils.createFloatBuffer
Title: glVertexPointer and FloatBuffer error
Post by: DustWorm2 on June 06, 2005, 12:10:52
Hey
Thanks for the reply. I am almost done with it, however. It looks like there is a mistake in my code and I cannot find it. Here is what I got: (mehtod to render simple quad )

public void quad(){

GL11.glEnableClientState( GL11.GL_VERTEX_ARRAY );
GL11.glEnableClientState( GL11.GL_COLOR_ARRAY );


GL11.glPolygonMode( GL11.GL_FRONT, GL11.GL_FILL );
GL11.glRotatef( rot, 0f, 0f, 1f );
      
FloatBuffer colorsBuffer = BufferUtils.createFloatBuffer( 12 );
FloatBuffer quadBuffer = BufferUtils.createFloatBuffer( 12 );
      
colorsBuffer.put( quadColors );
quadBuffer.put( quadVertices );

GL11.glColorPointer( 3, GL11.GL_FLOAT, colorsBuffer );
GL11.glVertexPointer( 3,GL11.GL_FLOAT, quadBuffer );
      
}
   
The problem is that the Quad I am trying to draw is not being rendered. Any ideas?
Title: hmmmmmm.....
Post by: Fool Running on June 06, 2005, 13:43:07
You need to call a render method for the arrays you set up:

GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 12);

(Or something simmilar  :lol: )
Title: glVertexPointer and FloatBuffer error
Post by: DustWorm2 on June 07, 2005, 02:35:04
Thanks a lot that actually help. Silly me, I was reading book and stopped to jump into codeing without reading further on that topic.
Regards

Oh and if anyone else has a problem with that, drop me a note and I will post a code.
Title: glVertexPointer and FloatBuffer error
Post by: tiagocoutinho on December 11, 2005, 19:15:37
Quote from: "DustWorm2"
Oh and if anyone else has a problem with that, drop me a note and I will post a code.

Hi. I am a Direct3D programmer.
I am having trouble making VBs work with LWJGL.
I would appreciate if you post the code.

Thank you in advance

Tiago