Hello Guest

glVertexPointer and FloatBuffer error

  • 5 Replies
  • 15513 Views
glVertexPointer and FloatBuffer error
« 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
-_-] Dust Worm [-_-] www.DustWormSoft.com [-_-]

*

Offline Matzon

  • *****
  • 2242
glVertexPointer and FloatBuffer error
« Reply #1 on: June 05, 2005, 14:47:45 »
You need to create a direct float buffer.
You could use BufferUtils.createFloatBuffer

glVertexPointer and FloatBuffer error
« Reply #2 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?
-_-] Dust Worm [-_-] www.DustWormSoft.com [-_-]

hmmmmmm.....
« Reply #3 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: )
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

glVertexPointer and FloatBuffer error
« Reply #4 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.
-_-] Dust Worm [-_-] www.DustWormSoft.com [-_-]

glVertexPointer and FloatBuffer error
« Reply #5 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