Sign in to follow this  
MirekMalysz

Rendering Part of Tile Map

Recommended Posts

i have a map being rendered, how is it possible to render only the part the i see on screen without rendering the QUADS that im using. the way i have it is that it renders the entire map, for a start i just have 1 texture, and it loops 50 tiles across and down. but it is always rendering all of them at once, therefore slowing the performance down alot, is there a way i can make it so only the ones i see are rendered so that it can increase speed? ive tried the scissor test, but it just hides the quads i dont want rendered. i need it so it completely avoids the quads that are outside the viewport... thx in advance

Share this post


Link to post
Share on other sites
Been tooling around with doing a tile based scrolling renderer today and been doing some thinking on how to make it fast and efficient.

Just thought of this after I read this post. Idea is as follows:

Basically you create a tiled mesh thats 1 more tile wide and tall than the maximum viewable on the screen. Then to achieve scrolling you simply translate up/down/left/right no more than 1 tile in each direction. If you reach the 1 tile threshold you pop the mesh back a tile and start the scroll over again.

Every time you pop the mesh back you increment/decrement the row/column of tiles you're drawing.

This will allow you to keep the mesh in a VBO (if you wish) and just feed it index lists. You can also defer the rendering and append indicies to to indexlists based on texture. This way you can batch the render calls by texture and minimize texture changes.

Hope I explained that well enough.

-=[ Megahertz ]=-

Share this post


Link to post
Share on other sites
well i understood it, but i dont think thats wat im going for. im tryin to make an RTS, and i dont think that will work well doin it that way..

is there a way i can draw a rectangle and attach the renderer to that, so that so the scene gets drawn in the rectangle?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
why don't you use an octree ? or simply check every tile against the frustum..(but this maybe will hurt performance more than rendering them all..)

Share this post


Link to post
Share on other sites
... unless i've missed something here, just dont draw what you cant see.

The AP is close with their suggestion, I'd infact point you at a Quad-tree instead. Break the world up into reasonably sized chucks, then do a simple test to see which chucks you can see to draw them or not.

Share this post


Link to post
Share on other sites
ok well ive tried the stencil test and im having trouble making it work, so far i have this:

for (yloop=0;yloop<Map_Y;yloop++) // Loop Through The Y Plane
{
for (xloop=0;xloop<Map_X;xloop++) // Loop Through The X Plane
{
// Position The Tiles On The Screen
glEnable(GL_STENCIL_TEST);

glStencilFunc(GL_ALWAYS, 1, 1);

glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

glDisable(GL_DEPTH_TEST);

glCallList(box); // Draw The Box
glEnable(GL_DEPTH_TEST);

glColorMask(1,1,1,1);

glStencilFunc(GL_EQUAL, 1, 1);

glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glEnable(GL_CLIP_PLANE0);
}
glTranslatef(-Map_X,-1.0f,0.0f);
}

i followed the tutorial on Nehe's site, but it still draws the whole map that im rendering not just the part that i see in my view, can anyone plz point out a possible error?

Share this post


Link to post
Share on other sites
You'll want to do a check with the vertex coordinates for your quads before you render. So, say (for example) x -10 y 10 is the top left of the screen, if the quads coordinates are < x -10 and > y 10 then don't render it.

That's a basic explanation but hopefully you can figure it out. If you need me to explain more clearly then just ask.

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