0
\$\begingroup\$

enter image description hereI modeled my sprite drawing on Grid.java and GLSprite.java from SpriteMethodTest, using 2D OpenGl ES 1.0/1.1 on Android, but the "quad" sprite background shows when two sprites overlap each other. I'm not using double buffering though, in onDrawFrame() I just do a gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

and the code in onSurfaceCreated() and onSurfaceChanged() and anywhere else is pretty much identical.

My texture images are single layer .png with a transparent background and are "even" sized. And all the bitmap texture loading gl code is the same. I compared my images with the ones from SpriteMethodTest, in Gimp, and they appear to have the same properties.

The display area is black and when the sprites overlap, the "quad" the texture is "on" is like a black square when it goes over another sprite.

What should I be looking for to try to fix it so that only the texture image is visible?

Thanks!

\$\endgroup\$
1
\$\begingroup\$

You need to enable blending.

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Also note that z-ordering is important when drawing blended sprites. You need to draw the sprites from back to front. If you do not do that and draw a sprite behind another, blending will not be correctly applied. You may want to disable depth buffering if you don't know you really need it.

You can find a great blending mode illustrator from here. Here is also an image which explains different blending functions:

Blending functions

\$\endgroup\$
  • \$\begingroup\$ In onSurfaceChanged() it had: gl.glShadeModel(GL10.GL_FLAT); gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); But I think I had part of it commented out, so I un-commented it and it looks way better! I'll look into all that more, thanks! \$\endgroup\$ – user1572522 Feb 6 '14 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.