使纹理可点击

时间:2016-05-10 08:36:54

标签: android opengl-es 3d-modelling

我在3D模型上添加了多个纹理,我只是想在我的活动类中点击任何纹理或点击它的纹理ID时得到通知。 欢迎任何帮助或建议......

public static int loadTexture(final InputStream is) {
            Log.v("GLUtil", "Loading texture '" + is + "' from stream...");

            final int[] textureHandle = new int[1];

            GLES20.glGenTextures(1, textureHandle, 0);
            GLUtil.checkGlError("glGenTextures");

            if (textureHandle[0] != 0) {
                Log.i("GLUtil", "Handler: " + textureHandle[0]);

                final BitmapFactory.Options options = new BitmapFactory.Options();
                options.inScaled = false;

                // Read in the resource
                final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
                if (bitmap == null) {
                    throw new RuntimeException("couldnt load bitmap");
                }

                // Bind to the texture in OpenGL
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
                GLUtil.checkGlError("glBindTexture");

                // Set filtering
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                        GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                        GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

                // Load the bitmap into the bound texture.
                GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
                GLUtil.checkGlError("texImage2D");
                // Recycle the bitmap, since its data has been loaded into OpenGL.
                bitmap.recycle();

            }

            if (textureHandle[0] == 0) {
                throw new RuntimeException("Error loading texture.");
            }

            return textureHandle[0];
        }

0 个答案:

没有答案