Sign in to follow this  
Napster23

Render only Tiles in Viewport

Recommended Posts

Have anyone an idea how i can only render the iso tiles in the Viewport. Perhaps with a little (pseudo)code? Now i do it like that: glBegin(GL_QUADS); for (int y = 0; y < KarteY; y++) { for (int x = 0; x < KarteX; x++) { tile = Karte[y][x]; glColor3f(1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, texture[tile]); glTexCoord2f(0.0f, 0.0f);glVertex2f(float(x), float(y)); glTexCoord2f(1.0f, 0.0f);glVertex2f(float(x + 1), float(y)); glTexCoord2f(1.0f, 1.0f);glVertex2f(float(x + 1), float(y + 1)); glTexCoord2f(0.0f, 1.0f);glVertex2f(float(x), float(y + 1)); } } glEnd(); Can anyone help me please?

Share this post


Link to post
Share on other sites
you can easily calculate at what coordinate a certain tile will be drawn on screen, as you know view offset and tile size, thus, firstly you can easily know if a tile is outside the screen, secondly... do it the other way around... you can now calculate which tile will be the leftmost/rightmost tile on the screen (x) and the same for the vertical-axis...

(a little abusive use of the "tile" word, but I hope you understand)

which will pretty much be as follows

TileLeftIndex = floor(ViewOffsetX / TileWidth)
TileRightIndex = ceil((ViewOffsetX + ViewWidth) / TileWidth)

I haven't really tried it, but it should work for squares, however you will need to modify it a little to cope with iso style worlds, but I think you understand what I want... HOWEVER, doing this will only work for the ground as the base of other objects could be outside the screen, but the object itself be inside the screen, two ways, either extend the top area (ugly and slow)... or use rectangles, and some kind of quadtree to easily narrow the possible objects down.

Hope it helps.

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