views:

19

answers:

0

Is it possible to use per vertex data interleaved in OpenGL ES on Android?

I'm unable to get the correct offset pointers for the normal and color members.

In C++ I would do something like this:

struct ColoredVertexData3D{
    Vertex3D    vertex;
    Vector3D    normal;
    ColorRGBA   color;
};

const ColoredVertexData3D vertexData[] =
{
    {
        {0.0f, 0.5f, 0.8f},       // Vertex |
        {0.0f, 0.4f, 0.6f},       // Normal | Vertex 0
        {1.0f, 0.0f, 0.0f, 1.0f}  // Color  |
    },
    {
        {0.8f, 0.0f, 0.5f},       // Vertex |
        {0.6f, 0.0f, 0.4f},       // Normal | Vertex 1
        {1.0f, 0.5f, 0.0f, 1.0f}  // Color  |
    },
    // ... more vertexes.
};

const int stride = sizeof(ColoredVertexData3D);
glVertexPointer(3, GL_FLOAT, stride, &vertexData[0].vertex);
glColorPointer(4, GL_FLOAT, stride, &vertexData[0].color);
glNormalPointer(GL_FLOAT, stride, &vertexData[0].normal);

Is the same thing possible on Android in Java? This is what I currently got:

ByteBuffer vertexData = ...;
int stride = 40;

gl.glVertexPointer(3, GL10.GL_FLOAT, stride, vertexData);

// This obviously doesn't work. ------------v
gl.glColorPointer(4, GL10.GL_FLOAT, stride, &vertexData[0].color);
gl.glNormalPointer(GL10.GL_FLOAT, stride, &vertexData[0].normal);