Creating a fullscreen window directly on second monitor

I’m trying to open a window fullscreen on second monitor, main app there.
I’ve just noticed glfwGetMonitors doesn’t work before ofCreateWindow.
Any ideas of how to accomplish this without creating two windows?
Danke Schön Obrigracias.

#include "ofMain.h"
#include "ofApp.h"
#include "GLFW/glfw3.h"

//========================================================================
int main( ){
	ofGLFWWindowSettings settings;
	
// I don't want this one here
	auto guiWindow = ofCreateWindow(settings);

	int monitorCount;
	GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
	
	if (monitorCount > 1) {
	
		int a = 1;
		int xM; int yM;
		glfwGetMonitorPos(monitors[a], &xM, &yM);
		glm::vec2 pos = glm::vec2(xM, yM);

		const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[a]);
		glm::vec2 size = glm::vec2(desktopMode->width, desktopMode->height);
		
		settings.setSize (size.x, size.y);
		settings.setPosition(pos);
		settings.windowMode = OF_FULLSCREEN;
		
		guiWindow = ofCreateWindow(settings);
		auto mainApp = make_shared<ofApp>();

		ofRunApp(guiWindow, std::move(mainApp));
		ofRunMainLoop();
	} else {
		cout << monitorCount << endl;
	}
}

I have found that it is always easier to do that kind of things on ofApp::setup, because there you can query screen size, which display you are in, etc.

Although, did you try

ofGLFWWindowSettings settings;
settings.monitor = 1;	

	auto guiWindow = ofCreateWindow(settings);
1 Like

Thanks @roymacdonald I’ve just tried and while it can be used instead of setPosition it only works after the creation of the first window, so I suppose I still have to create at least one window before know the available monitors available.

I see. My best guess would be to copy the glfw calls in ofAppGLFWWindow::setup and go on disabling one by one and compiling untill I get the minimum amout of lines with which glfwGetMonitors works

Digging into old projects that I used glfwGetMonitors, I found that I first call glfwInit(). Can you try that?

Like in here:

I thought that I needed something like this. Thanks.
When I searched for glfwInit() in OF´s code I realized that there are 2 static functions that can be really handy

void ofAppGLFWWindow::listVideoModes(); 
void ofAppGLFWWindow::listMonitors();