SimpleUtilities.java
Dosyayı İndir
package com.godoro.androidopengl;
import android.content.*;
import android.graphics.*;
import android.opengl.*;
import java.nio.*;
import javax.microedition.khronos.opengles.*;
public class SimpleUtilities {
public static FloatBuffer toFloatBuffer(float[] floatArray,int factor) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(floatArray.length * factor);
byteBuffer.order(ByteOrder.nativeOrder());
FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
floatBuffer.put(floatArray);
floatBuffer.position(0);
return floatBuffer;
}
public static FloatBuffer toFloatBuffer(float[] floatArray) {
return toFloatBuffer(floatArray,4);
}
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_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
// 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);
bitmap.recycle();
return textureId;
}
public static int loadTextureFromResource( GL10 gl, Context context, int resourceId) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId);
return loadTexture(gl,bitmap);
}
}
Dosyayı İndir