GLSurfaceView displaying black on Nexus 7 with Android 4.2

家住魔仙堡 提交于 2019-11-28 07:56:17

问题


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

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

    }
}

回答1:


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



来源:https://stackoverflow.com/questions/16005070/glsurfaceview-displaying-black-on-nexus-7-with-android-4-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!