# I'm getting thin black borders on textured quads

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

## Recommended Posts

I'm working a new rig with an ATI card after working on one with an nVidia card. On a recompile on my new rig and running it, I get black borders around my textures. My original code that worked on nVidia cards:
    glBindTexture( GL_TEXTURE_2D, sprites.get_texture() );

glTexCoord2f( 0.f, 0.f );
glVertex2f( -23.f, -23.f );

glTexCoord2f( sprites.width() / sprites.t_width(), 0.f );
glVertex2f(  23.f, -23.f );

glTexCoord2f( sprites.width() / sprites.t_width(), sprites.height() / sprites.t_height() );
glVertex2f(  23.f,  23.f );

glTexCoord2f( 0.f, sprites.height() / sprites.t_height() );
glVertex2f( -23.f,  23.f );

glEnd();


Now, I can get the black borders to disappear by shifting the texture coordinates half a texel:
    glBindTexture( GL_TEXTURE_2D, sprites.get_texture() );

GLfloat s = ( 1.f / sprites.t_width() ) / 2.f;
GLfloat t = ( 1.f / sprites.t_height() ) / 2.f;

glTexCoord2f( 0.f + s, 0.f + t );
glVertex2f( -23.f, -23.f );

glTexCoord2f( sprites.width() / sprites.t_width() - s, 0.f + t );
glVertex2f(  23.f, -23.f );

glTexCoord2f( sprites.width() / sprites.t_width() - s, sprites.height() / sprites.t_height() - t );
glVertex2f(  23.f,  23.f );

glTexCoord2f( 0.f + s, sprites.height() / sprites.t_height() - t );
glVertex2f( -23.f,  23.f );

glEnd();


But is there a more elegant way to do this?

##### Share on other sites
tried fiddling with the clamp mode?
GL_CLAMP_TO_EDGE / GL_REPEAT etc?

I would suggest this is a subpixel accuracy problem, also try making your texture coordinates slightly less than 1.0f (e.g. 0.95f) and see if that gives you any hints..

##### Share on other sites
Quote:
 Original post by silvermacetried fiddling with the clamp mode?GL_CLAMP_TO_EDGE / GL_REPEAT etc?

I tried doing that for both S and T, but it would just make the black borders show up on 2 of the 4 sides.

Quote:
 Original post by silvermaceI would suggest this is a subpixel accuracy problem, also try making your texture coordinates slightly less than 1.0f (e.g. 0.95f) and see if that gives you any hints..

This is what the second block of code does. It fixes the problem, but I was hoping there was a neater way of doing it.

##### Share on other sites
If you are using some sort of texture atlas I would suggest having a small border around each texture. If you are using one texture for each sprite it should be OK to wrap your texture coordinates around the quad using 0.0-1.0. That's what I do with my ATI/nvidia cards.