package framework.RWT; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL11; import javax.microedition.khronos.opengles.GL11Ext; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLES20; import android.opengl.GLSurfaceView; import android.opengl.GLUtils; import framework.model3D.Position3D; import java3d.ImageComponent2D; import java3d.Texture; import java3d.TextureLoader; public class RWTSprite { private int[] textureNo = null; private TextureLoader texLoader; private Texture tex; // 表示座標 private Position3D pos = new Position3D(0.f, 0.f, 0.f); private Position3D texSize = new Position3D(0.f, 0.f, 0.f); private Position3D texPos = new Position3D(0.f, 0.f, 0.f); private Position3D viewSize = new Position3D(0.f, 0.f, 0.f); public RWTSprite(final RWTSurfaceView surface) { surface.addSprite(this); } final public Position3D getPosition() { return pos; } final public Position3D getViewSize() { return viewSize; } final public Position3D getTextureSize() { return texSize; } /** * テクスチャ設定 * * @author s.iwatani * @param res * @param id */ public void setTexture(Resources res, int id, int flags, GL10 gl) { texLoader = new TextureLoader(res, id, flags); ImageComponent2D image = texLoader.getImage(); tex = texLoader.getTexture(); texPos.setX(0.f); texPos.setY(image.getBitmap().getHeight()); texSize.setX(image.getBitmap().getWidth()); texSize.setY(-image.getBitmap().getHeight()); pos.setX(0.f); pos.setY(0.f); pos.setZ(0.f); viewSize.setX((float)image.getBitmap().getWidth()); viewSize.setY((float)image.getBitmap().getHeight()); } public void draw(GL10 gl) { int[] textureId = new int[1]; gl.glGenTextures(1, textureId, 0); //テクスチャIDに対応するテクスチャをバインドする gl.glBindTexture(GL10.GL_TEXTURE_2D, textureNo[0]); //テクスチャの座標と幅と高さを指定 int rect[] = {(int)texPos.getX(), (int)texPos.getY(), (int)texSize.getX(), (int)texSize.getY()}; ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D,GL11Ext.GL_TEXTURE_CROP_RECT_OES, rect, 0); ((GL11Ext) gl).glDrawTexfOES((int)pos.getX(), (int)pos.getY(), 0, (int)viewSize.getX(), (int)viewSize.getY()); } }