GLSurfaceView显示黑色的Nexus 7与Android 4.2黑色、GLSurfaceView、Nexus、Android

2023-09-05 02:17:43 作者:做你的小仙女

我有一个OpenGL ES2.0的应用程序,正在运行从2.2至4.1的各种版本的Andr​​oid设备。不过,我已被告知,与Android 4.2上的Nexus 7上运行,当它在App的3D图形都是黑的。操作栏和对话框做工精细,虽然。我已经尝试过在一个模拟的Nexus 7采用英特尔Atom处理器,HAX和GPU启用运行4.2.2和工程确定。我会pferred运行ARM映像$ P $但是这似乎并没有包含的Open GL ES2.0

没有任何人有任何深入了解什么可能的的Nexus 7造成这个问题,以及如何解决它?

一种可能性是,目前的应用程序版本有目标API级别设置为15,而4.2.2的17级莫非是一个问题?它的工作原理确定在模拟器上虽然。

下面是我使用的情况下,这是任何帮助设置onSurfaceCreated渲染器()的纹理code。

  / **
 *设定纹理的对象
 * /
私人无效setupTextures(字符串[] texFiles){
    //创建新的纹理ID如果对象有他们
    //纹理数量
    mTextureIDs =新INT [texFiles.length]

    GLES20.glGenTextures(texFiles.length,mTextureIDs,0);

    的for(int i = 0; I< texFiles.length;我++){
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,mTextureIDs [I]);

        //参数
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MIN_FILTER,
                GLES20.GL_NEAREST);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER,
                GLES20.GL_LINEAR);

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_S,
                GLES20.GL_REPEAT);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_T,
                GLES20.GL_REPEAT);

        。INT ID = mContext.getResources()则getIdentifier(texFiles [I]中,生,com.antonymsoft.slidixcube);
        InputStream的是= mContext.getResources()openRawResource(ID)。
        点阵位图;
        尝试 {
            位= BitmapFactory.de codeStream(是);
        } 最后 {
            尝试 {
                is.close();
            }赶上(IOException异常E){
                // 忽略。
            }
        }

        //创建
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,0,位图,0);
        bitmap.recycle();

    }
}
 

解决方案

你是什么材质的大小?它应该是两个电源,例如16×32 512×512 1024×512等。

I have an OpenGL ES2.0 app that is working on devices running various Android versions from 2.2 up to 4.1. However I have been told that when running it on a Nexus 7 with Android 4.2 the 3D graphics in the App are all black. The Action Bar and dialogs work fine though. I have tried it on an emulated Nexus 7 with Intel Atom processor, HAX and GPU enabled running 4.2.2 and that works OK. I would have preferred to run the ARM image but that doesn't seem to include Open GL ES2.0

谷歌正式放出Nexus7 10版Android 5.1.1官方镜像

Does anyone have any insight into what might be causing this problem on the Nexus 7 and how to work around it?

One possibility is that the current App version has the target API level set to 15 whereas 4.2.2 is level 17. Could that be an issue? It works OK on the emulator though.

Below is the code that I use to set the textures in the renderer onSurfaceCreated() in case that is any help.

/**
 * Sets up texturing for the object
 */
private void setupTextures(String[] texFiles) {
    // create new texture ids if object has them
    // number of textures
    mTextureIDs = new int[texFiles.length];

    GLES20.glGenTextures(texFiles.length, mTextureIDs, 0);

    for(int i = 0; i < texFiles.length; i++) {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIDs[i]);

        // parameters
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
                GLES20.GL_NEAREST);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER,
                GLES20.GL_LINEAR);

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
                GLES20.GL_REPEAT);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
                GLES20.GL_REPEAT);

        int ID = mContext.getResources().getIdentifier( texFiles[i], "raw", "com.antonymsoft.slidixcube" );
        InputStream is = mContext.getResources().openRawResource(ID);
        Bitmap bitmap;
        try {
            bitmap = BitmapFactory.decodeStream(is);
        } finally {
            try {
                is.close();
            } catch(IOException e) {
                // Ignore.
            }
        }

        // create it 
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();

    }
}

解决方案

What is your textures size ? It should be power of two, for example 16x32 512x512 1024x512 and so on.

 
精彩推荐