android - 尝试加载两个纹理,但只有一个被加载

标签 android opengl-es

我制作了一个所有对象都使用一个 Sprite 表的游戏,目前为止运行良好。现在我制作了一个具有自己纹理的对象,但(至少在我的手机上,一个 Evo)它只显示一个白色平面。但是,这在模拟器上运行良好。这是我加载纹理的代码:

public void LoadTexture(GL10 gl, Context context) throws IOException {
    InputStream is = context.getAssets().open("Image.png");
    Bitmap bitmap = null;
    try{
        bitmap = BitmapFactory.decodeStream(is);
    }finally{
        try{
            is.close();
            is = null;
            gl.glGenTextures(1, texture,0);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);

            //Create Nearest Filtered Texture

            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);

            //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

            //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
            GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);


            gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
            //Clean up


            bitmap.recycle();
        }catch(IOException e){

        }
    }

}

并且,在不同的类中:

public void LoadTexture(GL10 gl, Context context) throws IOException{
    InputStream is = context.getAssets().open("end.png");
    Bitmap bitmap = null;
    try{
        bitmap = BitmapFactory.decodeStream(is);
    }finally{
        try{
            is.close();
            is = null;
            gl.glGenTextures(1, texture,0);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);

            //Create Nearest Filtered Texture

            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);

            //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

            //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
            GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);


            gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
            //Clean up


            bitmap.recycle();
        }catch(IOException e){

        }
    }
}

这两个类都有一个启用/禁用纹理的绘制框架例程和一个私有(private)成员 (int[] texture = new int[1])。我尝试更改变量,但同样的事情还是发生了。两个纹理都加载到 onSurfaceCreated(GL10 gl, EGLConfig config);

最佳答案

我遇到过类似的问题,但你可能不是这样。我试图加载的图像也是我的应用程序图标,但不知何故它没有加载它我更改了操作系统未引用的图像并且它工作正常

关于android - 尝试加载两个纹理,但只有一个被加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6630877/

相关文章:

android - 防止 ACRA 发送重复异常

android - 如何使 ZXing 4.4 条码扫描器直接转到“URL”?

android - Flutter Build 在 assembleDebug 期间失败

iphone - 如何在 iPhone 上使用 openGLES 制作水效果 View ?

ios - OpenGLES 2中的文本/字体渲染(iOS-CoreText?)-选项和最佳实践?

android - 在图像上的触摸点(坐标)处绘制矩形或形状

Android Gridview 中的复选框回收 View 问题

android - 快速暂停/恢复应用程序时 Android NDK 中的 SurfaceView 崩溃

android - OpenGLRenderer 试图缩小位图 - 当到达 ViewPager 的末尾时

iphone - 使用 OpenGL ES 在 iPhone 上播放视频?