Hi there,
For a project of mine i would like to draw to an ofFbo and use that as a texture via ofFbo::getTextureReference().
As a test i built a small project where i tried to do it, but no chance. The sphere will stay black whatever i do.
My h-file:
#pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofImage earth, texta;
GLUquadricObj *quadric;
ofTexture text;
ofFbo fbo;
};
my cpp-file:
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(0,0,0);
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofDisableArbTex(); //needed for textures to work with gluSphere
earth.loadImage("earth.jpg");
//text = earth.getTextureReference();
fbo.allocate(2048, 1024, GL_RGB, 2);
int xMax = earth.getWidth()*3;
int yMax = earth.getHeight();
unsigned char pixels[xMax * yMax];
for(int y = 0; y < yMax; y++) {
for(int x = 0 ; x < xMax; x++) {
pixels[x+y] = (int)(255 * ofRandomuf());
}
}
//earth.reloadTexture();
//texta.setFromPixels(pixels);
text.allocate(xMax/3, yMax, GL_RGB);
text.loadData(pixels, xMax/3, yMax, GL_RGB);
}
//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
fbo.begin();
glDisable(GL_DEPTH_TEST);
ofSetColor(255);
//ofSphere(20);
earth.draw(20,20);
fbo.end();
glEnable(GL_DEPTH_TEST); //enable depth comparisons and update the depth buffer
//fbo.draw(0,0);
//change origin to center
ofTranslate(ofGetWidth()/2, ofGetHeight()/2, 0);
//rotate sphere over time
ofRotateY(ofGetFrameNum());
//ofRotateX(); //north pole facing up
//bind and draw texture
//texta.draw(0,0);
ofSetColor(255);
fbo.getTextureReference().bind();
ofScale(10, 10, 10);
//ofSphere( 200);
glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (10.0, 0.0, 0.0);
glTexCoord2f (1.0, 1.0);
glVertex3f (10.0, 10.0, 0.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0.0, 10.0, 0.0);
glEnd ();
fbo.getTextureReference().unbind();
//fbo.draw(0,0);
}
you can also download all the files (including the textures) her -> http://dl.dropbox.com/u/8807406/planetRenderTest.zip