Hi,
Can’t get more basic than that. I’m trying to tile a texture to cover the entire screen:
//in h file:
ofImage bg;
//in setup:
bg.load("bg.png");
bg.getTexture().setTextureWrap(GL_REPEAT, GL_REPEAT);
//in draw
bg.draw(ofGetWindowRect());
The texture is being stretched and not wrapped. What am I missing here?
Thanks in advance,
Tal
lilive
March 16, 2015, 7:07pm
#2
Hi,
bg.draw(ofGetWindowRect());
ask OF to draw the image streched to the entire screen.
Found in the forum:
This used to work, but now it defaults to GL_CLAMP_TO_EDGE
img.getTextureReference().setTextureWrap(GL_REPEAT, GL_REPEAT);
img.width = ofGetWidth();
img.height = ofGetHeight();
img.draw(0, 0);
Even ofSetTextureWrap(GL_REPEAT, GL_REPEAT) is ineffective now.
Any ideas?
The solution is here:
of-texture-tiling-win.cpp
ofImage img;
ofTexture texture;
ofPlanePrimitive plane;
float tx0, ty0, tx1, ty1;
void ofApp::setup(){
ofDisableArbTex();
img.loadImage("test.jpg");
texture = img.getTextureReference();
texture.setTextureWrap(GL_REPEAT, GL_REPEAT);
This file has been truncated. show original
In your case:
ofImage bgImage;
ofPlanePrimitive bgPlane;
void ofApp::setup(){
ofDisableArbTex();
bgImage.loadImage("image.jpg");
bgImage.getTextureReference().setTextureWrap( GL_REPEAT, GL_REPEAT );
bgPlane.set( ofGetWidth(), ofGetHeight(), 2, 2 );
bgPlane.setPosition( ofGetWidth() * 0.5f, ofGetHeight() * 0.5f, 0.f );
bgPlane.mapTexCoords( 0, 0, ofGetWidth() / (float)bgImage.width, ofGetHeight() / (float)bgImage.height );
}
void ofApp::draw(){
bgImage.bind();
bgPlane.draw();
bgImage.unbind();
}
src.zip (1.2 KB)
arturo
March 16, 2015, 8:28pm
#3
to tile a texture you need texture coordinates further than the maximum size of the orignal image (or 1 if using normalized tex coordinates) the default draw for a texture will always generate a rectangle with the maximum tex coordinates.
//.h
ofVboMesh quad;
//setup
quad.addVertex(0,0);
quad.addTexCoord(0,0);
quad.addVertex(ofGetWidth(),0);
quad.addTexCoord(ofGetWidth(),0);
quad.addVertex(ofGetWidth(),ofGetHeight());
quad.addTexCoord(ofGetWidth(),ofGetHeight());
quad.addVertex(0,ofGetHeight());
quad.addTexCoord(0,ofGetHeight());
quad.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
//draw
texture.bind();
quad.draw();
texture.unbind();
2 Likes