Commit 773570e5 authored by w4t's avatar w4t

Multiwindow hold each instance's context and switch them and example

parent bd655e50
ofxImGui
ofxXmlSettings
\ No newline at end of file
#include "ofMain.h"
#include "ofApp.h"
#include "ofAppGLFWWindow.h"
//========================================================================
int main( ){
ofGLFWWindowSettings settings;
settings.setSize(300, 300);
settings.setPosition(ofVec2f(0, 100));
auto window1 = ofCreateWindow(settings);
settings.setPosition(ofVec2f(300, 100));
auto window2 = ofCreateWindow(settings);
auto app1 = std::make_shared<ofApp>();
auto app2 = std::make_shared<ofApp>();
ofRunApp(window1, app1);
ofRunApp(window2, app2);
ofRunMainLoop();
}
#include "ofApp.h"
\ No newline at end of file
#pragma once
#include "ofMain.h"
#include "ofxImGui.h"
class ofApp : public ofBaseApp{
public:
ofApp() : v(0) {}
void setup() {
gui.setup();
}
void draw() {
gui.begin();
ImGui::SliderFloat("slider", &v, 0.f, 10.f);
gui.end();
}
private:
ofxImGui::Gui gui;
float v;
};
...@@ -12,19 +12,19 @@ namespace ofxImGui ...@@ -12,19 +12,19 @@ namespace ofxImGui
: lastTime(0.0f) : lastTime(0.0f)
, theme(nullptr) , theme(nullptr)
{ {
ImGui::CreateContext(); context = ImGui::CreateContext();
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
Gui::~Gui() Gui::~Gui()
{ {
exit(); exit();
ImGui::DestroyContext(); ImGui::DestroyContext(context);
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
void Gui::setup(BaseTheme* theme_, bool autoDraw_) { void Gui::setup(BaseTheme* theme_, bool autoDraw_) {
ImGui::CreateContext(); ImGui::SetCurrentContext(context);
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)ofGetWidth(), (float)ofGetHeight()); io.DisplaySize = ImVec2((float)ofGetWidth(), (float)ofGetHeight());
...@@ -66,7 +66,7 @@ namespace ofxImGui ...@@ -66,7 +66,7 @@ namespace ofxImGui
} }
loadedTextures.clear(); loadedTextures.clear();
ImGui::DestroyContext(); ImGui::DestroyContext(context);
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
...@@ -165,6 +165,7 @@ namespace ofxImGui ...@@ -165,6 +165,7 @@ namespace ofxImGui
//-------------------------------------------------------------- //--------------------------------------------------------------
void Gui::begin() { void Gui::begin() {
ImGui::SetCurrentContext(context);
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
float currentTime = ofGetElapsedTimef(); float currentTime = ofGetElapsedTimef();
......
...@@ -63,5 +63,6 @@ namespace ofxImGui ...@@ -63,5 +63,6 @@ namespace ofxImGui
BaseTheme* theme; BaseTheme* theme;
std::vector<ofTexture*> loadedTextures; std::vector<ofTexture*> loadedTextures;
ImGuiContext* context;
}; };
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment