# [java] JOGL - Texture coordinates in a vertex array for isometric tiled map

## Recommended Posts

Son of Cain    480
Hi folks, I've no clue on how to use a vertex array for texture coordinates in a multi-layered, isometric tiled map. I've searched on google for material and references, but got nothing besides the red book's basic information and examples. I do all the drawing for my tiles (and also the animated sprites) in immediate mode - that is, between glBegin() and glEnd(). I can't use display lists because this is no static content, of course. So I think I must use vertex array and perhaps VBO, right? But I can't find resources to learn about these tricks... specially if related to problem I'm trying to tackle here :D So if anyone has any advice, criticism, and material to point out regarding this issue, I would appreciate it a lot! :D Son Of Cain

##### Share on other sites
I'm not sure but isn't that more of a question to ask in the opengl forums since jogl is bound to opengl.

You might get more results there!

##### Share on other sites
Son of Cain    480
Yeah, indeed. I'm so used to this forum that I didn't acknowledge the existence of the OpenGL forum when posting =/

But I can't cross post, so I'm just going to wait a benevolent (and powerful) soul to move it to the OpenGL forum for me :D

Son Of Cain

##### Share on other sites
GKW    200
You can always google for vertex array tutorials.

##### Share on other sites
Son of Cain    480
Yes, and I did that and I'm reading through some tutorials, but I was wondering if any of you had tried accomplish a similar task, and could give me some advice.

Someone suggested me the following in another forum: when loading a map, setup a big texture containing all the image used by the tiles of a the particular map, and then map the texture coordinates of each map according to a subregion of that big texture in memory, resulting in a big texture coordinate array. That would get rid of immediate mode for rendering tiles.

But when I draw the map, I only draw the visible tiles (of course). Wouldn't that be overkill to send an entire array for OpenGL, when I need only a 'portion' of it? Or am I misunderstanding the concept here? (quite possible =)

Anyway, this is how I render my tile:

GL gl = Game.getRenderer().getGL();                gl.glPushMatrix();                texture.bind();                gl.glTranslatef(x, y, 0);                gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);                TextureCoords coords = texture.getImageTexCoords();                gl.glBegin(GL.GL_QUADS);        {            gl.glTexCoord2f(coords.left(), coords.top());            gl.glVertex2f(0, 0);                        gl.glTexCoord2f(coords.left(), coords.bottom());            gl.glVertex2f(0, texture.getHeight());                        gl.glTexCoord2f(coords.right(), coords.bottom());            gl.glVertex2f(texture.getWidth(), texture.getHeight());                        gl.glTexCoord2f(coords.right(), coords.top());            gl.glVertex2f(texture.getWidth(), 0);        }        gl.glEnd();                gl.glPopMatrix();

I simply want to optimize that, to get rid of the immediate mode in order to minimize JNI overhead of native method calls. Performance is not an issue as of now (the game runs quite smooth), but this I'm trying is an ideal optimization, don't want to continue without it :D

Son Of Cain

##### Share on other sites
GKW    200
The first thing you have to do is to load all you vertex and texture coordinates into a FloatBuffer. It has to be a direct buffer in the native order for the best speed up. You can start off with a FloatBuffer for the vertex and a FloatBuffer for the texture coordinates. Then you set your arrays with calls to glVertexPointer and glTexCoordPointer. After that you just have to pick which method you want to use to render the data. glArrayElement, glDrawElements, etc. I would imagine you could do some sort of frustum culling to generate a list of quads that you wish to render and then use glDrawElements. I can't tell exactly how you hve your data stored so you might not see that much of a speed up until you arrage your data differently.

##### Share on other sites
Son of Cain    480
Thanks for the guidelines dude, I'll try it out when work gives me a break, and then post back ;)

Son Of Cain