Game Development Reference
In-Depth Information
public void bind() {
GL10 gl = glGraphics.getGL();
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
vertices.position(0);
gl.glVertexPointer(2, GL10.GL_FLOAT, vertexSize, vertices);
if if(hasColor) {
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
vertices.position(8);
gl.glColorPointer(4, GL10.GL_FLOAT, vertexSize, vertices);
}
if (hasTexCoords) {
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
vertices.position(hasColor?24:8);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, vertexSize, vertices);
}
}
// rest as before
Listing 13-8. Excerpt of Vertices3.java, Using JniUtils
public class Vertices3 {
final GLGraphics glGraphics;
final boolean hasColor;
final boolean hasTexCoords;
final boolean hasNormals;
final int vertexSize;
final ByteBuffer vertices;
final ShortBuffer indices;
public Vertices3(GLGraphics glGraphics, int maxVertices, int maxIndices,
boolean hasColor, boolean hasTexCoords, boolean hasNormals) {
this .glGraphics = glGraphics;
this .hasColor = hasColor;
this .hasTexCoords = hasTexCoords;
this .hasNormals = hasNormals;
this .vertexSize = (3 + (hasColor ? 4 : 0) + (hasTexCoords ? 2 : 0)+(hasNormals ? 3 : 0)) * 4;
this .vertices = ByteBuffer.allocateDirect(maxVertices * vertexSize);
this .vertices.order(ByteOrder.nativeOrder());
if (maxIndices > 0) {
ByteBuffer buffer = ByteBuffer.allocateDirect(maxIndices * Short.SIZE / 8);
buffer.order(ByteOrder.nativeOrder());
this .indices = buffer.asShortBuffer();
} else {
this .indices = null;
}
}
Search WWH ::




Custom Search