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
Texture Border Artifacts
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:
Ideas?
Thanks,
Geometrian
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.
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.
Great! That worked, thank you! Added:before:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement