How to set border mode for image texture?

void ofApp::draw(){
	ofSetColor(255);
	img_.bind();
	ofMesh mesh;
	int vx0 = 0; int vy0 = 0;int vx1 = 500; int vy1 = 500;
	int tx0 = 0; int ty0 = 0;int tx1 = 500; int ty1 = 500;
	mesh.addVertex(ofPoint(vx0, vy0)); mesh.addTexCoord(ofPoint(tx0, ty0));
	mesh.addVertex(ofPoint(vx1, vy0)); mesh.addTexCoord(ofPoint(tx1, ty0));
	mesh.addVertex(ofPoint(vx1, vy1)); mesh.addTexCoord(ofPoint(tx1, ty1));
	mesh.addVertex(ofPoint(vx0, vy1)); mesh.addTexCoord(ofPoint(tx0, ty1));
	mesh.addIndex(0); mesh.addIndex(1);	mesh.addIndex(2);
	mesh.addIndex(0); mesh.addIndex(3); mesh.addIndex(2);
	mesh.draw();
	img_.unbind();
}

I use this code to draw a part of an image. the problem is, if the texture coordinate is larger than the image size(tx1 in my code), it will just duplicate the image border. I want that it just uses solid color(say black) to fill that part. how could i do this?

you need to set the wrapping mode:

img_,setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);

assuming img is a texture, if it’s an ofImage just call getTexture().setTextureWrap.

Setting the border color is not supported directly by OF right now but you can use:

img_.bind();
ofFloatColor color(1.0,1.0,1.0,1.0);
glTexParameterfv(GL_TEXTURE_RECTANGLE, GL_TEXTURE_BORDER_COLOR, &color.r);
img_.unbind();
2 Likes

thanks so much! it works!
p.s. seems that the default color is just black.