GLUtilities.java
Dosyayı İndir
package com.godoro.androidopengl;
import android.graphics.*;
import android.opengl.*;
import java.nio.*;
import javax.microedition.khronos.opengles.*;
public class GLUtilities {
public static FloatBuffer toFloatBuffer(float[] floatArray) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(floatArray.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
floatBuffer.put(floatArray);
floatBuffer.position(0);
return floatBuffer;
}
public static ShortBuffer toShortBuffer(short[] shortArray) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(shortArray.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
shortBuffer.put(shortArray);
shortBuffer.position(0);
return shortBuffer;
}
public static ByteBuffer toByteBuffer(byte[] byteArray) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(byteArray.length);
byteBuffer.put(byteArray);
byteBuffer.position(0);
return byteBuffer;
}
public static int loadTexture(GL10 gl,Bitmap bitmap){
int[] textures = new int[1];
gl.glGenTextures(1, textures, 0);
int textureId = textures[0];
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_REPEAT);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
return textureId;
}
}
Dosyayı İndir