質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

0回答

1064閲覧

複数のImageを張り付ける時のコードについて

退会済みユーザー

退会済みユーザー

総合スコア0

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2017/01/24 05:10

編集2022/01/12 10:55

ポリゴンに複数の画像を張り付けたいのですが変更に必要なコードがわかりません。
調べる時に必要そうな単語を教えてください

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.ShortBuffer; import javax.microedition.khronos.opengles.GL10; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.opengl.GLUtils; class Cube { //各バッファの接点 private FloatBuffer mVertexBuffer; private FloatBuffer mNormalBuffer; private ShortBuffer mIndexBuffer; private FloatBuffer mTextureBuffer; // 接続する頂点の配列数 private int numberOfindex = 36; //テクスチャの管理id private int textureId; /** * 角度 */ private float angle = 0f; public Cube(GL10 gl, Resources r) { float x = 2f; float y = 2f; float z = 0.1f; //頂点 float[] vertices = { x, y, z, -x, y, z, -x,-y, z, x,-y, z, // v0-v1-v2-v3 front x, y, z, x,-y, z, x,-y,-z, x, y,-z, // v0-v3-v4-v5 right x, y, z, x, y,-z, -x, y,-z, -x, y, z, // v0-v5-v6-v1 top -x, y, z, -x, y,-z, -x,-y,-z, -x,-y, z, // v1-v6-v7-v2 left -x,-y,-z, x,-y,-z, x,-y, z, -x,-y, z, // v7-v4-v3-v2 bottom x,-y,-z, -x,-y,-z, -x, y,-z, x, y,-z // v4-v7-v6-v5 back }; //テクスチャUV座標 float[] textures = { 1, 0, 0, 0, 0, 1, 1, 1, // v0-v1-v2-v3 front 0, 0, 0, 1, 1, 1, 1, 0, // v0-v3-v4-v5 right 0, 1, 1, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top 1, 0, 0, 0, 0, 1, 1, 1, // v1-v6-v7-v2 left 0, 1, 1, 1, 1, 0, 0, 0, // v7-v4-v3-v2 bottom 0, 1, 1, 1, 1, 0, 0, 0 // v4-v7-v6-v5 back }; //法線ベクトル 表面と裏面どちらを向いているか float[] normals = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 left 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7-v4-v3-v2 bottom 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 // v4-v7-v6-v5 back }; short indices[] = { 0, 1, 2, 0, 2, 3, // front 4, 5, 6, 4, 6, 7, // right 8, 9,10, 8,10,11, // top 12,13,14, 12,14,15, // left 16,17,18, 16,18,19, // bottom 20,21,22, 20,22,23 // back }; // Vertex mVertexBuffer = makeFloatBuffer(vertices); //Normal mNormalBuffer = makeFloatBuffer(normals); // index mIndexBuffer = makeShortBuffer(indices); // texture mTextureBuffer = makeFloatBuffer(textures); textureId = loadTexture(gl, r, R.drawable.anayuki); } /** * システム上のメモリ領域を確保するためのメソッド * Float用 */ public static final FloatBuffer makeFloatBuffer(float[] arr) { ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb; } /** * システム上のメモリ領域を確保するためのメソッド * Short用 */ public static final ShortBuffer makeShortBuffer(short[] arr) { ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); ShortBuffer fb = bb.asShortBuffer(); fb.put(arr); fb.position(0); return fb; } /** * 描画 */ public void draw(GL10 gl) { //ここではz軸方向に -3.0だけ移動させます. gl.glTranslatef(0, 0, -30.0f); //マトリクスの回転 gl.glRotatef(angle++, 0, 1, 0); //テクスチャ機能の有効化 gl.glEnable(GL10.GL_TEXTURE_2D); //テクスチャオブジェクトの指定 gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId); // 頂点のポインタを設定 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer); //法線ベクトルの指定 gl.glNormalPointer(GL10.GL_FLOAT,0,mNormalBuffer); gl.glEnableClientState(GL10.GL_NORMAL_ARRAY); //テクスチャのポインタを設定 gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer); // 頂点の描画 // gl.glDrawElements( プリミティブ, 頂点の数, タイプ, インデックス) gl.glDrawElements(GL10.GL_TRIANGLES, numberOfindex, GL10.GL_UNSIGNED_SHORT, mIndexBuffer); } /** * テクスチャを読み込む. * 読み込む画像のサイズは2の階乗の値でなければならない. */ public static final int loadTexture(GL10 gl, Resources r, int resId) { int[] textures = new int[1]; //読み込むBitmapのオプションの設定 BitmapFactory.Options options = new BitmapFactory.Options(); //リソースの自動リサイズをしない options.inScaled = false; // 32bit画像として読み込む options.inPreferredConfig = Config.ARGB_8888; //Bitmapの作成 Bitmap bmp = BitmapFactory.decodeResource(r, resId, options); if (bmp == null) { return 0; } // OpenGL用のテクスチャを生成する gl.glGenTextures(1, textures, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0); 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.glBindTexture(GL10.GL_TEXTURE_2D, 0); //OpenGLへの転送が完了したので、VMメモリ上に作成したBitmapを破棄する bmp.recycle(); return textures[0]; } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問