Code example for FloatBuffer

Methods: clear, position, put

0
	 
	public static final FloatBuffer makeVerticesBuffer(float[] arr) {
		FloatBuffer fb = null;
		if (polygonVerticesPool.containsKey(arr.length)) {
			fb = polygonVerticesPool.get(arr.length);
			fb.clear();
			fb.put(arr);
			fb.position(0);
			return fb;
		} 
		fb = makeFloatBuffer(arr);
		polygonVerticesPool.put(arr.length, fb);
		return fb;
	} 
	 
	public static final FloatBuffer makeColorsBuffer(float[] arr) {
		FloatBuffer fb = null;
		if (polygonColorsPool.containsKey(arr.length)) {
			fb = polygonColorsPool.get(arr.length);
			fb.clear();
			fb.put(arr);
			fb.position(0);
			return fb;
		} 
		fb = makeFloatBuffer(arr);
		polygonColorsPool.put(arr.length, fb);
		return fb;
	} 
	 
	public static final FloatBuffer makeTexCoordsBuffer(float[] arr) {
		FloatBuffer fb = null;
		if (texCoordsPool.containsKey(arr.length)) {
			fb = texCoordsPool.get(arr.length);
			fb.clear();
			fb.put(arr);
			fb.position(0);
			return fb;
		} 
		fb = makeFloatBuffer(arr);
		texCoordsPool.put(arr.length, fb);
		return fb;
	} 
	 
	//���t�@�N�^�����O 
	public static final void drawSquare(GL10 gl) {
		drawSquare(gl, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	} 
	 
	//�|���S�����`�悷�郁�\�b�h 
	public static final void drawSquare(GL10 gl, float x, float y, float r, float g, float b, float a) {
		float[] vertices = {
				-0.5f + x, -0.5f + y,
				 0.5f + x, -0.5f + y,
				-0.5f + x,  0.5f + y,
				 0.5f + x,  0.5f + y,
		}; 
		 
		float[] colors = {
				r, g, b, a,
				r, g, b, a,
				r, g, b, a,
				r, g, b, a,
		}; 
		 
		//�錾�����|���S�����W�ƐF���V�X�e�����̃������Ɋm�ۂ��Ă��� 
		FloatBuffer squareVertices = makeVerticesBuffer(vertices);
		FloatBuffer squareColors = makeColorsBuffer(colors);
		 
		//�|���S�����`�悵�Ă��� 
		gl.glVertexPointer(2, GL10.GL_FLOAT, 0, squareVertices);
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glColorPointer(4, GL10.GL_FLOAT, 0, squareColors);
		gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
		 
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
	}