From 0335a52479b6bd654482ca9d559433aa95b0e00a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 11 Mar 2021 23:48:05 +0100 Subject: [PATCH] Fix pixel-perfect draw2DLine on OpenGL --- include/IVideoDriver.h | 4 ++-- source/Irrlicht/COpenGLDriver.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index 4b0c277..9192b48 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -923,8 +923,8 @@ namespace video //! Draws a 2d line. /** In theory both start and end will be included in coloring. - BUG: Currently hardware drivers (d3d/opengl) ignore the last pixel - (they use the so called "diamond exit rule" for drawing lines). + BUG: Currently d3d ignores the last pixel + (it uses the so called "diamond exit rule" for drawing lines). \param start Screen coordinates of the start of the line in pixels. \param end Screen coordinates of the start of the line in diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 22d4abf..cbbc61a 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -1887,8 +1887,6 @@ void COpenGLDriver::draw2DRectangle(const core::rect& position, void COpenGLDriver::draw2DLine(const core::position2d& start, const core::position2d& end, SColor color) { - // TODO: It's not pixel-exact. Reason is the way OpenGL handles line-drawing (search the web for "diamond exit rule"). - if (start==end) drawPixel(start.X, start.Y, color); else @@ -1923,6 +1921,9 @@ void COpenGLDriver::draw2DLine(const core::position2d& start, } glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, Quad2DIndices); + + // Draw non-drawn last pixel (search for "diamond exit rule") + glDrawArrays(GL_POINTS, 1, 1); } }