Fullscreen

Usually, to sketch a new idea, I start working with processing. It is more convenient to simply open the processing app and write code than create a whole new project with openFrameworks. Or so it seems. Somewhere down the road comes this little thing, that's simply not to archive with processing, but is so essential for the idea. Thats when I finally fire up the good old project generator and port everything I just did the last couple of hours to openFrameworks.

So it happened, that I needed to start a sketch on my second monitor in fullscreen. Processing: totally impossible. Arguably, this is not the standard task in openFrameworks either, but with a bit of research, it's perfectly doable.

main.cpp

int main( ){    
    CGDisplayCount displayCount;
    CGDirectDisplayID displays[32];

    // Grab the active displays
    CGGetActiveDisplayList(32, displays, &displayCount);
    int numDisplays = displayCount;

    // If two displays present, use the 2nd one. If only one, use the first
    int whichDisplay = numDisplays-1;

    int displayHeight = CGDisplayPixelsHigh (displays[whichDisplay]);
    int displayWidth = CGDisplayPixelsWide (displays[whichDisplay]);

    CGRect displayBounds= CGDisplayBounds (displays[whichDisplay]);

    // Setup the GL context
    ofSetupOpenGL(displayWidth, displayHeight, OF_FULLSCREEN);

    // OF_FULLSCREEN makes the window as big as the primary display, but we want it to be as big as whichever we're using
    ofSetWindowShape(displayWidth, displayHeight);

    // Move onto our display
    ofSetWindowPosition(displayBounds.origin.x, displayBounds.origin.y);

    // Print display info (if in debug scheme, see http://madcity.at/2013/ofLog-debug-release/)
    #ifdef IS_DEBUG
    cout << numDisplays << " display(s) detected." << endl
         << "Using display " << whichDisplay << " (" << displayWidth << "x" << displayHeight << ")." << endl;
    #endif

    ofRunApp(new ofApp());
}

Source: Comment by gregorywitt on "Dual Monitor Full-screen"

Date: 2015-05-14 | Tags: openFrameworks