Motorola Droid / Milestone and Vertex Arrays

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Motorola Droid / Milestone and Vertex Arrays

Postby Patton » Wed Feb 24, 2010 10:20 pm

Has somebody also encountered problems while rendering vertex arrays on Motorola devices? I've heard that the Motorola has some issues in the OpenGL driver, and can't handle VBO's. I use regular vertex arrays in my application:

Code: Select all
private FloatBuffer vertexBuffer;

ByteBuffer bb = ByteBuffer.allocateDirect(4 * 4);
bb.order(ByteOrder.nativeOrder());
vertexBuffer = bb.asFloatBuffer();

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);


And it causes a crash, without any exceptions, it just pops out to "desktop".

Any ideas?
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Top

Postby Patton » Fri Feb 26, 2010 10:41 am

I have a little update about this issue.

Motorola crashes when I use glDrawArrays with GL_COLOR_ARRAY state enabled.
Here's the updated example.

Code: Select all
ByteBuffer bb = ByteBuffer.allocateDirect(4 * 4);
bb.order(ByteOrder.nativeOrder());
vertexBuffer = bb.asFloatBuffer();

ByteBuffer bb = ByteBuffer.allocateDirect(4 * 4);
bb.order(ByteOrder.nativeOrder());
colorBuffer= bb.asFloatBuffer();

// ... fill out vertex and color data ... //

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColorPointer(3, GL10.GL_FLOAT, 0, colorBuffer);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);


I still don't know what's the problem. I'll try with non-float color values.
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby zorro » Fri Feb 26, 2010 1:50 pm

Try and make the color array a 4-float type: RGBA. I read somewhere that this is the 'safe' way to use color arrays in Android.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Kernle 32DLL » Fri Feb 26, 2010 4:22 pm

It's a known Android 2.0 Issue (see this link). Seems like Android 2.0+ forces a use of 4 color values per vertex.

Altough i think you have a completely different problem. Why do you create a 4*4 Buffer for Vertex and Color Buffers? This means you get for both buffers 4 float values. Not only do you use for the actual Drawing only 3 values, but in total you only have 1 vertex in your buffer. But the actual drawing wants to draw 4 vertexes, causing a memory violation.

For more detailed information, read here:
ByteBuffer.asFloatBuffer
glColorPointer
glVertexPointer
glDrawArrays

So long,
Kernle
Kernle 32DLL
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Feb 26, 2010 4:18 pm

Postby Patton » Fri Feb 26, 2010 8:34 pm

A 4-float type color array (RGBA) does the magic on Motorola :) I only hope that all other devices on which the game currently works with 3 values, will handle correctly now the 4 values as well.

Thanks!!!

@Kernle 32DLL
That 4*4 Buffer for vertex and colors was only an example to draw a quad. In my game I use different sizes of buffers.
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby eyebex » Thu Apr 08, 2010 8:15 am

Some misc. notes on this issue:

1) The OP is not using VBOs, but regular vertex arrays. This is just to make sure people understand that this issue does not only occur with VBOs.

(Will be continued in a second post below because I cannot post a URL in my first post, doh!)
eyebex
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 08, 2010 8:05 am

Top

Postby eyebex » Thu Apr 08, 2010 8:16 am

2) If linking to glColorPointer documentation, you should use the right one, namely the one for OpenGL ES, not for regular OpenGL. As you can see, they differ in this particular point:
Specifies the number of components per color. Must be 4. The initial value is 4.

So strictly spoken, this is not a Milestone / Android issue, but a documented OpenGL ES limitation. It's just pure luck if other values than 4 work for "size" on your device.
eyebex
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 08, 2010 8:05 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests