Skip to content

Commit

Permalink
Merge pull request #419 from Ymihere03/fix-window-resize
Browse files Browse the repository at this point in the history
Fix window resize
  • Loading branch information
assertivist authored Aug 13, 2024
2 parents ae3297d + c11e5f5 commit d1cdbd6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
17 changes: 7 additions & 10 deletions src/game/CAbstractPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/game/CAvaraApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/render/AbstractRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
21 changes: 17 additions & 4 deletions src/render/ModernOpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -567,8 +575,13 @@ std::unique_ptr<OpenGLShader> ModernOpenGLRenderer::LoadShader(const std::string
return std::make_unique<OpenGLShader>(*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]);
Expand Down
3 changes: 2 additions & 1 deletion src/render/ModernOpenGLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<OpenGLShader> 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);
};
1 change: 1 addition & 0 deletions src/render/NullRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
};

0 comments on commit d1cdbd6

Please sign in to comment.