Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying selectively redraw background for an android game, but the moving image is duplicated across the screen
    text
    copied!<p>It's easiest if I just start by showing pictures of the problem. The pictures show a snapshot of a texture moving around.</p> <p>The application on my HTC Hero:</p> <p><img src="https://i.stack.imgur.com/h6dBC.png" alt="Image from my Hero"></p> <p>The same application on the emulator where it works fine (Disregard the randomly placed leftovers, I know the cause of them, and it's not a problem): <img src="https://i.stack.imgur.com/wGomb.png" alt="Image from the emulator"></p> <p>Now, if you look at the first image, the top one is the "real one" and the others always follow beneath, and there are copies above aswell. I am currently only repainting the background squares that was visited, and they are for some reason drawn above the copies (you can see they are all partially painted over by a tile).</p> <p>Do you have to always repaint the whole screen every frame on the android phones? Or is it possible to get rid of these weird copies?</p> <p>Here is the code used to draw the textures (I'm new to opengl-es so it's a lot like replica island):</p> <p>first</p> <pre><code>public static void beginDrawing(GL10 gl, float viewWidth, float viewHeight) { gl.glShadeModel(GL10.GL_FLAT); gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrthof(0.0f, viewWidth, 0.0f, viewHeight, 0.0f, 1.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glEnable(GL10.GL_TEXTURE_2D); } </code></pre> <p>Then for every texture (I draw background first, then in this case only one hulk texture. I'm sure it's being drawn only once):</p> <pre><code> gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID); ((GL11Ext) gl).glDrawTexfOES(x, y, 0, (float) mWidth, (float) mHeight); </code></pre> <p>and at the end:</p> <pre><code>public static void endDrawing(GL10 gl) { gl.glDisable(GL10.GL_BLEND); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glPopMatrix(); } </code></pre> <p>The code I use to load textures:</p> <pre><code>private void loadGLTextures(GL10 gl) { int[] textures = new int[1]; gl.glGenTextures(1, textures, 0); textureID = textures[0]; gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); int[] mCropWorkspace = new int[4]; mCropWorkspace[0] = 0; mCropWorkspace[1] = bitmap.getHeight(); mCropWorkspace[2] = bitmap.getWidth(); mCropWorkspace[3] = -bitmap.getHeight(); ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCropWorkspace, 0); mCrop = mCropWorkspace; bitmap.recycle(); } </code></pre> <p>All help is very much appriciated, and please leave a comment if anything is unclear!</p> <p>EDIT: I should add that if I every frame redraw all the squares, the "extra" images are hidden, and it works the way it should.</p>
 

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