PDA

View Full Version : GL_TEXTURE_BORDER_COLOR



Semi-Automatic-Munky
04-12-2001, 03:53 AM
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?.

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);


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

DaViper
04-12-2001, 03:56 AM
Did you specify a border??

Semi-Automatic-Munky
04-12-2001, 04:00 AM
How do you mean?

If you mean have I put anything into
glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_C OLOR,color);

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

Thanks.

Deiussum
04-12-2001, 04:51 AM
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
);

...

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

Semi-Automatic-Munky
04-12-2001, 05:27 AM
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 =/

Semi-Automatic-Munky
04-12-2001, 06:09 AM
This is very strange. It only crashes if you use a 256* 256 texture, use a 64*64 or 128*128 and in runs, until you select that texture, then it slows right down and draws a nonesense texture.

j
04-12-2001, 07:00 AM
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.

j

Semi-Automatic-Munky
04-12-2001, 07:35 AM
Hmmm,
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.

j
04-12-2001, 08:09 AM
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.

j

Semi-Automatic-Munky
04-12-2001, 08:15 AM
Driver thing makes sense, very annoying though.
Do you think it is possible to stop it defauling to GL_CLAMP_TO_EGDE?

Thanks.

Remind me to slap the graphics card people about.

Stephen Brooks
03-01-2011, 01:15 PM
I came across the exact same thing and I think I have the solution: you should use GL_CLAMP_TO_BORDER e.g.:


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP_TO_BORDER);
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
glTexCoord2f(1+0.5/64,1+0.5/64);

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.