Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 20
Registered: ‎11-15-2010
My Device: Not Specified

Passing FloatBuffer to gl.glVertexPointer()

[ Edited ]

I am passing a FloatBuffer that was created with the FloatBuffer.wrap command, and remarkably the code throws a java.lang.IllegalArgumentException when I call:

FloatBuffer floatbuffer = FloatBuffer.wrap( myArrayOfFloats ) ;
gl.glVertexPointer( 3, GL10.GL_FLOAT, 0, floatbuffer ); /// ILLEGALARGUMENTEXCEPTION

Where myArrayOfFloats is just a plain ol' array of floats.

It works, however, when I use the example's way of FIRST doing allocation, then saving the contents of an array of floats using the FloatBuffer.put() method:

floatbuffer = ByteBuffer.allocateDirect( (myArrayOfFloats.length)*4 ).asFloatBuffer();
floatbuffer.put( myArrayOfFloats );
floatbuffer.rewind(); // Gotcha!!

I'm not sure why its not working when I DO NOT use allocateDirect.

Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-, Z10 (STL100-3)-, Z30 (STA100-5)-, Passport (SQW100-1)-, PlayBook (16GB)-
My Carrier: Verizon

Re: Passing FloatBuffer to gl.glVertexPointer()

What message does the exception say or is there no message?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.