openframeworks / openframeworks/openFrameworks
ofAppGLFWWindow: Update to use new fullscreen code in GLFW 3.2
@ofTheo is already working on this.
Since Jul 12, 2016.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
As of 3.2 there is code available in GLFW to go fullscreen without destroying a window.
https://github.com/glfw/glfw/issues/43
https://github.com/glfw/glfw/commit/94ccaead5b8436756729759132b22893005071ff
It still requires a bit of work on our end (the way they do it is a bit weird, but it works) and we will still need to track non-fullscreen positions, but it could be a good basis for fixing some of the fullscreen issues we are seeing on Windows (#5155 not sure if this one is completely related) and Linux (#5129)
I have run into a fair number of small issues with fullscreen on Windows with 0.9 - 0.9.3, mainly with trying to go fullscreen on a second monitor from code ( ie not dragged to the monitor ). And the way we go fullscreen making it hard to debug when the app crashes ( it doesn't allow you to tab away from the window ).
It feels like a good time to update ofAppGLFWWindow to use new 3.2 features and try and and make it more stable overall.
I did a quick test with the new API on windows - using it directly in ofApp.
'f' puts a window fullscreen on the monitor it is on or if its top left corner is outside of any monitor, the closest one.
'w' makes it a window again - but it doesn't currently restore the position
I am going to try this on OS X.
Would be great if someone could try it on Linux.
If it seems to work well it could allow us to remove some of the platform specific windowing code from ofAppGLFWWindow. We will still need to do something custom probably for multi-window fullscreen, but I think letting GLFW do as much as possible would be ideal.
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
if (key == 'f') {
shared_ptr<ofAppGLFWWindow> ptr = dynamic_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
if (ptr) {
int count = 0;
GLFWmonitor** monitors = glfwGetMonitors(&count);
//check each existing monitor and see if the window top left is inside any of them
// if not match by closest position
int winPosX, winPosY = 0;
glfwGetWindowPos(ptr->getGLFWWindow(), &winPosX, &winPosY);
ofPoint winPos(winPosX, winPosY);
int closestIndex = -1;
float closestDist = 9999999.0;
for (int d = 0; d < count; d++) {
if (monitors[d] != NULL) {
int x, y = 0;
glfwGetMonitorPos(monitors[d], &x, &y);
const GLFWvidmode* mode = glfwGetVideoMode(monitors[d]);
ofRectangle rect(x, y, mode->width, mode->height);
//if we are inside a monitor - make this the one to go fullscreen on
if (rect.inside(x, y)) {
closestIndex = d;
break;
}
//otherwise if we are not inside a monitor look for closest monitor
float dist = (winPos - rect.getTopLeft()).length();
if (dist < closestDist) {
closestDist = dist;
closestIndex = d;
}
}
}
if (closestIndex >= 0) {
const GLFWvidmode* mode = glfwGetVideoMode(monitors[closestIndex]);
glfwSetWindowMonitor(ptr->getGLFWWindow(), monitors[closestIndex], winPosX, winPosY, mode->width, mode->height, mode->refreshRate);
}
}
}
if (key == 'w') {
shared_ptr<ofAppGLFWWindow> ptr = dynamic_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
glfwSetWindowMonitor(ptr->getGLFWWindow(), NULL, 40, 40, 1280, 720, 0);
ofSetVerticalSync(true);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.