Sign in to follow this  

Horizontal/Vertical Banding

This topic is 3595 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

Hey guys. This is a minor glitch in my program that has annoyed me for some time. I'm making a game that's based on a generic 2D tiling system. Each different type of tile is held in a list, and displayed on the screen based on its (x, y) coordinates. The problem is that when scrolling across the 'map', at certain points, the top row of pixels and the bottom row of pixels on each tile seem to swap. The same happens on the left and right sides of the tiles. This results in small, but irritating horinzontal/vertical bands. Here's the relevant code (it removed all 'plus' symbols, so i replaced them with 'PLUS'): Building Lists:
[source lang=cpp]
/* Build the Tile lists */
for(int loop=0;loop<tottiles; loopPLUSPLUS) /* loop for every type of tile */
{	
	glNewList(tilelist PLUS loop,GL_COMPILE); 
		glBindTexture(GL_TEXTURE_2D, tiletexture[loop]); /* apply the wanted testure */		
                   glEnable(GL_TEXTURE_2D);
					
			glBegin(GL_QUADS);	/* create the tile */
				glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
				glTexCoord2f(1.0f,1.0f); glVertex3f( -0.488f, 1.0f, 0.0f);
				glTexCoord2f(1.0f,0.0f); glVertex3f( -0.488f, 0.5f, 0.0f);
				glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f, 0.5f, 0.0f);
			glEnd();

		glDisable(GL_TEXTURE_2D);
	glEndList();
}




Drawing 'Map':
[source lang=cpp]
for(int i=0; i<10; iPLUSPLUS) /* map's x-axis */
{
	for(int j=0; j<10; jPLUSPLUS) /* map's y-axis */
	{
		glTranslatef(float(0.512f*i), float(-0.5*j), 0.0f);   /* ensure tiles are drawn in their correct positions */
					
			glCallList(tile[i][j].terrain);	  /* display the appropriate list */
							
		glTranslatef(float(-0.512f*i), float(0.5*j), 0.0f);	
	}
}



If you need more information such as the the texture creation code (NeHe's method) or anything, please let me know. Any help/suggestions would be greatly appreciated! Thanks

Share this post


Link to post
Share on other sites
loopPLUSPLUS [crying]

Are you using GL_LINEAR filtering and scaling the tiles?

If so you can try using GL_NEAREST or adding a one-pixel transparent border and adjusting your UV coordinates.

The other thing you could try is clamping your translation vector when drawing the map to integer values.

But performance wise, changing the texture for every tile is a no-no. You should have a tile sheet, and "blit" the tile from that larger sheet so you don't have to change the texture.

Share this post


Link to post
Share on other sites
Quote:
loopPLUSPLUS
Yeah, I dunno why it deleted all of my 'plus' symbols, strange.


Anyway, I managed to fix the issue. GL_NEAREST didn't improve the situation so I started messing with the texture coordinates.

Using values of 0.99f instead of 1.0f seems to have fixed it, eg.

glTexCoord2f(0.0f,0.99f);

It's probably not a very 'professional' way of doing things but then again I am only a hobbyist programmer.

As to the changing textures, you are completely right, I didn't even think about the effect it had on performance. The process only happens once at the start of the program so fixing it won't be a huge priority, but I will surely get to it eventually to reduce my startup times.

Thanks for the help Boder [smile]

Share this post


Link to post
Share on other sites
It's not that it hurts your start-up times, it's that it hurts your game's performance to switch textures constantly. Having all your tiles on one big tile texture saves you from having to switch textures as often.

Share this post


Link to post
Share on other sites
Quote:
It's not that it hurts your start-up times, it's that it hurts your game's performance to switch textures constantly. Having all your tiles on one big tile texture saves you from having to switch textures as often.
If I'm just calling lists, does it still have to switch textures when I display them? I thought it stored the whole list including it's texture, and just displayed it from memory without having to 'switch textures' and stuff. Maybe I misunderstood when I learned about lists.
Quote:
Have you tried to use GL_CLAMP_TO_EDGE?
This is the first time I've heard of 'GL_CLAMP_TO_EDGE', so I'll Google it and try to apply it.

Thanks alot [smile]

Share this post


Link to post
Share on other sites

This topic is 3595 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.

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