Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.shpaker.experiment;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- import java.nio.IntBuffer;
- import javax.microedition.khronos.opengles.GL10;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.opengl.GLUtils;
- public class Image {
- private final IntBuffer mTextureBuffer;
- private int x, y, width, height;
- private int texCoords[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
- private void setVerticles(int x, int y, int width, int height) {
- this.x(x);
- this.y(y);
- this.width(width);
- this.height(height);
- this.texCoords[0] = x;
- this.texCoords[1] = y;
- this.texCoords[2] = x + width;
- this.texCoords[3] = y;
- this.texCoords[4] = x;
- this.texCoords[5] = y + height;
- this.texCoords[6] = x + width;
- this.texCoords[7] = y + height;
- }
- public Image() {
- setVerticles(0, 0, 0, 0);
- ByteBuffer tdd = ByteBuffer.allocateDirect(texCoords.length * 4);
- tdd.order(ByteOrder.nativeOrder());
- mTextureBuffer = tdd.asIntBuffer();
- }
- public void src(GL10 gl, Context context, int resource) {
- Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),
- resource);
- GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
- gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
- GL10.GL_LINEAR);
- gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
- GL10.GL_LINEAR);
- bmp.recycle();
- }
- public void drawImage(GL10 gl, int x, int y, int width, int height) {
- gl.glEnable(GL10.GL_TEXTURE_2D);
- gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, mTextureBuffer);
- setVerticles(x, y, width, height);
- mTextureBuffer.put(texCoords);
- mTextureBuffer.position(0);
- gl.glVertexPointer(2, GL10.GL_FIXED, 0, mTextureBuffer);
- // gl.glColor4f(1, 1, 1, 0);
- gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
- }
- }
Add Comment
Please, Sign In to add comment