GLSurfaceView displaying black on Nexus 7 with Android 4.2
Asked Answered
A

1

6

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

    }
}
Anora answered 14/4, 2013 at 22:23 Comment(6)
If the surface is entirely black I'd think the issue was more fundamental than texture load. What's your rendermode? How are you setting up your GL context?Battement
@ReubenScratton Thanks for your response! The following lines set my context and rendermode from the constructor of my class derived from GLSurfaceView. ` // Create an OpenGL ES 2.0 context. setEGLContextClientVersion(2); // Set the Renderer for drawing on the GLSurfaceView mCubeSize = 2; mCubeRenderer = new CubeRenderer( context ); setRenderer(mCubeRenderer); // Render the view only when there is a change in the drawing data setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); `Anora
Oh also I forgot to say that I create an instance of my GLSurfaceView subclass using an XML layout and then use findViewById() to retrieve a reference.Anora
Sorry, no real idea here. Are your texture bitmaps all power-of-two? Can you post more code?Battement
My textures are not power of two. Is that still important - even on OpenGL ES 2 and a device as new as the Nexus 7? This is my first venture into OpenGL and GPUs so I'm very open to advice on this. Regarding posting more code I need to think about what to put up so that I'm not adding a lot of irrelevant stuff into the post.Anora
I wouldn't trust non-power-of-two bitmaps to work as textures. What sizes are your bitmaps? Can you log the value of glGetError() after your texImage2D() call?Battement
G
5

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

Garish answered 18/4, 2013 at 21:45 Comment(1)
Yes that was it. Amazingly some devices still do not support non-power of two textures.Anora

© 2022 - 2024 — McMap. All rights reserved.