Sign in to follow this  
Lazy Foo

I'm getting thin black borders on textured quads

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() );
    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?

Share this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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