Hi everyone!!
I’m programming a little game, faking isometric view with ortho + rotate (x & y) + billboarding sprites.
To optimize the GL calls, my SpriteManager is using a Vertex Buffer to draw all the sprite on screen in a single call.
Creation Code
spritePool = new Sprite[MAX_SPRITES];
vertexData = new float[3*6*MAX_SPRITES]; //6 vertices por sprite
ByteBuffer vbb = ByteBuffer.allocateDirect(vertexData.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
Use Code
/*
* p1 p2
* +-----------+
* | |
* | |
* | + |
* | px,py |
* | |
* +-----------+
* p3 p4
*
* p1 p2 p2
* +-----------+ -+
* | + + |
* | + + |
* | + + |
* | + + |
* | + + |
* +- +-----------+
* p3 p3 p4
*
*/
GL11.glVertexPointer(3, 0, vertexBuffer);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glDrawArrays(GL11.GL_TRIANGLES,0,totalSprites*6);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
Everything was working OK until I added textures, I checked and the textures are being loaded with the correct alpha. The sprites only draw the alpha > 0 part of the texture, but some quads are drawn with the background over sprites.
The image show a sprite drawn OK (green, transparent quad), and a sprite with the error (red, background over sprtes):
http://www.demegames.cl/images/error.png
The blending and texture calls are:
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
Do I need some sorting of the triangles? or the blending call is not correct??