diff --git a/Core/CDrawUtil.cpp b/Core/CDrawUtil.cpp index c4619888..57b1bd73 100644 --- a/Core/CDrawUtil.cpp +++ b/Core/CDrawUtil.cpp @@ -97,6 +97,12 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB) DrawLine(PointA, PointB, CColor::skWhite); } +void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB) +{ + // Overload for 2D lines + DrawLine(CVector3f(PointA.x, PointA.y, 0.f), CVector3f(PointB.x, PointB.y, 0.f), CColor::skWhite); +} + void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const CColor& LineColor) { Init(); @@ -116,6 +122,12 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const mLineVertices.Unbind(); } +void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB, const CColor& LineColor) +{ + // Overload for 2D lines + DrawLine(CVector3f(PointA.x, PointA.y, 0.f), CVector3f(PointB.x, PointB.y, 0.f), LineColor); +} + void CDrawUtil::DrawCube() { Init(); @@ -129,6 +141,14 @@ void CDrawUtil::DrawCube(const CColor& Color) DrawCube(); } +void CDrawUtil::DrawCube(const CVector3f& Position, const CColor& Color) +{ + CGraphics::sMVPBlock.ModelMatrix = CTransform4f::TranslationMatrix(Position).ToMatrix4f(); + CGraphics::UpdateMVPBlock(); + UseColorShader(Color); + DrawCube(); +} + void CDrawUtil::DrawShadedCube(const CColor& Color) { Init(); diff --git a/Core/CDrawUtil.h b/Core/CDrawUtil.h index 6b8548e5..d9a8d7fd 100644 --- a/Core/CDrawUtil.h +++ b/Core/CDrawUtil.h @@ -54,9 +54,12 @@ public: static void DrawSquare(const CVector2f& TexUL, const CVector2f& TexUR, const CVector2f& TexBR, const CVector2f& TexBL); static void DrawSquare(const float *pTexCoords); static void DrawLine(const CVector3f& PointA, const CVector3f& PointB); + static void DrawLine(const CVector2f& PointA, const CVector2f& PointB); static void DrawLine(const CVector3f& PointA, const CVector3f& PointB, const CColor& LineColor); + static void DrawLine(const CVector2f& PointA, const CVector2f& PointB, const CColor& LineColor); static void DrawCube(); static void DrawCube(const CColor& Color); + static void DrawCube(const CVector3f& Position, const CColor& Color); static void DrawShadedCube(const CColor& Color); static void DrawWireCube(); static void DrawWireCube(const CAABox& AABox, const CColor& Color); diff --git a/Core/CRenderer.cpp b/Core/CRenderer.cpp index d39e4583..1584274a 100644 --- a/Core/CRenderer.cpp +++ b/Core/CRenderer.cpp @@ -126,6 +126,7 @@ void CRenderer::RenderBuckets(CCamera& Camera) { if (!mInitialized) Init(); mSceneFramebuffer.Bind(); + Camera.LoadMatrices(); // Set backface culling if (mOptions & eEnableBackfaceCull) glEnable(GL_CULL_FACE); @@ -250,21 +251,18 @@ void CRenderer::RenderBloom() glEnable(GL_DEPTH_TEST); } -void CRenderer::RenderSky(CModel *pSkyboxModel, CVector3f CameraPosition) +void CRenderer::RenderSky(CModel *pSkyboxModel, CCamera& Camera) { if (!mInitialized) Init(); - if (!pSkyboxModel) return; + glEnable(GL_CULL_FACE); + Camera.LoadRotationOnlyMatrices(); - CTransform4f ModelMtx; - ModelMtx.Translate(CameraPosition); - - CGraphics::sMVPBlock.ModelMatrix = ModelMtx.ToMatrix4f(); + CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity; CGraphics::sVertexBlock.COLOR0_Amb = CVector4f(1.f, 1.f, 1.f, 1.f); CGraphics::sPixelBlock.TevColor = CVector4f(1.f, 1.f, 1.f, 1.f); CGraphics::sNumLights = 0; - CGraphics::UpdateMVPBlock(); CGraphics::UpdateVertexBlock(); CGraphics::UpdatePixelBlock(); CGraphics::UpdateLightBlock(); diff --git a/Core/CRenderer.h b/Core/CRenderer.h index a90b7989..40a41470 100644 --- a/Core/CRenderer.h +++ b/Core/CRenderer.h @@ -67,7 +67,7 @@ public: // Render void RenderBuckets(CCamera& Camera); void RenderBloom(); - void RenderSky(CModel *pSkyboxModel, CVector3f CameraPosition); + void RenderSky(CModel *pSkyboxModel, CCamera& Camera); void AddOpaqueMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command); void AddTransparentMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command); void BeginFrame(); diff --git a/OpenGL/CShaderGenerator.cpp b/OpenGL/CShaderGenerator.cpp index 6953fd45..aa066ab0 100644 --- a/OpenGL/CShaderGenerator.cpp +++ b/OpenGL/CShaderGenerator.cpp @@ -218,8 +218,8 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& Mat) ShaderCode << "// Main\n" << "void main()\n" << "{\n" - << " mat4 MVP = ModelMtx * ViewMtx * ProjMtx;\n" - << " mat4 MV = ModelMtx * ViewMtx;\n"; + << " mat4 MV = ModelMtx * ViewMtx;\n" + << " mat4 MVP = MV * ProjMtx;\n"; if (VtxDesc & ePosition) ShaderCode << " gl_Position = vec4(RawPosition, 1) * MVP;\n"; if (VtxDesc & eNormal) ShaderCode << " Normal = normalize(RawNormal.xyz * inverse(transpose(mat3(MV))));\n"; diff --git a/UI/CEditorGLWidget.cpp b/UI/CEditorGLWidget.cpp index 1bbcad81..6aaf7ca4 100644 --- a/UI/CEditorGLWidget.cpp +++ b/UI/CEditorGLWidget.cpp @@ -67,7 +67,6 @@ void CEditorGLWidget::paintGL() // Camera movement is processed here in order to sync it with the paint event // This way movement happens exactly once per frame - no more, no less ProcessInput(DeltaTime); - mCamera.LoadMatrices(); // Pre-render signal allows for per-frame operations to be performed before the draw happens emit PreRender(); diff --git a/UI/CWorldEditor.cpp b/UI/CWorldEditor.cpp index 91915fcf..7fb2650a 100644 --- a/UI/CWorldEditor.cpp +++ b/UI/CWorldEditor.cpp @@ -387,9 +387,10 @@ void CWorldEditor::ViewportRender(CCamera& Camera) if (mDrawSky) { CModel *pSky = mpSceneManager->GetActiveSkybox(); - if (pSky) mpRenderer->RenderSky(pSky, Camera.Position()); + if (pSky) mpRenderer->RenderSky(pSky, Camera); } + Camera.LoadMatrices(); mpRenderer->RenderBuckets(Camera); mpRenderer->RenderBloom(); diff --git a/UI/CWorldEditorWindow.cpp b/UI/CWorldEditorWindow.cpp index 12a687aa..46e923e5 100644 --- a/UI/CWorldEditorWindow.cpp +++ b/UI/CWorldEditorWindow.cpp @@ -95,7 +95,7 @@ void CWorldEditorWindow::PaintViewport(double DeltaTime) if (mShouldDrawSky) { CModel *pSky = mpSceneManager->GetActiveSkybox(); - if (pSky) mpRenderer->RenderSky(pSky, mCamera.Position()); + if (pSky) mpRenderer->RenderSky(pSky, mCamera); } mpRenderer->RenderBuckets(mCamera);