Sign in to follow this  
Son of Cain

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

Recommended Posts

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 this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites
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.glTranslatef(x, y, 0);


TextureCoords coords = texture.getImageTexCoords();

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.glVertex2f(texture.getWidth(), 0);


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 this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this