Advertisement Jump to content
Sign in to follow this  

Render only Tiles in Viewport

This topic is 4930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!