Jump to content
  • Advertisement
Sign in to follow this  
Lazy Foo

I'm getting thin black borders on textured quads

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

If you intended to correct an error in the post then please contact us.

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
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..

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!