about the texture coordinate offset

Hi,OpenGL guru:
there is a 2D texture mapped to a rectangle, and I set the texture parameter as follows:
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

When I shift one texel the texture coordinate to the left side, the rectangle right border’s color is same to the color of the nearnest texel.
But I want the extension part’s color to be zero.

Do I make myself clear? And can anyone come up with any suggestions?

Thanks a lot.

Set the constant texture border color to black, then set the wrapping mode to clamp to border. Something like this:

const GLfloat black[4] = { 0, 0, 0, 1 };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, black);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

– Tom

Thanks a lot.
Your method works.
In previous way, I set the border color, but with
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
So it’s not what I want.

Thanks again.

More about this problem in detail:
for example, there is a texture as follows:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
In ortho mode, I bind this texture to a square which vertices are(0,0),(4,0),(4,4),(0,4). If I set the texture parameters as follows, I can get the correct result from glReadPixel into an array which is same to the above texture data.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

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

glTexImage2D( GL_TEXTURE_2D, 0, 1, DimX, DimY, 0, GL_RED, GL_UNSIGNED_BYTE, TextureData );

But the problem is that, I want the array data like follows:
0 2
8 10
which mean I just take half data from the texture.
Here I shrink the square in both directions, but it comes up with what I don’t want.

Can anybody provide the outway? Thanks a lot.

[This message has been edited by foollove (edited 09-09-2003).]

[This message has been edited by foollove (edited 09-09-2003).]