@edapx wrote:
Hello, I am building an application that has 2 windows, an editor and the main application that contains some visuals tuned by the editor. This is the main.cpp file to be clear
#include "ofMain.h" #include "ofApp.h" #include "Editor.h" int main( ){ ofGLFWWindowSettings settings; settings.setGLVersion(3, 2); // Main GUI settings.setSize(700, 700); settings.setPosition(ofVec2f(0,0)); settings.resizable = true; shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings); shared_ptr<Editor> editor(new Editor); // App. settings.setSize(1400, 700); settings.setPosition(ofVec2f(300,0)); settings.resizable = true; settings.shareContextWith = guiWindow; // this allows to read the texture generated in the editor shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings); shared_ptr<ofApp> mainApp(new ofApp); mainApp->editor = editor; ofRunApp(guiWindow, editor); ofRunApp(mainWindow, mainApp); ofRunMainLoop(); }
The Editor class, is generating the texture for a cube map. The App class, read that texture and draw it to the screen.
Editor.h#pragma once #include "ofMain.h" #include "TextureManager.h" class Editor: public ofBaseApp { public: void setup(); void update(); void draw(); // ... TextureManager textureManager; };
TextureManager.cpp
void TextureManager::setup(){ int width = 100; int deep = 100; int height = 100; ofDisableArbTex(); finalFbo.allocate(width*2+deep*2, deep*2+height); finalFbo.begin(); ofClear(255, 255, 255, 0); finalFbo.end(); } void TextureManager::update(){ } void TextureManager::draw(){ float side = 100; finalFbo.begin(); ofClear(255, 255, 255, 0); ofPushStyle(); if(drawFront){ ofSetColor(ofFloatColor::cyan); ofDrawRectangle(deep*2 + width, deep, width, height); } if(drawLeft){ ofSetColor(ofFloatColor::red); ofDrawRectangle(0, deep, deep, height); } if(drawRight){ ofSetColor(ofFloatColor::fuchsia); ofDrawRectangle(deep+width, deep, deep, height); } if(drawBack){ ofSetColor(ofFloatColor::yellow); ofDrawRectangle(deep, deep, width, height); } if(drawTop){ ofSetColor(ofFloatColor::darkBlue); ofDrawRectangle(deep, 0, width, deep); } if(drawBottom){ ofSetColor(ofFloatColor::green); ofDrawRectangle(deep, width+height, width, deep); } ofPopStyle(); finalFbo.end(); finalFbo.getTexture().draw(0,0); };
App.cpp
#include "ofApp.h" void ofApp::update(){ editor->textureManager.update(); } void ofApp::draw(){ ofDrawBitmapString(ofGetFrameRate(),10,10,0); editor->textureManager.finalFbo.getTexture().draw(0,0); }
It works, as you in this picture where the window with the black background is the editor, and the gray one is the app.
But as soon as I move the generation of the texture in the TextureManager from the
draw
method to theupdate
method, like:void TextureManager::update(){ finalFbo.begin(); ofClear(255, 255, 255, 0); ofPushStyle(); if(drawFront){ ofSetColor(ofFloatColor::cyan); ofDrawRectangle(deep*2 + width, deep, width, height); } if(drawLeft){ ofSetColor(ofFloatColor::red); ofDrawRectangle(0, deep, deep, height); } if(drawRight){ ofSetColor(ofFloatColor::fuchsia); ofDrawRectangle(deep+width, deep, deep, height); } if(drawBack){ ofSetColor(ofFloatColor::yellow); ofDrawRectangle(deep, deep, width, height); } if(drawTop){ ofSetColor(ofFloatColor::darkBlue); ofDrawRectangle(deep, 0, width, deep); } if(drawBottom){ ofSetColor(ofFloatColor::green); ofDrawRectangle(deep, width+height, width, deep); } ofPopStyle(); finalFbo.end(); }; void TextureManager::draw(){ finalFbo.getTexture().draw(0,0); };
the texture in the main App it it does not have the correct size, proportion and orientation. It look like this
It happens on Mac and Linux, I am using of 0.10. Does anyone have a clue about what’s going on?
Posts: 5
Participants: 2