Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

Texture Border Artifacts

This topic is 3671 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

Hello, In my program, there are several textures with colorkey transparency. The picture below is one such texture seen in game: As you can see, the main texture is red, and the curved/diagonal section is made by the transparency, but there is a strange thin red line along the edge of the texture which shouldn't be there. This problem recurs on various other textures as well. I've thoroughly checked all my textures, and they are all correct--they don't have that line. Obviously, this little artifact is annoying and should be disposed of. Here is my texture loading code:
def Texture(path,colorkey=None,alpha=False,convertalpha=False,Size=False,Surface=False):
    texture = glGenTextures(1)
    surface = pygame.image.load(path)
    if convertalpha:surface = surface.convert_alpha()
    else:surface = surface.convert()
    if alpha != False:surface.set_alpha(alpha)
    if colorkey != None:surface.set_colorkey(colorkey)
    Data = pygame.image.tostring(surface,"RGBA",1)
    glBindTexture(GL_TEXTURE_2D,texture)
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,surface.get_width(),surface.get_height(),0,GL_RGBA,GL_UNSIGNED_BYTE,Data)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
##    gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,Surface.get_width(),Surface.get_height(),GL_RGB,GL_UNSIGNED_BYTE,Data)
    if not Size and not Surface:
        return texture
    if Size and not Surface:
        return texture,surface.get_size()
    if not Size and Surface:
        return texture,surface
    if Size and Surface:
        return texture,surface.get_size(),surface
Ideas? Thanks, Geometrian

Share this post


Link to post
Share on other sites
Advertisement
Ok, so I think the problem has to do with the texture wrapping. If the textures are set to wrap when they are using a filter, they will filter as if the borders are neighboring the borders of the other side. I bet if you use

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

and comment out (I don't think it's this way by default, but maybe)

//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

you will not see the annoying red line in empty space.

Share this post


Link to post
Share on other sites
Great! That worked, thank you! Added:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
before:
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)

Share this post


Link to post
Share on other sites
It's better to use

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

on certain GPU/drivers that implement GL_CLAMP correctly. You would see a border on these cards. Your system is probably treating GL_CLAMP as GL_CLAMP_TO_EDGE.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!