diff --git a/src/game/CAbstractPlayer.cpp b/src/game/CAbstractPlayer.cpp index b433a0f7..831a53c5 100644 --- a/src/game/CAbstractPlayer.cpp +++ b/src/game/CAbstractPlayer.cpp @@ -562,7 +562,7 @@ void CAbstractPlayer::LoadDashboardParts() { dashboardSpinSpeed = ToFixed(100); dashboardSpinHeading = 0; - int layout = itsGame->itsApp->Get(kHUDPreset); + layout = itsGame->itsApp->Get(kHUDPreset); //float alpha = itsGame->itsApp->Get(kHUDAlpha); //Fixed hudAlpha = FIX1 * alpha; @@ -718,21 +718,22 @@ void CAbstractPlayer::RenderDashboard() { // Lastly set relativeImpulse based on the impact location of the hit to bump the HUD Fixed hitAngle = FOneArcTan2(dSpeed[2], dSpeed[0]); Fixed angleDiff = hitAngle - viewYaw; + float magnitude = ToFloat(VectorLength(3, dSpeed)); if (angleDiff > 0) { // Hit from the right side - relativeImpulse[0] = FIX(1.0); + relativeImpulse[0] = FIX(1.0*magnitude); } else if (angleDiff < 0) { // Hit from the left side - relativeImpulse[0] = FIX(-1.0); + relativeImpulse[0] = FIX(-1.0*magnitude); } if (dSpeed[1] > FIX(.5)) { // Hit from the top - relativeImpulse[1] = FIX(1.0); + relativeImpulse[1] = FIX(1.0*magnitude); } else if (dSpeed[1] < FIX(-.5)) { // Hit from the bottom - relativeImpulse[1] = FIX(-1.0); + relativeImpulse[1] = FIX(-1.0*magnitude); } pidReset(&pMotionX); @@ -924,11 +925,7 @@ void CAbstractPlayer::DashboardPosition(CScaledBSP *part, bool autoRot, float x, // X/Y Coordinates on the screen are roughly described as a percentage of the screen away from the bottom and the left // (-1.0, -1.0) is the bottom left of the screen // (1.0, 1.0) is the top right of the screen - - - // TODO: Adjust these until it looks good, then go multiply - // all the DashboardPosition parameters by these numbers, and - // then delete these + float scale_x = 11.12; float scale_y = 8.23; Fixed hud_dist = (FIX3(6000) * 25)/8; diff --git a/src/game/CAvaraApp.cpp b/src/game/CAvaraApp.cpp index 47aff359..d2965776 100755 --- a/src/game/CAvaraApp.cpp +++ b/src/game/CAvaraApp.cpp @@ -200,7 +200,9 @@ void CAvaraAppImpl::RenderContents() { } void CAvaraAppImpl::WindowResized(int width, int height) { - gRenderer->UpdateViewRect(width, height, mPixelRatio); + // Only update if the resolution is actually changing + if (gRenderer->viewParams->viewPixelDimensions.h != width || gRenderer->viewParams->viewPixelDimensions.v != height) + gRenderer->UpdateViewRect(width, height, mPixelRatio); //performLayout(); } diff --git a/src/render/AbstractRenderer.h b/src/render/AbstractRenderer.h index 563e35a5..97d9ced1 100644 --- a/src/render/AbstractRenderer.h +++ b/src/render/AbstractRenderer.h @@ -103,7 +103,7 @@ class AbstractRenderer { * @param height The height in pixels. * @param pixelRatio The pixel ratio. */ - void UpdateViewRect(int width, int height, float pixelRatio); + virtual void UpdateViewRect(int width, int height, float pixelRatio) = 0; protected: float fov = 50.0f; }; diff --git a/src/render/ModernOpenGLRenderer.cpp b/src/render/ModernOpenGLRenderer.cpp index 0b11a7f7..488eacb1 100644 --- a/src/render/ModernOpenGLRenderer.cpp +++ b/src/render/ModernOpenGLRenderer.cpp @@ -177,9 +177,6 @@ ModernOpenGLRenderer::ModernOpenGLRenderer(SDL_Window *window) : AbstractRendere glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); - MakeFramebuffer(0, w, h); - MakeFramebuffer(1, w, h); - // Configure alpha blending. glEnable(GL_BLEND); glBlendFuncSeparate(GL_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE); @@ -275,6 +272,17 @@ void ModernOpenGLRenderer::ApplyProjection() glCheckErrors(); } +void ModernOpenGLRenderer::UpdateViewRect(int width, int height, float pixelRatio) +{ + AbstractRenderer::UpdateViewRect(width, height, pixelRatio); + + GLsizei w, h; + SDL_GL_GetDrawableSize(window, &w, &h); + + AdjustFramebuffer(0, w, h); + AdjustFramebuffer(1, w, h); +} + void ModernOpenGLRenderer::LevelReset() { dynamicWorld->DisposeParts(); @@ -567,8 +575,13 @@ std::unique_ptr ModernOpenGLRenderer::LoadShader(const std::string return std::make_unique(*vertPath, *fragPath); } -void ModernOpenGLRenderer::MakeFramebuffer(short index, GLsizei width, GLsizei height) +void ModernOpenGLRenderer::AdjustFramebuffer(short index, GLsizei width, GLsizei height) { + // Remove previous bound objects + glDeleteTextures(1, &texture[index]); + glDeleteFramebuffers(1, &fbo[index]); + glDeleteRenderbuffers(1, &rbo[index]); + // Create a framebuffer, texture, and renderbuffer for the HUD. glGenFramebuffers(1, &fbo[index]); glBindFramebuffer(GL_FRAMEBUFFER, fbo[index]); diff --git a/src/render/ModernOpenGLRenderer.h b/src/render/ModernOpenGLRenderer.h index 5bc65a6a..42470304 100644 --- a/src/render/ModernOpenGLRenderer.h +++ b/src/render/ModernOpenGLRenderer.h @@ -26,6 +26,7 @@ class ModernOpenGLRenderer final: public AbstractRenderer { virtual void RemoveHUDPart(CBSPPart *part) override; virtual void RemovePart(CBSPPart *part) override; virtual void RenderFrame() override; + virtual void UpdateViewRect(int width, int height, float pixelRatio) override; private: SDL_Window *window; @@ -54,6 +55,6 @@ class ModernOpenGLRenderer final: public AbstractRenderer { void Draw(OpenGLShader &shader, const CBSPPart &part, float defaultAmbient, bool useAlphaBuffer = false); void IgnoreDirectionalLights(OpenGLShader &shader, bool yn); std::unique_ptr LoadShader(const std::string &vertFile, const std::string &fragFile); - void MakeFramebuffer(short index, GLsizei width, GLsizei height); + void AdjustFramebuffer(short index, GLsizei width, GLsizei height); void SetTransforms(const CBSPPart &part); }; diff --git a/src/render/NullRenderer.h b/src/render/NullRenderer.h index 4d5cb23f..21f5bea5 100644 --- a/src/render/NullRenderer.h +++ b/src/render/NullRenderer.h @@ -32,4 +32,5 @@ class NullRenderer final: public AbstractRenderer { virtual void RemoveHUDPart(CBSPPart *part) override {}; virtual void RemovePart(CBSPPart *part) override {}; virtual void RenderFrame() override {}; + virtual void UpdateViewRect(int width, int height, float pixelRatio) override {}; };