PDA

View Full Version : Texture Outlines



Fezziwig
03-19-2012, 02:25 PM
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:



glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Tex_Terrain = SOIL_load_OGL_texture("Data/Mud_Terrain.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_MIPMA PS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);

The drawn function is like this:



void Draw_Texture(float x, float y, float width, float height, float Angle, GLuint texture)
{
glPushMatrix();
glBindTexture(GL_TEXTURE_2D,texture);
glTranslatef(x, y, 0);
glRotatef(Angle, 0, 0, 1);
glBegin(GL_QUADS);
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);
glEnd();
glPopMatrix();
}

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.

Thanks,
Rowan

carsten neumann
03-19-2012, 04:22 PM
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 ;)
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.

BionicBytes
03-20-2012, 05:53 AM
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.

Fezziwig
03-20-2012, 09:20 AM
Um.. maybe these images would help.
Screenshot:
http://i.imgur.com/Syt28.png
Terrain texture:
http://i.imgur.com/Sl3Pl.png
The outlines are more visible when the terrain is rotated:
http://i.imgur.com/LcHC2.png

hope this helps illustrated my problem.

Fezziwig
03-20-2012, 09:45 AM
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?

Fezziwig
03-21-2012, 10:10 AM
Ah, Solved :).
Rather than using a for loop to draw lots of squares I should have been drawing a large square with these parameters.

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);

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