~ 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>
This commit is contained in:
Alexis Maiquez 2021-09-08 19:42:27 +02:00
parent 213af7b99a
commit 48da16f7e5
4 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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,