LoginSignup
23
22

More than 5 years have passed since last update.

マルチウィンドウ間で映像を共有する

Last updated at Posted at 2016-03-07

更新履歴
10/24:文言のアップデート

 openFrameworksのv0.9.0から、マルチウィンドウが標準機能で実装できるようになりました。さらに、マルチウィンドウにおいて、ofFboのテクスチャを共有することが可能です。

マルチウィンドウについては以下のExampleをチェック

  • events/multiWindowExample
  • events/multiWindowOneAppExample

ofFboのテクスチャを共有するには

 さて、テクスチャ共有は簡単です。ウィンドウのセッティングに一行追記するだけで実現できます。
以下のソースは、GUIウィンドウとメインウィンドウを作成。GUI側で読み込んだmovファイルをメインウィンドウ側でも描画したものです。

マルチウィンドウ設定

サブウィンドウにsettings.shareContextWith = mainWindow;を追記

main.cpp
int main( ){

    ofGLFWWindowSettings settings;

    settings.width = 1280;
    settings.height = 720;
    settings.setPosition(ofVec2f(600, 0));
    settings.resizable = true;
    shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);

    settings.width = 640;
    settings.height = 360;
    settings.setPosition(ofVec2f(0,0));
    settings.resizable = false;
    settings.shareContextWith = mainWindow;
    shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings);

    shared_ptr<ofApp> mainApp(new ofApp);
    shared_ptr<GuiApp> guiApp(new GuiApp);
    mainApp->gui = guiApp;

    ofRunApp(guiWindow, guiApp);
    ofRunApp(mainWindow, mainApp);
    ofRunMainLoop();
}

サブウィンドウ側

サブウィンドウ側では、映像ファイルをロードしfboに格納

guiApp.h
    ofVideoPlayer layer;
    ofFbo fbo;
guiApp.cpp
void GuiApp::setup(){
    layer.load("clips/01.mov");
    layer.play();
    fbo.allocate(1280, 720, GL_RGB32F_ARB);
}

void GuiApp::update(){
    layer.update();
    fbo.begin();
    layer.draw(0, 0, 1280, 720);
    fbo.end();
}

void GuiApp::draw(){
    fbo.draw(0, 0, 128, 72);
}

メインウィンドウ側

 メインウィンドウ側からfboのテクスチャーを呼び出し描画

ofApp.cpp
void ofApp::draw(){
    gui->fbo.getTexture().draw(0, 0, ofGetWidth(), ofGetHeight());
}

 サブウィンドウにGUIとFboのテクスチャ、メインウィンドウ側でFboのテクスチャを読み出します。

 これで、サブウィンドウでソースを確認しつつ、メインウィンドウ側のmovファイルの透明度を操作するということが可能になります。
out.gif

23
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
22