فهرست منبع

~ listen for screen size changes and setup proper viewport so everything is rendered from the center of the screen
~ fixed a typo on one of the vertex positions for the CWallpaper::render function

Signed-off-by: Alexis Maiquez <almamu@almamu.com>

Alexis Maiquez 5 سال پیش
والد
کامیت
48da16f7e5
4فایلهای تغییر یافته به همراه18 افزوده شده و 3 حذف شده
  1. 7 0
      main.cpp
  2. 8 2
      src/WallpaperEngine/Render/CContext.cpp
  3. 2 0
      src/WallpaperEngine/Render/CContext.h
  4. 1 1
      src/WallpaperEngine/Render/CWallpaper.cpp

+ 7 - 0
main.cpp

@@ -202,6 +202,8 @@ int main (int argc, char* argv[])
 
     // get the real framebuffer size
     glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
+    // set the default viewport
+    context->setDefaultViewport ({0, 0, windowWidth, windowHeight});
 
     if (glewInit () != GLEW_OK)
     {
@@ -210,6 +212,7 @@ int main (int argc, char* argv[])
         return 3;
     }
 
+
     if (project->getType () == "scene")
     {
         WallpaperEngine::Core::CScene* scene = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> ();
@@ -264,6 +267,10 @@ int main (int argc, char* argv[])
 
     while (glfwWindowShouldClose (window) == 0)
     {
+        // get the real framebuffer size
+        glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
+        // set the default viewport
+        context->setDefaultViewport ({0, 0, windowWidth, windowHeight});
         // calculate the current time value
         g_Time = (float) glfwGetTime ();
         // get the start time of the frame

+ 8 - 2
src/WallpaperEngine/Render/CContext.cpp

@@ -13,7 +13,8 @@ CContext::CContext (std::vector <std::string> screens) :
     m_wallpaper (nullptr),
     m_screens (std::move (screens)),
     m_isRootWindow (m_screens.empty () == false),
-    m_window (0)
+    m_window (0),
+    m_defaultViewport ({0, 0, 1920, 1080})
 {
     this->initializeViewports ();
 }
@@ -99,10 +100,15 @@ void CContext::render ()
         }
     }
     else
-        this->m_wallpaper->render ({0, 0, 1920, 1080});
+        this->m_wallpaper->render (this->m_defaultViewport);
 }
 
 void CContext::setWallpaper (CWallpaper* wallpaper)
 {
     this->m_wallpaper = wallpaper;
+}
+
+void CContext::setDefaultViewport (glm::vec4 defaultViewport)
+{
+    this->m_defaultViewport = defaultViewport;
 }

+ 2 - 0
src/WallpaperEngine/Render/CContext.h

@@ -15,11 +15,13 @@ namespace WallpaperEngine::Render
         void initializeViewports ();
         void render ();
         void setWallpaper (CWallpaper* wallpaper);
+        void setDefaultViewport (glm::vec4 defaultViewport);
 
     private:
         Window m_window;
         std::vector <std::string> m_screens;
         std::vector <glm::vec4> m_viewports;
+        glm::vec4 m_defaultViewport;
         CWallpaper* m_wallpaper;
         bool m_isRootWindow;
     };

+ 1 - 1
src/WallpaperEngine/Render/CWallpaper.cpp

@@ -205,7 +205,7 @@ void CWallpaper::render (glm::vec4 viewport, bool newFrame)
 
     GLfloat position [] = {
         widthRatio * -1.0f, heightRatio * 1.0f, 0.0f,
-        widthRatio * 1.0, heightRatio * 1.0f, 0.0f,
+        widthRatio * 1.0f, heightRatio * 1.0f, 0.0f,
         widthRatio * -1.0f, heightRatio * -1.0f, 0.0f,
         widthRatio * -1.0f, heightRatio * -1.0f, 0.0f,
         widthRatio * 1.0f, heightRatio * 1.0f, 0.0f,