Texture Outlines

I want to draw some terrain tiled terrain but it appears there are outlines or gaps around the textures because there is a visible grid between each tile. Even if I make each tile bigger so that they overlap these annoying outlines are still visible.

The texture is loaded like this:


The drawn function is like this:

void Draw_Texture(float x, float y, float width, float height, float Angle, GLuint texture)
	glTranslatef(x, y, 0);
	glRotatef(Angle, 0, 0, 1);
	glTexCoord2d(0.0,0.0); glVertex2d(-width/2, -height/2);
	glTexCoord2d(1.0,0.0); glVertex2d(width/2, -height/2);
	glTexCoord2d(1.0,1.0); glVertex2d(width/2, height/2);
	glTexCoord2d(0.0,1.0); glVertex2d(-width/2, height/2);

And it is tiled like this:

void Draw_Terrain(void)
	for (int i = 0; i < MAP_WIDTH; i += 64)
		for (int j = 0; j < MAP_HEIGHT; j += 64)
			Draw_Texture(i+32, j+32, 64, 64, 0, Tex_Terrain);

Any glaring problems? Also, how can you tile infinitely?
Any help is much appreciated.


Does your texture correctly repeat, i.e. if there are two copies of it next to each other (outside your program, I’m just talking about the image) are they seamless?

Also, how can you tile infinitely?

You wait a long time :wink:
Well, computers are not fast enough to do thinks infinitely in finite time, so you have to stop somewhere. However, if you decide where to stop based on the camera position, you can make sure that there is always lots of terrain in front of the camera (and really that is the only place that counts, cause everything else is not visible anyway).
For starters you could do this: determine where in the world your camera is, then draw all tiles within a given distance from the camera.

it appears there are outlines or gaps around the textures because there is a visible grid between each tile

Any chance of a picture to describe this as I don’t get it from your words.
Do you mean that your texture wrap modes are not set correctly and are set to GL_CLAMP or GL_CLAMP_TO_EDGE? Usually you would use a texture which is tiled so the clamp mode would be GL_REAPEAT.

Um… maybe these images would help.

Terrain texture:

The outlines are more visible when the terrain is rotated:

hope this helps illustrated my problem.

After some thought I’m suspecting that it has a lot to do with how I make the camera follow the player. because the size of the outline changes as the player moves.

When the character is moved, the next position is calculated, then in the same function I call

glTranslatef(x - next_x, y - next_y, 0);

and then

x = next_x;
y = next_y;

I say this because the problem has only started since I added that. Is that the correct way to make the camera follow the player? and could it be the cause of the problem?

Ah, Solved :).
Rather than using a for loop to draw lots of squares I should have been drawing a large square with these parameters.


I think that was what you were trying to say BionicBytes.