Code example for GL11

Methods: glBindBuffer, glBufferData, glGenBuffers, glGetError

0
			if (gl instanceof GL11) {
				GL11 gl11 = (GL11) gl;
				int[] buffer = new int[1];
 
				// Allocate and fill the vertex buffer. 
				gl11.glGenBuffers(1, buffer, 0);
				mVertBufferIndex = buffer[0];
				gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertBufferIndex);
				final int vertexSize = mVertexBuffer.capacity()
						* mCoordinateSize;
				gl11.glBufferData(GL11.GL_ARRAY_BUFFER, vertexSize,
						mVertexBuffer, GL11.GL_STATIC_DRAW);
 
				// Allocate and fill the texture coordinate buffer. 
				gl11.glGenBuffers(1, buffer, 0);
				mTextureCoordBufferIndex = buffer[0];
				gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER,
						mTextureCoordBufferIndex);
				final int texCoordSize = mTexCoordBuffer.capacity()
						* mCoordinateSize;
				gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoordSize,
						mTexCoordBuffer, GL11.GL_STATIC_DRAW);
 
				// Unbind the array buffer. 
				gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
 
				// Allocate and fill the index buffer. 
				gl11.glGenBuffers(1, buffer, 0);
				mIndexBufferIndex = buffer[0];
				gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER,
						mIndexBufferIndex);
				// A char is 2 bytes. 
				final int indexSize = mIndexBuffer.capacity() * 2;
				gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, indexSize,
						mIndexBuffer, GL11.GL_STATIC_DRAW);
 
				// Unbind the element array buffer. 
				gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
 
				mUseHardwareBuffers = true;
 
				assert mVertBufferIndex != 0;
				assert mTextureCoordBufferIndex != 0;
				assert mIndexBufferIndex != 0;
				assert gl11.glGetError() == 0;
 
			} 
		} 
	}