Added UI Scaling support
This commit is contained in:
@ -57,10 +57,17 @@ int32_t DawnHost::init(DawnGame *game) {
|
||||
|
||||
// Override the defaults
|
||||
int32_t fbWidth, fbHeight;
|
||||
int32_t windowWidth, windowHeight;
|
||||
glfwGetFramebufferSize(this->data->window, &fbWidth, &fbHeight);
|
||||
glfwGetWindowSize(this->data->window, &windowWidth, &windowHeight);
|
||||
|
||||
assertTrue(fbWidth > 0, "Detected framebuffer width is too small?");
|
||||
assertTrue(fbWidth > 0, "Detected framebuffer height is too small?");
|
||||
assertTrue(windowWidth > 0, "Detected window width is too small?");
|
||||
assertTrue(windowHeight > 0, "Detected window height is too small?");
|
||||
game->renderManager.backBuffer.setSize(fbWidth, fbHeight);
|
||||
game->renderManager.backBuffer.scale = ((float_t)fbWidth) / ((float_t)windowWidth);
|
||||
assertTrue(game->renderManager.backBuffer.scale > 0, "Back buffer scale is invalid");
|
||||
assertNoGLError();
|
||||
|
||||
// Default keybinds
|
||||
@ -166,9 +173,18 @@ void glfwOnError(int error, const char* description) {
|
||||
|
||||
void glfwOnResize(GLFWwindow *window, int32_t w, int32_t h) {
|
||||
if(DAWN_HOST == nullptr) return;
|
||||
assertTrue(window == DAWN_HOST->data->window, "glfwOnResize: Window mismatch");
|
||||
|
||||
auto backBuffer = ((BackBufferRenderTarget*)&DAWN_HOST->game->renderManager.backBuffer);
|
||||
assertNotNull(backBuffer, "glfwOnResize: Back buffer is not valid");
|
||||
|
||||
int32_t windowWidth, windowHeight;
|
||||
glfwGetWindowSize(window, &windowWidth, &windowHeight);
|
||||
|
||||
// TODO: I may throttle this, it calls for every frame the window's resized.
|
||||
DAWN_HOST->game->renderManager.backBuffer.setSize((float_t)w, (float_t)h);
|
||||
backBuffer->setSize((float_t)w, (float_t)h);
|
||||
backBuffer->scale = ((float_t)w) / ((float_t)windowWidth);
|
||||
assertTrue(backBuffer->scale > 0, "glfwOnResize: Back buffer scale is invalid");
|
||||
}
|
||||
|
||||
void glfwOnKey(
|
||||
|
Reference in New Issue
Block a user