Skip to main content
gamedev.net
🔒 Locked

Texture border troubles...

Started by ill Jun 25, 2010 at 10:13 PM 0 replies 450+ views
Original Post
ill
ill
I'm doing a hardware accelerated 2D game, so I'm rendering textured quads with the sprites being the textures.

I'm having issues with the texture borders bleeding out. I tried using GL_CLAMP for GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T but it seems to have no effect. GL_CLAMP_TO_EDGE seems to have the exact same effect as GL_CLAMP. I seem to not have this problem when I try running the game on Windows but I like to code under Linux and I feel like the MESA 3D OpenGL implementation for Linux might be the cause.

One solution to this problem is to just have all my sprites have a 1 pixel border around them of black color with 0 alpha but this would take a lot of work. One thing I can do also is to have my texture loading function add the borders automatically that way the original images don't have to be changed but I don't want to do this until I can come up with a better solution, or just take the easy way out and do the border thing.

I'm trying to write the game so it's cross platform compatible for Windows, Linux, and Mac and want it to look good on all systems so I want the texture edges to look right on Linux.

I read this in one of the OpenGL extension specs and this sounds like what I want.

OpenGL texturing is limited to images with power-of-two dimensions
and an optional 1-texel border.

I can't find info on how to enable this border. Sounds like using this border would ensure the sprite edges are properly drawn without annoying bleeding.

Here's the important part of the Texture loading code with the DevIL and file reading stuff omitted.

    //////////////////////////////////    //pad image if not power of 2    paddedWidth = nextPow2(m_width);    paddedHeight = nextPow2(m_height);    if(paddedWidth != m_width || paddedHeight != m_height)    {        imageData = new ILubyte[paddedWidth * imageBPP * paddedHeight];        gluScaleImage(ilGetInteger(IL_IMAGE_FORMAT), m_width, m_height, GL_UNSIGNED_BYTE, ilGetData(),            paddedWidth, paddedHeight, GL_UNSIGNED_BYTE, imageData);    }    else    {        imageData = ilGetData();    }    /////////////////////////////    //set texture attributes    glGenTextures(1, &m_texture);    glBindTexture(GL_TEXTURE_2D, m_texture);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);    /////////////////////////////    //create texture in OpenGL    gluBuild2DMipmaps(GL_TEXTURE_2D, imageBPP, paddedWidth, paddedHeight,        ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, imageData);


I use mipmaps so sprites look good scaled up and down and when the game is running at a resolution different from the view port because that also causes the textures to rescale.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.