Note that there are some explanatory texts on larger screens.

plurals
  1. POglDrawTexfOES draws black texture on phone, and correct in emulator
    primarykey
    data
    text
    <p>I'm writing a 2D game using OpenGL, using png images (64x64 pixels, with transparency) stored in my resources. </p> <p>My code looks like this : </p> <pre><code>import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL11; import javax.microedition.khronos.opengles.GL11Ext; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLUtils; import android.opengl.GLSurfaceView.Renderer; public class TestGLRenderer implements Renderer { private int mTexGLNames[]; private Context mContext; public TestGLRenderer(Context ctx) { mContext = ctx; } public void onSurfaceCreated(GL10 gl, EGLConfig config) { // setup the gl renderer gl.glClearColor(0.2f, 0.4f, 0.6f, 1.0f); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glShadeModel(GL10.GL_FLAT); gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); // reserve GL texture names mTexGLNames = new int[1]; gl.glGenTextures(1, mTexGLNames, 0); // load image from resources Bitmap b; b = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.image); // load image in opengl gl.glBindTexture(GL10.GL_TEXTURE_2D, mTexGLNames[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, b, 0); } public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); gl.glBindTexture(GL10.GL_TEXTURE_2D, mTexGLNames[0]); int crop[] = new int[] { 0, 64, 64, -64 }; ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, crop, 0); ((GL11Ext) gl).glDrawTexfOES(160, 240, 0, 64, 64); } public void onSurfaceChanged(GL10 gl, int w, int h) { } } </code></pre> <p>The result is working as expected in the emulator (running Android 2.2), but the image appears as a black square on my phone (LG-P500, Android 2.2). Attached are screenshots from both the emulator and my phone. </p> <p>Is there something wrong with my code, or is it a problem with my phone (my phone can run other 3D games without problems) ?</p> <p><img src="https://i.stack.imgur.com/0OXRb.png" alt="Screenshot from the emulator"> <img src="https://i.stack.imgur.com/UbqQl.png" alt="Screenshot from my phone"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload