diff --git a/libs/openFrameworks/app/ofAppBaseWindow.h b/libs/openFrameworks/app/ofAppBaseWindow.h index 0a0b2d8ed87..448e64a9a83 100644 --- a/libs/openFrameworks/app/ofAppBaseWindow.h +++ b/libs/openFrameworks/app/ofAppBaseWindow.h @@ -48,6 +48,7 @@ class ofAppBaseWindow { virtual glm::ivec2 getWindowPosition() { return glm::ivec2(); } virtual glm::ivec2 getWindowSize() { return glm::ivec2(); } + virtual glm::ivec2 getFramebufferSize() { return glm::ivec2(); } virtual glm::ivec2 getScreenSize() { return glm::ivec2(); } virtual ofRectangle getWindowRect() { return ofRectangle(); } diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index 61e79c109e2..86d74007647 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -51,8 +51,7 @@ ofAppGLFWWindow::ofAppGLFWWindow() : coreEvents(new ofCoreEvents){ ofAppPtr = nullptr; - pixelScreenCoordScale = 1; - nFramesSinceWindowResized = 0; +// nFramesSinceWindowResized = 0; iconSet = false; windowP = nullptr; @@ -95,11 +94,6 @@ void ofAppGLFWWindow::close() { } } -//------------------------------------------------------------ -void ofAppGLFWWindow::setMultiDisplayFullscreen(bool bMultiFullscreen) { - settings.multiMonitorFullScreen = bMultiFullscreen; -} - //------------------------------------------------------------ void ofAppGLFWWindow::setup(const ofWindowSettings & _settings) { if (windowP) { @@ -129,6 +123,7 @@ void ofAppGLFWWindow::setup(const ofWindowSettings & _settings) { glfwWindowHint(GLFW_STEREO, settings.stereo); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_MAXIMIZED, settings.maximized); + // FIXME: Review this. #ifndef TARGET_OSX glfwWindowHint(GLFW_AUX_BUFFERS, settings.doubleBuffering ? 1 : 0); #else @@ -170,9 +165,6 @@ void ofAppGLFWWindow::setup(const ofWindowSettings & _settings) { sharedContext = (GLFWwindow *)settings.shareContextWith->getWindowContext(); } - - - GLFWmonitor *monitor = nullptr; // FIXME: maybe use as a global variable for the window? @@ -184,48 +176,29 @@ void ofAppGLFWWindow::setup(const ofWindowSettings & _settings) { ofLogError("ofAppGLFWWindow") << "requested monitor is: " << settings.monitor << " monitor count is: " << allMonitors.rects.size(); } - if (settings.windowMode == OF_GAME_MODE) { windowRect = allMonitors.rects[monitorIndex]; monitor = allMonitors.monitors[monitorIndex]; } -// cout << "GLFW Will create windowRect " << windowRect << endl; // MARK: - WINDOW glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); windowP = glfwCreateWindow(settings.getWidth(), settings.getHeight(), settings.title.c_str(), monitor, sharedContext); windowRect = getWindowRect(); -// windowRect = + if (settings.windowMode == OF_WINDOW || settings.windowMode == OF_FULLSCREEN) { -// cout << "rects size " << allMonitors.rects.size() << endl; -// cout << "window mode monitorindex = " << monitorIndex << endl; -// cout << "settings.monitor = " << settings.monitor << endl; - -// cout << settings.windowName << " windowRect before " << windowRect << endl; if (monitorIndex > 0) { windowRect.x += allMonitors.rects[monitorIndex].x; windowRect.y += allMonitors.rects[monitorIndex].y; setWindowRect(windowRect); } - // OK, this is just so isPositionSet is ok in next few lines. - // FIXME: there is a problem here, position will be zeroed if setposition is called before window creation. -// { -// settings.setPosition({windowRect.x, windowRect.y}); -// } -// cout << settings.windowName << " windowRect after " << windowRect << endl; } - - -// cout << "GLFW windowRect " << windowRect << " : " << settings.windowName << endl; - if (settings.isPositionSet()) { -// cout << "GLFW isPosition set true : " << settings.windowName << endl; setWindowRect(windowRect); } else { -// cout << "GLFW isPosition set false : " << settings.windowName << endl; setWindowShape(windowRect.width, windowRect.height); } @@ -233,7 +206,6 @@ void ofAppGLFWWindow::setup(const ofWindowSettings & _settings) { ofLogError("ofAppGLFWWindow") << "couldn't create GLFW window"; return; } -// cout << "GLFW window created OK" << endl; // MARK: - @@ -253,10 +225,13 @@ void ofAppGLFWWindow::setup(const ofWindowSettings & _settings) { setWindowIcon(iconPixels); } #endif + + //FIXME: check if it works with hint GLFW_AUTO_ICONIFY if (settings.iconified) { iconify(true); } + //FIXME: check if it works with hint GLFW_MAXIMIZED if (settings.maximized) { glfwMaximizeWindow(windowP); } @@ -401,50 +376,49 @@ void ofAppGLFWWindow::pollEvents() { void ofAppGLFWWindow::draw() { currentRenderer->startRender(); if (bEnableSetupScreen) { -// cout << "ow currentRenderer->setupScreen()" << endl; currentRenderer->setupScreen(); } events().notifyDraw(); -#ifdef TARGET_WIN32 - if (currentRenderer->getBackgroundAuto() == false) { - // on a PC resizing a window with this method of accumulation (essentially single buffering) - // is BAD, so we clear on resize events. - if (nFramesSinceWindowResized < 3) { - currentRenderer->clear(); - } else { - if ((events().getFrameNum() < 3 || nFramesSinceWindowResized < 3) && settings.doubleBuffering) { - glfwSwapBuffers(windowP); - } else { - glFlush(); - } - } - } else { - if (settings.doubleBuffering) { - glfwSwapBuffers(windowP); - } else { - glFlush(); - } - } -#else - if (currentRenderer->getBackgroundAuto() == false) { - // in accum mode resizing a window is BAD, so we clear on resize events. - if (nFramesSinceWindowResized < 3) { - currentRenderer->clear(); - } - } +//#ifdef TARGET_WIN32 +// if (currentRenderer->getBackgroundAuto() == false) { +// // on a PC resizing a window with this method of accumulation (essentially single buffering) +// // is BAD, so we clear on resize events. +// if (nFramesSinceWindowResized < 3) { +// currentRenderer->clear(); +// } +// +// else { +// if ((events().getFrameNum() < 3 || nFramesSinceWindowResized < 3) && settings.doubleBuffering) { +// glfwSwapBuffers(windowP); +// } else { +// glFlush(); +// } +// } +// } else { +// if (settings.doubleBuffering) { +// glfwSwapBuffers(windowP); +// } else { +// glFlush(); +// } +// } +//#else +// +// +//#endif + if (settings.doubleBuffering) { glfwSwapBuffers(windowP); -// std::cout << "swap buffers " << ofGetFrameNum() << std::endl; + // std::cout << "swap buffers " << ofGetFrameNum() << std::endl; } else { glFlush(); } -#endif - + + currentRenderer->finishRender(); - nFramesSinceWindowResized++; +// nFramesSinceWindowResized++; } //-------------------------------------------- @@ -480,10 +454,10 @@ void ofAppGLFWWindow::setWindowTitle(const std::string & title) { //------------------------------------------------------------ int ofAppGLFWWindow::getPixelScreenCoordScale() { - - // TODO: - // discover which monitor this window - return pixelScreenCoordScale; + // FIXME: cache? + glm::vec2 contentScale; + glfwGetWindowContentScale(windowP, &contentScale.x, &contentScale.y); + return contentScale.x; } //------------------------------------------------------------ @@ -502,6 +476,14 @@ glm::ivec2 ofAppGLFWWindow::getWindowSize() { return size; } +//------------------------------------------------------------ +glm::ivec2 ofAppGLFWWindow::getFramebufferSize() { + // FIXME: cache size and handle in framebuffer_size_cb + glm::ivec2 size; + glfwGetFramebufferSize(windowP, &size.x, &size.y); + return size; +} + //------------------------------------------------------------ glm::ivec2 ofAppGLFWWindow::getWindowPosition() { glm::ivec2 pos; @@ -511,7 +493,7 @@ glm::ivec2 ofAppGLFWWindow::getWindowPosition() { //------------------------------------------------------------ glm::ivec2 ofAppGLFWWindow::getScreenSize() { - // FIXME: if screen = monitor and screensize is actual monitor from the window it is correct. + // it will return the monitor/screen size where the windows sit. windowRect = getWindowRect(); return allMonitors.getRectMonitorForScreenRect(windowRect).getSize(); } @@ -676,6 +658,7 @@ void ofAppGLFWWindow::setFullscreen(bool fullscreen) { Display * display = glfwGetX11Display(); if (targetWindowMode == OF_FULLSCREEN) { + // FIXME: Remove legacy code here int monitorCount; GLFWmonitor ** monitors = glfwGetMonitors(&monitorCount); @@ -1053,8 +1036,8 @@ void ofAppGLFWWindow::motion_cb(GLFWwindow * windowP_, double x, double y) { } ofMouseEventArgs args(action, - x * instance->pixelScreenCoordScale, - y * instance->pixelScreenCoordScale, + x, + y, instance->buttonInUse, instance->events().getModifiers()); instance->events().notifyMouseEvent(args); @@ -1307,7 +1290,7 @@ void ofAppGLFWWindow::refresh_cb(GLFWwindow * windowP_) { //------------------------------------------------------------ void ofAppGLFWWindow::monitor_cb(GLFWmonitor * monitor, int event) { - cout << "monitor_cb!" << endl; +// cout << "monitor_cb!" << endl; allMonitors.update(); } @@ -1324,7 +1307,7 @@ void ofAppGLFWWindow::position_cb(GLFWwindow* windowP_, int x, int y){ void ofAppGLFWWindow::resize_cb(GLFWwindow * windowP_, int w, int h) { ofAppGLFWWindow * instance = setCurrent(windowP_); instance->events().notifyWindowResized(w, h); - instance->nFramesSinceWindowResized = 0; +// instance->nFramesSinceWindowResized = 0; #if defined(TARGET_OSX) if (!instance->bWindowNeedsShowing) { @@ -1343,6 +1326,8 @@ void ofAppGLFWWindow::resize_cb(GLFWwindow * windowP_, int w, int h) { void ofAppGLFWWindow::framebuffer_size_cb(GLFWwindow * windowP_, int w, int h) { // cout << "framebuffer_size_cb " << w << " : " << h << endl; ofAppGLFWWindow * instance = setCurrent(windowP_); + + instance->currentRenderer->clear(); instance->events().notifyFramebufferResized(w, h); } @@ -1513,3 +1498,7 @@ void ofAppGLFWWindow::setDepthBits(int depth) { void ofAppGLFWWindow::setStencilBits(int stencil) { settings.stencilBits = stencil; } + +void ofAppGLFWWindow::setMultiDisplayFullscreen(bool bMultiFullscreen) { + settings.multiMonitorFullScreen = bMultiFullscreen; +} diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.h b/libs/openFrameworks/app/ofAppGLFWWindow.h index 8adb21d25a6..df547bfe0b7 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.h +++ b/libs/openFrameworks/app/ofAppGLFWWindow.h @@ -57,6 +57,7 @@ class ofAppGLFWWindow : public ofAppBaseWindow { glm::ivec2 getScreenSize(); glm::ivec2 getWindowSize(); + glm::ivec2 getFramebufferSize(); glm::ivec2 getWindowPosition(); ofRectangle getWindowRect(); @@ -91,8 +92,6 @@ class ofAppGLFWWindow : public ofAppBaseWindow { bool isWindowResizeable(); void iconify(bool bIconify); - - #if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY) typedef struct _XIM * XIM; typedef struct _XIC * XIC; @@ -145,8 +144,6 @@ class ofAppGLFWWindow : public ofAppBaseWindow { void close(); #if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY) - - XIM xim; XIC xic; #endif @@ -157,9 +154,6 @@ class ofAppGLFWWindow : public ofAppBaseWindow { ofWindowMode targetWindowMode; bool bEnableSetupScreen; - - // FIXME remove - float pixelScreenCoordScale; /// Scale factor from virtual operating-system defined client area extents (as seen in currentW, currentH) to physical framebuffer pixel coordinates (as seen in windowW, windowH). ofRectangle windowRect { 20, 20, 800, 600 }; ofRectangle windowRectFS { 0, 0, 1920, 1080 }; @@ -168,18 +162,13 @@ class ofAppGLFWWindow : public ofAppBaseWindow { int buttonInUse; bool buttonPressed; - int nFramesSinceWindowResized; +// int nFramesSinceWindowResized; bool bWindowNeedsShowing; GLFWwindow * windowP; ofBaseApp * ofAppPtr; bool iconSet; - -//#ifdef TARGET_WIN32 -// LONG lExStyle, lStyle; -//#endif // TARGET_WIN32 - // window settings, this functions can only be called from main before calling ofSetupOpenGL @@ -228,7 +217,6 @@ static struct ofMonitors { } ofRectangle getRectForAllMonitors() { -// cout << "getRectForAllMonitors " << allMonitorsRect << endl; return allMonitorsRect; } @@ -264,17 +252,7 @@ static struct ofMonitors { } } } -// cout << "getRectFromMonitors " << str << " :: " << r << endl; - return r; - } - - ofRectangle getRectFromMonitorsX() { - ofRectangle r; - ofRectangle r2 { 30, 30, 30, 30 }; - r = r.getUnion(r2); return r; } - } allMonitors; -//#endif diff --git a/libs/openFrameworks/app/ofMainLoop.cpp b/libs/openFrameworks/app/ofMainLoop.cpp index 6320088a236..fa5206e78ef 100644 --- a/libs/openFrameworks/app/ofMainLoop.cpp +++ b/libs/openFrameworks/app/ofMainLoop.cpp @@ -27,12 +27,7 @@ #include "ofAppGLFWWindow.h" #endif -ofMainLoop::ofMainLoop() -:bShouldClose(false) -,status(0) -,allowMultiWindow(true) -,escapeQuits(true){ - +ofMainLoop::ofMainLoop() : bShouldClose(false), status(0), allowMultiWindow(true), escapeQuits(true) { } ofMainLoop::~ofMainLoop() { diff --git a/libs/openFrameworks/types/ofRectangle.cpp b/libs/openFrameworks/types/ofRectangle.cpp index 2ec09264b51..a6f9a53e65d 100644 --- a/libs/openFrameworks/types/ofRectangle.cpp +++ b/libs/openFrameworks/types/ofRectangle.cpp @@ -18,6 +18,11 @@ ofRectangle::ofRectangle(float px, float py, float w, float h) : x(position.x), set(px,py,w,h); } +//---------------------------------------------------------- +ofRectangle::ofRectangle(int px, int py, int w, int h) : x(position.x), y(position.y) { + set(px,py,w,h); +} + //---------------------------------------------------------- ofRectangle::ofRectangle(const glm::vec3& p, float w, float h) : x(position.x), y(position.y) { set(p,w,h); diff --git a/libs/openFrameworks/types/ofRectangle.h b/libs/openFrameworks/types/ofRectangle.h index ad8a1587ccd..7b7a8aca1b5 100644 --- a/libs/openFrameworks/types/ofRectangle.h +++ b/libs/openFrameworks/types/ofRectangle.h @@ -105,6 +105,7 @@ class ofRectangle { /// \param w The width of the rectangle. /// \param h The height of the rectangle. ofRectangle(float px, float py, float w, float h); + ofRectangle(int px, int py, int w, int h); /// \brief Construct a rectangle from a point and dimensions. /// diff --git a/libs/openFrameworks/utils/ofMatrixStack.cpp b/libs/openFrameworks/utils/ofMatrixStack.cpp index 230d9b0b303..f84054a018a 100644 --- a/libs/openFrameworks/utils/ofMatrixStack.cpp +++ b/libs/openFrameworks/utils/ofMatrixStack.cpp @@ -122,7 +122,7 @@ int ofMatrixStack::getRenderSurfaceWidth() const{ if(currentRenderSurface){ return currentRenderSurface->getWidth(); }else if(currentWindow){ - return currentWindow->getWindowSize().x; + return currentWindow->getFramebufferSize().x; }else{ return 0; } @@ -132,7 +132,7 @@ int ofMatrixStack::getRenderSurfaceHeight() const{ if(currentRenderSurface){ return currentRenderSurface->getHeight(); }else if(currentWindow){ - return currentWindow->getWindowSize().y; + return currentWindow->getFramebufferSize().y; }else{ return 0; } @@ -143,7 +143,9 @@ glm::ivec2 ofMatrixStack::getRenderSurfaceSize() const { return currentRenderSurface->getSize(); } else if (currentWindow) { // FIXME: FramebufferSize - return currentWindow->getWindowSize(); + // return currentWindow->getWindowSize(); + return currentWindow->getFramebufferSize(); + } else { return {}; } @@ -203,13 +205,13 @@ ofRectangle ofMatrixStack::getNativeViewport() const{ return currentViewport; } -ofRectangle ofMatrixStack::getFullSurfaceViewport() const{ - if(currentRenderSurface){ - return ofRectangle(0,0,currentRenderSurface->getWidth(),currentRenderSurface->getHeight()); - }else if(currentWindow){ - return ofRectangle(0,0,currentWindow->getWidth(),currentWindow->getHeight()); - }else{ - return ofRectangle(); +ofRectangle ofMatrixStack::getFullSurfaceViewport() const { + if (currentRenderSurface) { + return { 0.0f, 0.0f, currentRenderSurface->getWidth(),currentRenderSurface->getHeight() }; + } else if (currentWindow) { + return { 0, 0, currentWindow->getWidth(), currentWindow->getHeight() }; + } else { + return {}; //ofRectangle(); } }