Welcome!

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

Reply
Contributor
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.

Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
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.