I am creating an app that needs to be projected onto a curved surface. To correct for the warp, I am attempting to map an FBO onto a cylinder to curve the digital image the same amount as the physical screen is curved. I can get a normal ofTexture to map onto the cylinder just fine, but cannot get an FBO texture to do the same.
I have made my FBO a power of two.
I have tried the mapping both with ofEnableArbTex() and ofDisableArbTex().
I can draw the FBO object normally using its draw() method.
I have tried ofxFBOTexture.bindAsTexture(), but it doesn’t seem to give me any texture mapping at all.
Using the .bind() and .unbind() seems to be working, as the color of the cylinder will change depending on the position of the image on the fbo object, but I can’t seem to get it to map the texture correctly.
I have looked over http://forum.openframeworks.cc/t/project-in-a-quot;curvedquot;-surface/2513/2 http://forum.openframeworks.cc/t/apply-video-to-3d-shape/2959/0 http://forum.openframeworks.cc/t/texturing-a-glusphere/1942/0 understanding only bits and pieces and using smatterings of the code where appropriate.
I think I am just mapping the texture wrong, but can’t figure out how to do it right.
Code is as follows:
void testApp::setup(){
//Quad Controls
num_slices = 180;
cylinder_width = 300;
cylinder_height = 300;
x_rotate = 90;
y_rotate = 180;
z_rotate = 30;
cat_image.loadImage("cat.jpg");
//ofImage with a picture of a cat (yes a cat, you are on the internet...)
fbo_tex.allocate(1024, 1024, true);
//tried the code with and without this...
//fbo_tex.clear(1,1,1,1);
// enable depth test, so we only see the front
glEnable(GL_DEPTH_TEST);
}
//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetColor(0xffffff);
fbo_tex.begin();
//draw the image on the fbo (I'm stretching it, but that shouldn't matter...)
//also, moving the image on the fbo changes the color of the cylinder, which makes me think it is a mapping issue
cat_image.draw(0,0, ofGetWidth(), ofGetHeight());
fbo_tex.end();
// create a new quadric to hold our cylinder
GLUquadric* quad = gluNewQuadric();
// tell GLU how to create the cylinder
gluQuadricNormals(quad, GLU_SMOOTH);
gluQuadricDrawStyle(quad, GLU_FILL);
gluQuadricTexture(quad, GL_TRUE);
gluQuadricOrientation(quad, GLU_OUTSIDE);
//move the cylinder where it is seen
ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2 - cylinder_height*.5, 0);
ofRotateX( x_rotate );
ofRotateY( y_rotate );
//I am rotating to make sure the texture isn't hiding on one side or another
ofRotateZ( z_rotate * ofGetElapsedTimef() *4 );
//Bind the fbo texture
fbo_tex.bind();
//fbo_tex.bindAsTexture(); //also tried this here instead
gluCylinder(quad, cylinder_width, cylinder_width, cylinder_height, num_slices, 1);
fbo_tex.unbind();
// delete the cylinder from memory
gluDeleteQuadric(quad);
//fbo_tex.draw(0, 0, ofGetWidth(), ofGetHeight());
//uncommenting here will draw the fbo with the ubiquitous cat picture...
}
Coming from a background of Flash, with bits of Processing and Max/MSP, I have never had to deal with any of this before, so I feel extra lost. Thanks in advance for helping yet one more OF newbie.
I have also looked over http://forum.openframeworks.cc/t/3d-video-texture/3547/0 and I feel the answer might be somewhere down this road, but it hasn’t become clear to me after 3+ readings.