OpenGL ES 2D on Samsung 4 - no textures on the screen

500 Views Asked by At

I have Nexsus 4 and several HTCs and my game works fine.

When I launch on Samsung 4 I see white rectangles (empty textures),

no errors,

Further, my game uses sensors but I see on Samsung 4 it doesn't work too,

but Samsung 3 - works,

please help,

[EDIT]

on Samsung 3 works!

I heard that they did a lot of changes with S4

[EDIT 2]

This is how I load textures:

public void loadTextures(GL10 gl, Context context){

    //Log.e(LOG_TAG, "DevQuestSprites :: loadTextures");  

    InputStream is;
    Bitmap bitmap;
    is = context.getResources().openRawResource(R.drawable.fly_a1_sprite);


    bitmap = BitmapFactory.decodeStream(is);
    try {
        is.close();
        is = null;
    } catch (IOException e) {
    }

    gl.glGenTextures(textureCount, textures, 0);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

    bitmap.recycle(); 

}

For me most impotent row is:

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

Here actually I put texture.

And this is draw method:

    public void draw(GL10 gl,
        ...
                    ...
        )
{   

     ...

    //gl.glMatrixMode(GL10.GL_MODELVIEW);

    gl.glTranslatef(transx, transy, 0.0f);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, floatBufferArray[mFrame]);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
    //gl.glDrawElements(GL10.GL_TRIANGLES, 1, GL10.GL_UNSIGNED_SHORT, vertexBuffer);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}

[EDIT 3]

I added to draw, onDrawFrame and main loop, no errors:

int error = gl.glGetError();
    if (error != 0)
        Log.e("main loop", "Draw " + error); 

After debugging I found only one new error for Samsung 4:

08-07 12:57:53.356: E/ViewRootImpl(29124): sendUserActionEvent() mView == null

[EDIT 4]

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig confid) {
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glShadeModel(GL10.GL_SMOOTH);        
    gl.glClearColor(0,0,0,0);
    gl.glClearDepthf(1.0f);
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glEnable(GL10.GL_BLEND);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
}
2

There are 2 best solutions below

2
On

One issue is that you have enabled alpha blending, but you can't use GLUtils.texImage2D() to load alpha textures on Android. This is a common problem that Google really should document better. The problem is that the Bitmap class converts all images into pre-multiplied format, but that does not work with OpenGL ES unless the image is completely opaque. The best solution is to use native code. This article gives more detail on this:

http://software.intel.com/en-us/articles/porting-opengl-games-to-android-on-intel-atom-processors-part-1

1
On

What is the size of your image? if you are using opnel GL It depends on which driver have the mobile but you need the size image to be power of two to work fine in all devices, 2,4,8,16,32...etc