It's been a while, but I'm back once again with another question.
I'm working on a game that's going to be based on a hexagon grid. I'm currently drawing each individual hexagon (using TRIANGLE_STRIP) and then loop through all the tiles to draw them.
This is my hexagon:
Using java Syntax Highlighting
- public class HexTile
- {
- private float height;
- private int[] textures = new int[1];
- private float vertices[] = { 0.0f, 0.0f, 0.0f, //center
- 0.0f, 1.0f, 0.0f, // top
- -1.0f, 0.5f, 0.0f, // left top
- -1.0f, -0.5f, 0.0f, // left bottom
- 0.0f, -1.0f, 0.0f, // bottom
- 1.0f, -0.5f, 0.0f, // right bottom
- 1.0f, 0.5f, 0.0f, // right top
- };
- private short[] indices = { 0, 1, 2, 3, 4, 5, 6, 1};
- //private float texture[] = { };
- private FloatBuffer vertexBuffer;
- private ShortBuffer indexBuffer;
- private FloatBuffer textureBuffer;
- public HexTile()
- {
- ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
- vbb.order(ByteOrder.nativeOrder());
- vertexBuffer = vbb.asFloatBuffer();
- vertexBuffer.put(vertices);
- vertexBuffer.position(0);
- ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
- ibb.order(ByteOrder.nativeOrder());
- indexBuffer = ibb.asShortBuffer();
- indexBuffer.put(indices);
- indexBuffer.position(0);
- /*ByteBuffer tbb = ByteBuffer.allocateDirect(texture.length * 4);
- tbb.order(ByteOrder.nativeOrder());
- textureBuffer = tbb.asFloatBuffer();
- textureBuffer.put(texture);
- textureBuffer.position(0);*/
- }
- public void setHeight(float h)
- {
- height = h;
- }
- public float getHeight()
- {
- return height;
- }
- public void draw(GL10 gl)
- {
- gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
- //gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
- gl.glDrawElements(GL10.GL_TRIANGLE_FAN, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
- }
- public void loadGLTexture(GL10 gl, Context context)
- {
- textures[0] = -1;
- Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.hex);
- while(textures[0] <= 0)
- gl.glGenTextures(1, textures, 0);
- //gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
- 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);
- GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
- bitmap.recycle();
- }
- }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
Now as I kind of expected this is killing the framerate. The framerate drops to 37 when drawing the worst case scenario (11 * 7 tiles) and that is without textures, just simple white hexagons.
I really don't have enough experience with openGL to figure out how to efficiently draw this grid. Each tile is going to have it's own texture, and will eventually be 3D (with only the front visible). So uuhm, what would be the most efficient way of drawing a grid like this?
I'd really appreciate if someone could help me with this!
Quipeace

