Alright, I am almost up and running following the information in this thread:
viewtopic.php?p=27227But, I am having a texture issue. I got a helicopter, it works fine with old school standard non-VBO style implementation.
But, with the VBO implementation the texture gets hosed. I can change the order of the verticies and salvage 3 out of 4 corner of the texture, but at best one corner of the texture is missing or corrupted.
Here is where I load the buffers. This texCoords array works fine in non-VBO mode but totally fails to show the texture in VBO mode. Also I have tried shading the quad with a color in VBO mode and it looks fine, so the shape is coming through fine. Its just the texture that is messed up.
Using java Syntax Highlighting
public class Sprite{
public Sprite(Context context, GL10 gl, int resourceId){
GL11 gl11 = (GL11)gl;
xPos = 0.25f;
yPos = 0.25f;
short[] mIndicesArray = {1,0,2,3};
float[] coords = {
-0.1f, -0.1f, 0f, //0 bottom left
-0.1f, 0.1f, 0f, //1 top left
0.1f, 0.1f, 0f, //2 top right
0.1f, -0.10f, 0f //3 bottom right
};
mNrOfVertices = 4;
float[] texCoords = {
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f
};
mContext = context;
loadTexture(gl,resourceId);
ByteBuffer vbb = ByteBuffer.allocateDirect(coords.length * 4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asFloatBuffer();
ByteBuffer ibb = ByteBuffer.allocateDirect(mIndicesArray.length * 2);
ibb.order(ByteOrder.nativeOrder());
mIndexBuffer = ibb.asShortBuffer();
ByteBuffer tbb = ByteBuffer.allocateDirect(texCoords.length * 4);
tbb.order(ByteOrder.nativeOrder());
mTexBuffer = tbb.asFloatBuffer();
mVertexBuffer.put(coords);
mIndexBuffer.put(mIndicesArray);
mTexBuffer.put(texCoords);
mVertexBuffer.position(0);
mIndexBuffer.position(0);
mTexBuffer.position(0);
int[] buffer = new int[1];
gl11.glGenBuffers(1, buffer, 0);
vertexBufferIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexBufferIndex);
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, 12 * 4, mVertexBuffer, GL11.GL_STATIC_DRAW);
gl11.glGenBuffers(1, buffer, 0);
textureBufferIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureBufferIndex);
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, 8 * 4, mTexBuffer, GL11.GL_STATIC_DRAW);
gl11.glGenBuffers(1, buffer, 0);
indexBufferIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBufferIndex);
gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, 4 * 2, mIndexBuffer, GL11.GL_STATIC_DRAW);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
}
Parsed in 0.037 seconds, using
GeSHi 1.0.8.4
And here is the portion where the quad gets drawn. currently the non-VBO lines are commented out.
Using java Syntax Highlighting
public void draw(GL10 gl, float angle, float x, float y) {
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glPushMatrix();
gl.glTranslatef(x, y, 0f);
gl.glRotatef(angle, 0.0f,0.0f, 1.0f);
GL11 gl11 = (GL11)gl;
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexBufferIndex);
gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
//gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureBufferIndex);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBufferIndex);
//gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);
gl11.glTexCoordPointer(3, GL11.GL_FLOAT, 0, 0);
//gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexBuffer);
//gl.glDrawElements(GL11.GL_TRIANGLE_STRIP, mNrOfVertices, GL11.GL_UNSIGNED_SHORT, mIndexBuffer);
gl11.glDrawElements(GL11.GL_TRIANGLE_STRIP, mNrOfVertices, GL11.GL_UNSIGNED_SHORT, 0);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
gl.glPopMatrix();
}
Parsed in 0.033 seconds, using
GeSHi 1.0.8.4
Any help here would be appreciated. I know the code is kind of messy and could be a lot better, but this is just a first pass trying to get anything to display correctly.