# Optimized Tiling

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

## Recommended Posts

Hallo, i have a problem with tiling. How can i optimize this part of code? for (int y = 0; y < mapheight; y++) { for (int x = 0; x < mapwidth; x++) { glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f);glVertex3f(float(x), float(y), 0.0f); glTexCoord2f(1.0f, 0.0f);glVertex3f(float(x + 1), float(y), 0.0f); glTexCoord2f(1.0f, 1.0f);glVertex3f(float(x + 1), float(y + 1), 0.0f); glTexCoord2f(0.0f, 1.0f);glVertex3f(float(x), float(y + 1), 0.0f); glEnd(); } }

##### Share on other sites
You don't have to begin and end for every quad. This is fine:

float fx = 0.0f;float fy = 0.0f;glBegin(GL_QUADS);for (int y = 0; y < mapheight; y++, fy += 1.0f){  for (int x = 0; x < mapwidth; x++, fx += 1.0f)  {    glTexCoord2f(0.0f, 0.0f);glVertex3f(fx, fy, 0.0f);    glTexCoord2f(1.0f, 0.0f);glVertex3f(fx + 1.0f, fy, 0.0f);    glTexCoord2f(1.0f, 1.0f);glVertex3f(fx + 1.0f, fy + 1.0f, 0.0f);    glTexCoord2f(0.0f, 1.0f);glVertex3f(fx, fy + 1.0f, 0.0f);  }}glEnd();

##### Share on other sites
Thank you for the very quick answer. This code works fine but it is not much faster
I have a second question.

Should i use Quadtree for large maps?
and if yes how can i do this in a 2d map?

[Edited by - Napster23 on July 18, 2005 4:40:04 AM]

##### Share on other sites
I'm assuming that code there draws all the tiles in your map. I doubt you'd need anything as complex as a quadtree, especially if your camera is at fixed zoom level. Simply determine which tiles are on screen and only render them. Hell, it can still be done with a variable zoom level.

##### Share on other sites
i want to make a map in ortho mode with iso view.

can you give me a piece of code how i can only render the tiles in the viewport?
Would be really nice.

##### Share on other sites
Quote:
 Original post by Napster23Hallo,i have a problem with tiling.How can i optimize this part of code?

Try this somewhere in your startup code (DO NOT call this every frame, just once at the beginning !):
unsigned int dlist = glGenLists(1);glNewList(dlist, GL_COMPILE);glBegin(GL_QUADS);for (int y = 0; y < mapheight; y++){	for (int x = 0; x < mapwidth; x++)	{	glTexCoord2f(0.0f, 0.0f);glVertex3f(float(x), float(y), 0.0f);	glTexCoord2f(1.0f, 0.0f);glVertex3f(float(x + 1), float(y), 0.0f);	glTexCoord2f(1.0f, 1.0f);glVertex3f(float(x + 1), float(y + 1), 0.0f);	glTexCoord2f(0.0f, 1.0f);glVertex3f(float(x), float(y + 1), 0.0f);	}}glEnd();glEndList();

Then, every frame you render your stuff by executing the display list:
glCallList(dlist);

Although faster than manual immediate mode, the real speed up will only come from using proper frustum culling and VBOs. But for starters, a display list is already a good approach.

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633344
• Total Posts
3011438
• ### Who's Online (See full list)

There are no registered users currently online

×