I'm getting thin black borders on textured quads

Started by
2 comments, last by O-san 14 years, 1 month ago
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() );
    glBegin( GL_QUADS );

	    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;

    glBegin( GL_QUADS );

	    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?

Learn to make games with my SDL 2 Tutorials

Advertisement
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..
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Quote:Original post by silvermace
tried 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 silvermace
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..


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.

Learn to make games with my SDL 2 Tutorials

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.

This topic is closed to new replies.

Advertisement