The parameters stride and pointer confuse me.
I have a vbo filled with float data on vertexPositions and textureCoords, created this way(may or may not be right):
glBindBuffer(GL_ARRAY_BUFFER, vboID);
vboList.add(vboID);
Vector4f vertices = new Vector4f();
Vector4f texCoords = new Vector4f();
TerrainTexture currentTex = null;
for (int x = 0; x < mapByteData.length; x++) {
for (int y = 0; y < mapByteData.length; y++) {
vertices.x = x * 16;
vertices.y = y * 16;
vertices.w = vertices.x + 16;
vertices.z = vertices.z + 16;
currentTex = textureMap.get(mapByteData[x][y]);
texCoords.x = currentTex.x;
texCoords.y = currentTex.y;
texCoords.w = texCoords.x + currentTex.w;
texCoords.z = texCoords.y + currentTex.h;
ArrayList<Float> blockCoords = new ArrayList<Float>(){{
add(vertices.x); add(vertices.y); add(texCoords.x); add(texCoords.y);
add(vertices.w); add(vertices.y); add(texCoords.w); add(texCoords.y);
add(vertices.w); add(vertices.z); add(texCoords.w); add(texCoords.z);
add(vertices.x); add(vertices.z); add(texCoords.x); add(texCoords.z);
}};
tempData.addAll(blockCoords);
}
}
FloatBuffer buffer = BufferUtils.createFloatBuffer((MAPSIZE*MAPSIZE) * (4 * 2) * (4 * 2));
int cnt = 0;
for (Float val : tempData) {
data[cnt] = val;
cnt++;
}
buffer.put(data);
buffer.flip();
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
(Tell me if you dont know what is happening above)
And then i draw the vbo like this:
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureSheetID);
glBindBuffer(GL_ARRAY_BUFFER, vboList.get(0));
glEnable(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 16, 0);
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 16, 2);
glDrawArrays(GL_QUADS, 0, MAPSIZE * MAPSIZE * 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
So i dont know what to put in the last 2 parameters of:
glVertexPointer(2, GL_FLOAT, 16, 0);
glTexCoordPointer(2, GL_FLOAT, 16, 2);
How the the data in the vbo is layed out(four lines for each 2d rect):
verticeX, verticeY, texCoordX, texCoordY,//TopLeft
verticeX, verticeY, texCoordX, texCoordY,//BottomLeft
verticeX, verticeY, texCoordX, texCoordY,//BottomRight
verticeX, verticeY, texCoordX, texCoordY,//TopRight
Thanks!(ask if anything is needed/questions)
EDIT:
I fixed it myself by putting the vertex and texture coords into separete vbo’s.