ofxFenster - addon to handle a second window [outdated]

NOTE: This version is still functional but won’t be maintained any longer. See this thread for the new version. [http://forum.openframeworks.cc/index.php/topic,6499.0.html]


This addon provides a second window to draw on.
To use it you have to extend the testApp class

#include "ofMain.h"  
#include "ofxFenster.h"  
class testApp : public ofBaseApp, public ofxFensterListener{  

Then you can override the following functions

	void fensterKeyPressed  (int key);  
	void fensterKeyReleased(int key);  
	void fensterMouseMoved(int x, int y );  
	void fensterMouseDragged(int x, int y, int button);  
	void fensterMousePressed(int x, int y, int button);  
	void fensterMouseReleased(int x, int y, int button);  
	void fensterWindowResized(int w, int h);  

The window has to be initialized before ofRunApp() is called. So you have to open it in main.cpp:

int main( ){  
    ofAppGlutWindow window;  
	ofSetupOpenGL(&window, 1024,768, OF_WINDOW);			// <-------- setup the GL context  
	testApp* app = new testApp;  
	ofxFenster fenster;  
	// this kicks off the running of my app  
	// pass in width and height too:  
	ofRunApp( app );  

for more information you can look at the example files.

download it here: http://underdoeg.com/uploads/cppLibs/ofxFenster/ofxFenster.zip

It is based on information from this thread: http://forum.openframeworks.cc/t/multiple-windows/1325/0.

One missing feature is sharing of the openGL contexts. Currently you can only load a texture or font into one window. To switch the context, use this code within testApp

//load image data  

To save some performance the second window has its own frame rate for update and draw. by default they are both 60. To save cpu you can set them individually with fenster->setFPS(int fpsForUpdate, int fpsForDraw);

I think it would be possible to have multiple windows. But I’m not shure it’s really needed.

Is only tested on OS X 10.6, but should compile on other systems as well.

Updated the files on the original link a little. Now you can use event listeners for draw and update. Use them like this:

ofAddListener(ofxFensterEvents.update, this, &someClass::winUpdate);  
ofAddListener(ofxFensterEvents.draw, this, &someClass::winDraw);  

where you have a class with the following functions:

class someClass{  
void winUpdate(ofxFensterEvent &e);  
void winDraw(ofxFensterEvent &e);  

Currently is only draw and update support.

Also new is: The default behaviour changed. If you don’t overwrite the mouse and key functions they will automatically be routed to the testApp class


hello and thx from Kyoto(but i’m in Brest, France now).

i’m participating to the new theater work of Gisèle Vienne as a visual programmer.
i’m fighting to 3 WUXGA projectors with oF on a mac pro.

i control 3 oF application for each projectors from Max/MSP through OSC.
i made a tiny framework with oF for controlling easily through OSC.
about it, after premier, i will post detail what i do with oF as another topic.

anyway, ofxFenster is very good solution for monitoring what oF is drawing on external display.
i made an example to monitoring what oF is drawing on another window.



hi anagma

thx for your example, glad you can use the addon. I’m considering building your functionality right into the library as an additional function like turnOnMonitoring() or something like that. For now I included your example in the zip file as well. Hope that’s ok?

This release also contains some bugfixes. mousePressed and mouseMove in ofFenster were broken and there was a bug that caused flickering when resizing the fenster. Should be fixed now.


hi underdoeg.

it’s ok.
i’m glad that my example may be contained into the library.
i’m looking forward to update :wink:


I’ve just tried ofxFenster with the monitoring. I’ve started with empty project and added the code found on the monitoring example to copy the content of the main window into a texture and displayed it on the fensterDraw() method. I’m playing a video on the main window and copying it to the fenster window.

some weird things are happening:

  • I cannot change the background color of the fenster window.
  • when I move the mouse or press a key the video flickers/stops on both windos.

is this normal? It’s like when is input the update function for fenster isn’t runned.



Hi Daniel

No, this should not be normal. In a project with ofxFenster I used a lot of mouse and key action and I didn’t have any problems. Changing the background color for the second window also worked.

It’s hard to tell what might be wrong. Maybe you could post some source files?


Hi Underdoeg.

First of all, I’m using OS X 10.5.

here goes my code:

void pixl8r::setup(){
fenster->setBackground(255, 255, 255);
fenster->setBounds(0, 0, 1024, 768);

ofSetWindowPosition(1024, 0);

// set the Interface Window title

previewRect = ofRectangle(0, 0, 320, 240);


void pixl8r::update(){


void pixl8r::draw(){

void pixl8r::fensterUpdate(){
ofBackground(0, 0, 0);
videoOutputImage.grabScreen(0, 0, ofGetWidth(), ofGetHeight());

void pixl8r::fensterDraw(){

// get the output and copy it into a texture
if(! bTexInit){
tex.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
bTexInit = true;
tex.loadData(videoOutputImage.getPixels(), videoOutputImage.getWidth(), videoOutputImage.getHeight(), GL_RGB);

tex.draw(previewRect.x, previewRect.y, previewRect.width, previewRect.height);

I believe I’m following correctly the examples.


thx. i’m busy right now, but i’ll look at it tomorrow.

Hi, sorry for late answer, have you found a solution yet?

To change the background color you have to use fenster->setBackground(r, g, b); That should work. You can also set the window title in main.cpp with fenster.init(app, “the title”);

But I have the same problem when moving the mouse. This is really strange because I used the same behaviour on another application and there it worked just fine. I tried some things but nothing helped. But I’m starting a new project with ofxFenster that uses mouse behaviours, maybe I’ll stumble upon something while developing it. I’ll post my results.

For now, if you don’t need mouse move and key support within you second window, you can manually comment out the following lines within ofxFenster.cpp ofxFenster::init(…):



hi underdoeg!

stumbled across your addon because of the need of a second window. worked pretty much out of the box. so thx a lot!
anyway, i needed the same video to be displayed on both screens and that didn’t work because each window has its own rendering context. after a bit of research i found out how to use wglShareLists to share contexts. just added a few lines to your init function and worked like a charm. thought i post it here as it might come in handy for others too.

void ofxFenster::init(ofxFensterListener* l, string name){
listener = l;
listener->fenster = this;
ofAddListener(ofEvents.update, this, &ofxFenster::update);
ofAddListener(ofEvents.draw, this, &ofxFenster::draw);

mainWinRef = glutGetWindow();
HGLRC rc1 = wglGetCurrentContext();
glutInitWindowSize(width, height);
winRef = glutCreateWindow(name.c_str());
HGLRC rc2 = wglGetCurrentContext();
wglShareLists(rc1, rc2);


this is windows only. but with a few directives and glx* calls it should work on other platforms too.

Wow Thanks! This is great.

I actually wanted to include this functionality. but I couldn’t get it working so far. I hope it’s ok for you if I include your code in the library for a future release. And maybe your right and I can implement it for linux and mac as well.


hi underdoeg !

did u made a new release of ofxFenster with the new addition from this thread?
i would love to give it a try to the whole shit … seems amazing to be able to have finally easy acces to second window !!


hi eloi

no, sorry not yet. i was quite occupied with some projects. but thanks for asking. this gives some motivation to add some functions. stay tuned, i’ll check out what i can do until the end of the week.


tunnnnning … :slight_smile:


sorry for the late response.

I took a look at it and it seems like the sharing part should be fairly easy for windows, as pilzinho pointed out. So attached you’ll find his version of ofxFenster.cpp. I currently don’t have a windows PC, so I am not sure if this works. maybe there is an include missing or so…

I tried to implement the context sharing for os x as well. But I just don’t get how to do it in combination with glut. It should be possible with AGL, as stated here https://developer.apple.com/library/mac-…-rence.html and here http://www.opengl.org/discussion-boards-…-ber=232064 .

Now my problem, as well as the guy in the second link has some problems using this with glut. But he seems to be onto something. But I could not yet try it. sorry.



When searching for multi-windows solution have I missed yours and in the end implemented my own. It could have saved me some trouble. :?

Anyway… for those who need to share OpenGL contexts on OSX, I have compiled GLUT so the first window created will share its context to all following windows.

Here it is (compiled for OSX 10.6):

If it doen’t work, try replacing /Sustem/Lybrary/Frameworks/GLUT.Framework with this one. sometimes even when I ask XCode to link it to link it, it uses the system framework.
But please backup it first.

yeah this is very useful. thanks!

Hi, I’m geting the following error when I try to use this addon:

GCC 4.2 is not compatible with the Mac OS X 10.4 SDK (file main.cpp)

Any suggestions?

Well, as it says. GCC 4.2 is not compatible with OS X 10.4. Since I’m on 10.6 and that’s where I created the XCode project, you’ll probably have to change this somewhere in your project. The addon should work with older compilers as well.

Take a look at this link http://stackoverflow.com/questions/3562-…-xcode-uses . Maybe this will help?

If not you could also try to create a new emptyExample and then copy over the files of ofxFensterExample