From 05451849f8cec9ed91a213d5020cf6406ba94feb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 31 Dec 2013 12:50:20 +0300 Subject: Improve drawNet in safeopenglgraphics. --- src/render/safeopenglgraphics.cpp | 28 ++++++++++++++++++++++++---- src/render/safeopenglgraphics.h | 4 ++++ 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp index 717e7d5bf..c988e6825 100644 --- a/src/render/safeopenglgraphics.cpp +++ b/src/render/safeopenglgraphics.cpp @@ -566,17 +566,37 @@ void SafeOpenGLGraphics::drawPoint(int x, int y) glEnd(); } -void SafeOpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) +bool SafeOpenGLGraphics::drawNet(const int x1, const int y1, + const int x2, const int y2, + const int width, const int height) { setTexturingAndBlending(false); restoreColor(); glBegin(GL_LINES); - glVertex2f(static_cast(x1) + 0.5F, static_cast(y1) + 0.5F); - glVertex2f(static_cast(x2) + 0.5F, static_cast(y2) + 0.5F); + for (int y = y1; y < y2; y += height) + { + glVertex2f(static_cast(x1) + 0.5F, static_cast(y) + 0.5F); + glVertex2f(static_cast(x2) + 0.5F, static_cast(y) + 0.5F); + } + + for (int x = x1; x < x2; x += width) + { + glVertex2f(static_cast(x) + 0.5F, static_cast(y1) + 0.5F); + glVertex2f(static_cast(x) + 0.5F, static_cast(y2) + 0.5F); + } glEnd(); - glBegin(GL_POINTS); + return true; +} + +void SafeOpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) +{ + setTexturingAndBlending(false); + restoreColor(); + + glBegin(GL_LINES); + glVertex2f(static_cast(x1) + 0.5F, static_cast(y1) + 0.5F); glVertex2f(static_cast(x2) + 0.5F, static_cast(y2) + 0.5F); glEnd(); } diff --git a/src/render/safeopenglgraphics.h b/src/render/safeopenglgraphics.h index 36ce27ded..c4bfd46de 100644 --- a/src/render/safeopenglgraphics.h +++ b/src/render/safeopenglgraphics.h @@ -59,6 +59,10 @@ class SafeOpenGLGraphics final : public Graphics void drawImageRect(int x, int y, int w, int h, const ImageRect &imgRect); + bool drawNet(const int x1, const int y1, + const int x2, const int y2, + const int width, const int height) override final; + protected: void setTexturingAndBlending(const bool enable); -- cgit v1.2.3-70-g09d2