Hey Sam,
The issue here is that TD’s CPlusPlus TOP FBO is left unbound after ofFbo::end, so you must simply rebind it after you are done using an ofFbo and want to use TD’s instead. TD’s FBO index is stored in the TOP Context class. You can rebind like so:
glBindFramebuffer(GL_FRAMEBUFFER, context->getFBOIndex());
Here is the chunk of code in ::setup
void OpenFrameworksTOP::setup()
{
glewInit();
renderer->setup(3, 2);
ofFbo::Settings settings(renderer);
settings.width = 1280;
settings.height = 720;
settings.numSamples = 0;
settings.internalformat = GL_RGBA;
fbo.allocate(settings);
#ifdef TARGET_OPENGLES
shader.load("shadersES2/shader");
#else
if(ofIsGLProgrammableRenderer())
{
shader.load("shadersGL3/shader");
}
else
{
shader.load("shadersGL2/shader");
}
#endif
isSetup = true;
}
and ::execute
void
OpenFrameworksTOP::execute(const TOP_OutputFormatSpecs* outputFormat,
OP_Inputs* inputs,
TOP_Context *context)
{
double xPos = inputs->getParDouble("Translation");
int width = outputFormat->width;
int height = outputFormat->height;
// Use the first input TOP (here we assume it exists but in reality it might not)
const OP_TOPInput *topInput = inputs->getInputTOP(0);
ofTexture texture;
texture.setUseExternalTextureID(topInput->textureIndex);
texture.texData.width = topInput->width;
texture.texData.height = topInput->height;
texture.texData.tex_w = topInput->width;
texture.texData.tex_h = topInput->height;
texture.texData.tex_t = 1.0f;
texture.texData.tex_u = 1.0f;
texture.texData.textureTarget = topInput->textureType;
texture.texData.bFlipTexture = true;
// Need to use a ofAppNoWindow so that openFrameworks doesn't create a conflicting
// OpenGL context. We want to use TouchDesigner's context in ::execute
ofSetupOpenGL(&myWindow, width, height, OF_WINDOW);
context->beginGLCommands();
// shaders must be loaded within the TouchDesigner context
if (!isSetup)
{
setup();
}
fbo.begin();
renderer->clear(255, 255, 255, 0);
renderer->draw(texture, 0, 0, 0, 1280, 720, 0, 0, 1280, 720);
fbo.end();
auto t = fbo.getTexture();
glBindFramebuffer(GL_FRAMEBUFFER, context->getFBOIndex());
begin();
shader.setUniform1f("xPos", (float)-xPos);
renderer->draw(t, 0, 0, 0, 1280, 720, 0, 0, 1280, 720);
end();
context->endGLCommands();
}