From 0562dac6851ca1cc96761b8fab934a7621c35328 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 20 Aug 2019 12:45:23 +0200 Subject: [PATCH] - fix screenverts math and some line drawing bugs --- Source/Core/Rendering/Plotter.cs | 6 ++-- Source/Core/Rendering/Renderer2D.cs | 52 +++++++++++++++-------------- Source/Native/OpenGLContext.cpp | 4 +-- Source/Native/ShaderPlotter.h | 7 ++-- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Source/Core/Rendering/Plotter.cs b/Source/Core/Rendering/Plotter.cs index 1a5dd45c..a5712781 100755 --- a/Source/Core/Rendering/Plotter.cs +++ b/Source/Core/Rendering/Plotter.cs @@ -105,8 +105,8 @@ namespace CodeImp.DoomBuilder.Rendering } else { - start = -0.5f; - end = len + 0.5f; + start = 0.0f; + end = len; } float lineextent = 3.0f; // line width in shader + 1 @@ -165,7 +165,7 @@ namespace CodeImp.DoomBuilder.Rendering public void DrawLineSolid(int x1, int y1, int x2, int y2, PixelColor c, bool dotted = false) { - DrawLine(x1, y1, x2, y2, c.ToInt(), true); + DrawLine(x1, y1, x2, y2, c.ToInt(), dotted); } public void DrawLine3DFloor(Vector2D start, Vector2D end, PixelColor c, PixelColor c2) diff --git a/Source/Core/Rendering/Renderer2D.cs b/Source/Core/Rendering/Renderer2D.cs index 7f5ee58a..dbf2893b 100755 --- a/Source/Core/Rendering/Renderer2D.cs +++ b/Source/Core/Rendering/Renderer2D.cs @@ -365,7 +365,7 @@ namespace CodeImp.DoomBuilder.Rendering graphics.SetBufferData(thingsvertices, THING_BUFFER_SIZE * 12, VertexFormat.Flat); // Make screen vertices - FlatVertex[] verts = CreateScreenVerts(new Size(plotter.Width, plotter.Height)); + FlatVertex[] verts = CreateScreenVerts(new Size(windowsize.Width, windowsize.Height)); graphics.SetBufferData(screenverts, verts); // Force update of view @@ -380,27 +380,27 @@ namespace CodeImp.DoomBuilder.Rendering private static FlatVertex[] CreateScreenVerts(Size texturesize) { FlatVertex[] screenverts = new FlatVertex[4]; - screenverts[0].x = 0.5f; - screenverts[0].y = 0.5f; - screenverts[0].c = -1; - screenverts[0].u = 1f / texturesize.Width; - screenverts[0].v = 1f / texturesize.Height; - screenverts[1].x = texturesize.Width - 1.5f; - screenverts[1].y = 0.5f; - screenverts[1].c = -1; - screenverts[1].u = 1f - 1f / texturesize.Width; - screenverts[1].v = 1f / texturesize.Height; - screenverts[2].x = 0.5f; - screenverts[2].y = texturesize.Height - 1.5f; - screenverts[2].c = -1; - screenverts[2].u = 1f / texturesize.Width; - screenverts[2].v = 1f - 1f / texturesize.Height; - screenverts[3].x = texturesize.Width - 1.5f; - screenverts[3].y = texturesize.Height - 1.5f; - screenverts[3].c = -1; - screenverts[3].u = 1f - 1f / texturesize.Width; - screenverts[3].v = 1f - 1f / texturesize.Height; - return screenverts; + screenverts[0].x = 0.0f; + screenverts[0].y = 0.0f; + screenverts[0].c = -1; + screenverts[0].u = 0.0f; + screenverts[0].v = 0.0f; + screenverts[1].x = texturesize.Width; + screenverts[1].y = 0.0f; + screenverts[1].c = -1; + screenverts[1].u = 1.0f; + screenverts[1].v = 0.0f; + screenverts[2].x = 0.0f; + screenverts[2].y = texturesize.Height; + screenverts[2].c = -1; + screenverts[2].u = 0.0f; + screenverts[2].v = 1.0f; + screenverts[3].x = texturesize.Width; + screenverts[3].y = texturesize.Height; + screenverts[3].c = -1; + screenverts[3].u = 1.0f; + screenverts[3].v = 1.0f; + return screenverts; } #endregion @@ -447,9 +447,7 @@ namespace CodeImp.DoomBuilder.Rendering if(vertexsize < 0) vertexsize = 0; if(vertexsize > 4) vertexsize = 4; - Matrix scaling = Matrix.Scaling((1f / windowsize.Width) * 2f, (1f / windowsize.Height) * -2f, 1f); - Matrix translate = Matrix.Translation(-(float)windowsize.Width * 0.5f, -(float)windowsize.Height * 0.5f, 0f); - viewmatrix = translate * scaling; + viewmatrix = Matrix.Scaling(2.0f / windowsize.Width, -2.0f / windowsize.Height, 1.0f) * Matrix.Translation(-1.0f, 1.0f, 0.0f); Vector2D lt = DisplayToMap(new Vector2D(0.0f, 0.0f)); Vector2D rb = DisplayToMap(new Vector2D(windowsize.Width, windowsize.Height)); viewport = new RectangleF(lt.x, lt.y, rb.x - lt.x, rb.y - lt.y); @@ -1537,6 +1535,10 @@ namespace CodeImp.DoomBuilder.Rendering if(renderlayer != RenderLayers.None) return; //mxd renderlayer = RenderLayers.Surface; + // Recreate render targets if the window was resized + if (windowsize.Width != graphics.RenderTarget.ClientSize.Width || windowsize.Height != graphics.RenderTarget.ClientSize.Height) + CreateRendertargets(); + // Rendertargets available? if(surfacetex != null) { diff --git a/Source/Native/OpenGLContext.cpp b/Source/Native/OpenGLContext.cpp index 5f4bf0c0..95e85321 100644 --- a/Source/Native/OpenGLContext.cpp +++ b/Source/Native/OpenGLContext.cpp @@ -118,14 +118,14 @@ int OpenGLContext::GetWidth() const { RECT box = { 0 }; GetClientRect(window, &box); - return box.right; + return box.right - box.left; } int OpenGLContext::GetHeight() const { RECT box = { 0 }; GetClientRect(window, &box); - return box.bottom; + return box.bottom - box.top; } ///////////////////////////////////////////////////////////////////////////// diff --git a/Source/Native/ShaderPlotter.h b/Source/Native/ShaderPlotter.h index 669bc1d2..b75640e3 100644 --- a/Source/Native/ShaderPlotter.h +++ b/Source/Native/ShaderPlotter.h @@ -27,13 +27,12 @@ const char* plotter_ps = R"( void main() { // line stipple - int visible = int(UV.x) & 1; - if (visible == 1) + if (mod(UV.x, 2.0) > 1.0) discard; // line smoothing - float linewidth = 2.0; - float falloff = 1.5; //1.5..2.5 + float linewidth = 3.0; + float falloff = 1.8; //1.5..2.5 float centerdist = abs(UV.y); float a = pow(clamp((linewidth - centerdist) / linewidth, 0.0, 1.0), falloff);