Get screen size of second monitor


Is there a way to get screen size of the second monitor? The issue I’m having is this. I start the app on main monitor and drag it to the second monitor with different resolution. How can I get the screen resolution of the monitor where the app currently is.

ofGetScreenWidth() return me the primary monitor resolution, while ofGetWidth returns the window size.

Crappy answer but do you know the resolution of the primary monitor? You can put the app in full screen, get the whole window width and then subtract the primary monitor width. From there you can call setwindowsize and setwindowposition to get the app to fill the second screen only.

Try to check which windowing system your version of OF is using. If I’m not mistaken, 0.8.0 uses GLFW, I haven’t tested any of these but GLFW offers some functionality regarding several monitors.

I think it’s the default, apparently you can’t directly access those functions. But if you add:

#include "ofAppGLFWWindow.h"

To your ofApp.h you should be able to access all those functions. And then get all monitors information.

Check ofAppGLFWWindow::getCurrentMonitor to see an example of use for these functions.

Then use glfwGetMonitors and glfwGetMonitorPhysicalSize to get the screen size of any monitor.

chuckleplant: Hi, can you give some advice how to check what windowing library is used? Thanks!

Try placing ofGetCurrentRenderer wherever in code, and debug into the call, see where it gets you. You should be able to debug some virtual function from ofAppBaseWindow and see what class is implementing them.

There might be an easier way though!

GLFW should be the default window for all OF 0.8.0 -> OF 0.9.0
ofGetScreenWidth() / height() should return the screen width of the monitor your window is on.

This is the actual code which queries which monitor is active. So ofGetScreenWidth should be querying the correct screen dimensions.

ofPoint ofAppGLFWWindow::getScreenSize(){
	int count;
	GLFWmonitor** monitors = glfwGetMonitors(&count);
		int currentMonitor = getCurrentMonitor();
		const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[currentMonitor]);
			if( orientation == OF_ORIENTATION_DEFAULT || orientation == OF_ORIENTATION_180 ){
				return ofVec3f(desktopMode->width*pixelScreenCoordScale, desktopMode->height*pixelScreenCoordScale,0);
				return ofVec3f(desktopMode->height*pixelScreenCoordScale, desktopMode->width*pixelScreenCoordScale, 0);
			return ofPoint(0,0);
		return ofPoint(0,0);
1 Like

Thanks a lot guyz! It works, now i can get all the displays info.

The next step is to figure out a way to specify particular display for application start?
I’ve found that particular display is specifying when fullscreen window is creating

GLFWwindow* window = glfwCreateWindow(640, 480, “My Title”, glfwGetPrimaryMonitor(), NULL);

But i can’t find this exact place in the project…

Here is a function to detect the second monitor dimension and position in a main.cpp file. The function is used to set a second window in full screen on the second monitor:

bool setSecondWindowDimensions(ofGLFWWindowSettings& settings) {
    // Check screens size and location
    int count;
    GLFWmonitor** monitors = glfwGetMonitors(&count);
    cout << "Number of screens found: " << count << endl;
    if (count>1) {
        int xM; int yM;
        glfwGetMonitorPos(monitors[1], &xM, &yM); // We take the second monitor
        const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[1]);

        settings.width = desktopMode->width;
        settings.height = desktopMode->height;
        settings.setPosition(ofVec2f(xM, yM));
        return true;
    } else {
        settings.width = 800; // Default settings if there is only one screen
        settings.height = 600;
        settings.setPosition(ofVec2f(0, 0));
        return false;

int main() {
    ofGLFWWindowSettings settings;
    settings.width = 1200;
    settings.height = 600;
    settings.setPosition(ofVec2f(0, 0));
    settings.resizable = true;
    shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);

    settings.resizable = false;
    settings.decorated = false;
    settings.shareContextWith = mainWindow;
    shared_ptr<ofAppBaseWindow> secondWindow = ofCreateWindow(settings);

    shared_ptr<ofApp> mainApp(new ofApp);
    ofAddListener(secondWindow->events().draw, mainApp.get(), &ofApp::drawProjWindow);

    mainApp->projWindow = secondWindow;

    ofRunApp(mainWindow, mainApp);
1 Like

Any way with OF 1.01 ? GLFWmonitor don’t work with the last release (osx)

EDIT : solution is here !

Simply add : #include “GLFW/glfw3.h”