Quite simple GL_TEXTURE_BORDER_COLOR seems to do precicely nothing.
I got it set to clamp, and cant think of any reason why it does nothhing at all, is there something else I need to enable?.

glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);

Please any guidence on the correct way to use this feature would be greatly appreciated.

Did you specify a border??

How do you mean?

If you mean have I put anything into

Then yes I have color as float color[4];


I think he means with regard to glTexImage2D. As you seem to be unaware of this, my guess is the answer is no, you didn’t specify a border.

From MSDN:

void glTexImage2D(
GLenum target,
GLint level,
GLint internalformat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *pixels

The width of the texture image. Must be 2n + 2(border) for some integer n.
The height of the texture image. Must be 2m + 2(border) for some integer m.
The width of the border. Must be either 0 or 1.

Thanks, but still no luck.

glTexImage2D( GL_TEXTURE_2D, 0, 3,2+sizeX, 2+sizeY, 1, GL_RGB, GL_UNSIGNED_BYTE, data);

This makes it crash.

I’m still doing someething horibly wrong somewhere =/

This is very strange. It only crashes if you use a 256* 256 texture, use a 6464 or 128128 and in runs, until you select that texture, then it slows right down and draws a nonesense texture.

Well, texture border color and texture borders are a bit different. When you set the border parameter in glTexImage2D to 1, what you are saying is that you are passing in a 258x258 (or 66x66, or 130x30) image. OpenGL then uses the border pixels in these images as, well, borders.

Texture border color simply sets a single color that the very edge of the texture should be. With GL_CLAMP, a texture coordinate of (0.0f, 0.0f) should give you 1/4 of the lower left hand pixel, and 3/4 of the border color.

Is the border color you want significantly different from the texture color? It’s hard to notice sometimes, especially when the texture resolution is high.


So I dont need to set the border in glTexImage2d();
But still I get nothing. In the book I have it says I can use the border_color and clamping to make a texture appear in one spot on a polygon, as it will clamp the edges to the border color with alpha of 0, then using alpha test it will only texture where the coords are between 0 and 1, and leave the rest of the poly untouched.
Is this possible then? and if the border colour defaults to 0,0,0,0 why when you clamp a texture doesnt it draw black around it.

That’s strange.

Whenever I have GL_CLAMP on, I can clearly see at the border of the texture where it is being blended with the border color.

Maybe a driver thing? If your graphics card decides to use GL_CLAMP_TO_EDGE_EXT instead of GL_CLAMP, that would definitely get rid of the texture border effects.


Driver thing makes sense, very annoying though.
Do you think it is possible to stop it defauling to GL_CLAMP_TO_EGDE?


Remind me to slap the graphics card people about.

I came across the exact same thing and I think I have the solution: you should use GL_CLAMP_TO_BORDER e.g.:

GLfloat color[4]={0,0,0,1};
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);

Why? Because the border is half a texel outside the (0,0)-(1,1) texture area (the “edge” as in GL_CLAMP_TO_EDGE is half a texel inside). Plain GL_CLAMP actually clamps it half way between the last texel of the texture and the border.

To see your border and the texture fading away into it, you’ll need to specify texture coordinates like

glTexCoord2f(-0.5/64,-0.5/64); // For a 64x64 texture

Anyway, yes, a bit of a pain. OpenGL’s texture coordinates make more sense when you’re doing “nearest colour” rather than bilinear interpolation because in the latter case the pure texture colours end up in the middles of texels.