Second windowed window on second screen

Hi y’all,

I was wondering how to get a windowed window on my second screen. I cannot fill-in the second monitor as parameter for glfwCreateWindow because this results in a full-screen window.

How I solved it now (after looking through the internet) is just placing the window on the second screen (by using glfwSetWindowPos with coordinates bigger than the first screen). Is this the appropriate way to do this, or is there another, better way I haven’t found on google?

Furthermore, if I use 2 (equal) GPUs, one per screen, does this method ensure that one GPU draws one window and the other GPU draws the other window?

The reason I’m asking, is because when I implemented all of this my program is less stable than my program that only uses 1 screen, 1 GPU and creates only 1 window. With less stable I mean more deviations from the refresh rate and some flickering.

I implemented the 2 windows as follows: the main thread creates 2 windows and sets up GLFW. Then I create a thread. Then both the main and the thread go in the usual drawing loop (as long as window is open, keep rendering, drawing and swap buffering).This way I’m getting the refresh rate as FPS (whereas with only 1 thread I got refresh rate/2 as FPS), but as I said before, it’s less stable and deviates more often.

I hope somebody is kind enough to answer my questions. I really did Google quite a bit and went through many StackOverflow posts, but I couldn’t find satisfying answers. Moreover, I hope my question is clear and the given information is sufficient. Thank you all in advance:)!

It’s definitely the right direction, but they second monitor may be located elsewhere; it doesn’t have to be to the right of the first one (guessing that’s what you meant by “bigger coordinates”). Use glfwGetMonitorPos and glfwGetVideoMode to determine the monitor viewport and then place your window inside it with glfwSetWindowPos.

Are the threads rendering to separate windows or are they sharing windows?

For now I am more concerned with having two windows working on two displays in a stable way, so I just did it in this easier way (yeah for now I am assuming the second window is to the right of my main/primary display). I definitely agree that the second monitor may be located elsewhere, so when I have it working stably I will look into glfwGetMonitorPos and the rest. Thanks for the suggestion :slight_smile:
Edit: While waiting for another reply, I actually went and implemented your suggestion (though I didn’t need `glfwGetVideoMode), and it’s much better than before. Thanks :slight_smile:

Each thread is rendering (and swapping buffers) to 1 window. However, at window creation the second window shares resources with the first window (glfwCreateWindow's last parameter is NULL for window 1 and window 1 for window 2). But in the while(!shouldNotClose) loop each thread renders to one window only. I hope this makes sense for you?

Thanks for your response already, and looking forward to the next :slight_smile:

Edit: after testing I found that when both displays are connected to the same GPU I achieve a stable 100 Hz on my second display. On my primary display however, the same flickering happens (a lot of times only 98 Hz is achieved). I’m not sure if this is because it’s the primary window, if something goes wrong with GLFW or I made a mistake in implementing the 2 windows. Any further help is greatly appreciated cause I ran out of ideas…