Jump to content

  • Log In with Google      Sign In   
  • Create Account


Isometric tilemap rendering


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Lucky808   Members   -  Reputation: 139

Like
0Likes
Like

Posted 27 February 2013 - 04:16 PM

Hi all,

 

Has anyone read the book "Learning IOS Game Programming"? I'm current using the rendering method (for Orthogonal maps) taught in the book in my new game. I've successfully converted some of the code to work with Isometric tilemap. However, I hit a road block when it comes to rendering objects on the map in the right order. I'm using 3 map layers. (1.ground, 2.grass, 3.wall and trees). I render the first 2 layers, then the player object, then the 3rd layer. However I could not get it to render objects in correct orders. i.e. a player standing in front of a tree should show up as such, meaning the tree should be rendered 1st then the player.

I've implemented a depth buffer and set up the following:

 

 

        glOrthof(0.0f, rect.size.width, 0.0f, rect.size.height, 0.0f, 100.0f);

 

 

        glEnable(GL_DEPTH_TEST);

        glDepthMask(GL_TRUE);

        glDepthFunc(GL_LEQUAL);

        glDepthRangef(0.0f, 1.0f);

 

        glClearDepthf(1.0f);

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 

But objects are still not being rendered in the correct order. If someone who is familiar with the rendering method in that book can you please point me to the right direction.

Any input will be appreciated!

 

Thanks in advance.

 



Sponsor:

#2 ifthen   Members   -  Reputation: 820

Like
0Likes
Like

Posted 27 February 2013 - 05:31 PM

glOrtho() takes six parameters: left clipping plane, right clipping plane, a top one and a bottom one, and values of "near" and "far", respectively. What do the last two values mean? Other than being clipping planes, too (making the viewport of glOrtho() look like a cube in which you look into from one side), they are essential for making the depth buffer work. The depth buffer stores the values not in the linear sense, but we can roughly say that they are inversed (as in 1/depth), so the precision is lost only far away from camera where we don't see it. However, this is only "roughly" - the actual equation is much more precise and depends greatly on relationship of "near" and "far" values.

 

Your problem is that near is 0 in your case, that means that the relationship of "near" and "far" is zero division; that means you lose all of your depth buffer precision.

The solution? Set near (the second-last parameter to glOrtho()) to 1.0. It is maybe not the only cause of your depth buffer problem, but it is certainly one of them.


Edited by ifthen, 27 February 2013 - 05:32 PM.


#3 Lucky808   Members   -  Reputation: 139

Like
0Likes
Like

Posted 27 February 2013 - 06:51 PM

Thanks for the tips. however as soon as I adjust the second last parameter to 1.0,  the screen becomes blank. i don't see anything being rendered.



#4 ifthen   Members   -  Reputation: 820

Like
0Likes
Like

Posted 27 February 2013 - 07:29 PM

Well... you could be rendering your objects with the Z axis set to zero (if you are rendering "fake 3D" orthogonal tilemaps and not true 3D ones). Make sure that you translate them properly to the screen. If you are using the old fixed-pipeline OpenGL, you can simply translate the object like this

//in the drawing routine
void drawSomeObject()
{
int Z = 5; // from 1 up, if you want to use 1 too, lower "near" to 0.5 or something so the object is not clipped due to floating errors
glTranslate(0,0,Z);
//draw it somehow, e.g. using glBegin()/glEnd()
glTranslate(0,0,-Z);
}

 

The objects with higher Z value (i.e. farther from you) will be obscured by the objects with lower Z value if you do this.



#5 Lucky808   Members   -  Reputation: 139

Like
0Likes
Like

Posted 27 February 2013 - 09:12 PM

Yes, the objects were loaded without z-axis values. do they need z values for rendering in an isometric tilemap?

also, i tried implementing glTranslatef() into my rendering routine but made no difference. the moment i changed the 2nd last parameter to 1 in glOrtho() the screen went blank again :(



#6 Wyrframe   Members   -  Reputation: 731

Like
0Likes
Like

Posted 27 February 2013 - 10:21 PM

If you're wanting to render using the depth buffer to do layering for you, you should ideally be actually placing your scene contents in real 3D space. At the very least, you need to have different Z values for objects at different depths, or else the depth buffer is doing nothing at all. If you want to manually composite the depth of the scene using old-school 2D-esque sorting techniques, then disable the depth buffer, set the Z bounds to -1,+1 (you're currently using 0.0f,100.0f), and go wild with objects at Z=0. There are places for mixing the two, but most of them are in the realm of scene composition effects like distortion, full-screen shaders, etc.

(( This email has been quad-ROT13 encrypted. Reading it violates the DMCA. ))
(( 我说很少的汉语,还我的语法平庸, but at least I'm UNICODE-compliant. ))


#7 Lucky808   Members   -  Reputation: 139

Like
0Likes
Like

Posted 28 February 2013 - 09:09 PM

Ok, think I will go with placing my scene in a 3D space. In that case, how do I set up the z value for each tile on an Isometric tilemap. x and y position are determined by their index from an 2D array.(X increases towards southeast, Y increases towards northeast) something like:

 

 

        vertex1.geometryVertex.x += (aTileCoord.x + aTileCoord.y) * (aTileSize.width/2);

              vertex1.geometryVertex.y += (aTileCoord.x - aTileCoord.y) * -(aTileSize.height/2);

              vertex2.geometryVertex.x += (aTileCoord.x + aTileCoord.y) * (aTileSize.width/2);

              vertex2.geometryVertex.y += (aTileCoord.x - aTileCoord.y) * -(aTileSize.height/2);

              vertex3.geometryVertex.x += (aTileCoord.x + aTileCoord.y) * (aTileSize.width/2);

              vertex3.geometryVertex.y += (aTileCoord.x - aTileCoord.y) * -(aTileSize.height/2);

              vertex4.geometryVertex.x += (aTileCoord.x + aTileCoord.y) * (aTileSize.width/2);

              vertex4.geometryVertex.y += (aTileCoord.x - aTileCoord.y) * -(aTileSize.height/2);

 

what should I put in for z?


#8 Sik_the_hedgehog   Crossbones+   -  Reputation: 1607

Like
0Likes
Like

Posted 28 February 2013 - 10:52 PM

Your problem is that near is 0 in your case, that means that the relationship of "near" and "far" is zero division; that means you lose all of your depth buffer precision.

This is true for perspective projection because that's achieved by dividing the coordinates by the depth. Orthographic projection doesn't have this issue and the depth buffer in fact is linear in that case.


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS