diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index c6864b6c..bfc6f7de 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -590,6 +590,11 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)) = 0; + //! Draws a pixel. + /** \param position: the position of the pixel. + \param color: Color of the pixel to draw. */ + virtual void drawPixel(u32 x, u32 y, const SColor & color) = 0; + //! Draws a non filled concyclic regular 2d polyon. /** This method can be used to draw circles, but also triangles, tetragons, pentagons, hexagons, heptagons, octagons, diff --git a/source/Irrlicht/CD3D8Driver.cpp b/source/Irrlicht/CD3D8Driver.cpp index 747cf845..d07351aa 100644 --- a/source/Irrlicht/CD3D8Driver.cpp +++ b/source/Irrlicht/CD3D8Driver.cpp @@ -1211,6 +1211,29 @@ void CD3D8Driver::draw2DLine(const core::position2d& start, pID3DDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vtx[0], sizeof(S3DVertex)); } +//! Draws a pixel +void CD3D8Driver::drawPixel(u32 x, u32 y, const SColor & color) +{ + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + if(x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height) + return; + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + setTexture(0,0); + + setVertexShader(EVT_STANDARD); + + const s32 xPlus = -renderTargetSize.Width / 2; + const f32 xFact = 2.0f / renderTargetSize.Width; + const s32 yPlus = renderTargetSize.Height / 2; + const f32 yFact = 2.0f / renderTargetSize.Height; + S3DVertex vertex((f32)((s32)x + xPlus) * xFact, + (f32)(yPlus - (s32)y) * yFact, + 0.f, 0.f, 0.f, 0.f, color, 0.f, 0.f); + + pID3DDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &vertex, sizeof(vertex)); +} + //! sets right vertex shader diff --git a/source/Irrlicht/CD3D8Driver.h b/source/Irrlicht/CD3D8Driver.h index ab2ae79c..0891a942 100644 --- a/source/Irrlicht/CD3D8Driver.h +++ b/source/Irrlicht/CD3D8Driver.h @@ -93,6 +93,9 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)); + //! Draws a pixel. + virtual void drawPixel(u32 x, u32 y, const SColor & color); + //! Draws a 3d line. virtual void draw3DLine(const core::vector3df& start, const core::vector3df& end, SColor color = SColor(255,255,255,255)); diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index 0875770b..7f660342 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -1513,6 +1513,28 @@ void CD3D9Driver::draw2DLine(const core::position2d& start, &vtx[0], sizeof(S3DVertex) ); } +//! Draws a pixel +void CD3D9Driver::drawPixel(u32 x, u32 y, const SColor & color) +{ + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + if(x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height) + return; + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + setTexture(0,0); + + setVertexShader(EVT_STANDARD); + + const s32 xPlus = -renderTargetSize.Width / 2; + const f32 xFact = 2.0f / renderTargetSize.Width; + const s32 yPlus = renderTargetSize.Height / 2; + const f32 yFact = 2.0f / renderTargetSize.Height; + S3DVertex vertex((f32)((s32)x + xPlus) * xFact, + (f32)(yPlus - (s32)y) * yFact, + 0.f, 0.f, 0.f, 0.f, color, 0.f, 0.f); + + pID3DDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &vertex, sizeof(vertex)); +} //! sets right vertex shader diff --git a/source/Irrlicht/CD3D9Driver.h b/source/Irrlicht/CD3D9Driver.h index 87599dd5..19120670 100644 --- a/source/Irrlicht/CD3D9Driver.h +++ b/source/Irrlicht/CD3D9Driver.h @@ -113,6 +113,9 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)); + //! Draws a pixel. + virtual void drawPixel(u32 x, u32 y, const SColor & color); + //! Draws a 3d line. virtual void draw3DLine(const core::vector3df& start, const core::vector3df& end, SColor color = SColor(255,255,255,255)); diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 07c247de..588a00e2 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -688,6 +688,10 @@ void CNullDriver::draw2DLine(const core::position2d& start, { } +//! Draws a pixel +void CNullDriver::drawPixel(u32 x, u32 y, const SColor & color) +{ +} //! Draws a non filled concyclic regular 2d polyon. diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index f0de00ce..8a40f8b1 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -186,6 +186,9 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)); + //! Draws a pixel + virtual void drawPixel(u32 x, u32 y, const SColor & color); + //! Draws a non filled concyclic reqular 2d polyon. virtual void draw2DPolygon(core::position2d center, f32 radius, video::SColor Color, s32 vertexCount); diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 4814207a..dc2c696b 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -1487,7 +1487,21 @@ void COpenGLDriver::draw2DLine(const core::position2d& start, glEnd(); } +//! Draws a pixel +void COpenGLDriver::drawPixel(u32 x, u32 y, const SColor &color) +{ + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + if(x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height) + return; + disableTextures(); + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + glBegin(GL_POINTS); + glColor4ub(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + glVertex2i(x, y); + glEnd(); +} bool COpenGLDriver::setTexture(u32 stage, const video::ITexture* texture) { diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index c63b4c04..5632e6d2 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -201,6 +201,9 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)); + //! Draws a single pixel + virtual void drawPixel(u32 x, u32 y, const SColor & color); + //! Draws a 3d line. virtual void draw3DLine(const core::vector3df& start, const core::vector3df& end, diff --git a/source/Irrlicht/CSoftwareDriver.cpp b/source/Irrlicht/CSoftwareDriver.cpp index 815b31c9..9893927c 100644 --- a/source/Irrlicht/CSoftwareDriver.cpp +++ b/source/Irrlicht/CSoftwareDriver.cpp @@ -812,7 +812,12 @@ void CSoftwareDriver::draw2DLine(const core::position2d& start, ((CImage*)RenderTargetSurface)->drawLine(start, end, color ); } - +//! Draws a pixel +void CSoftwareDriver::drawPixel(u32 x, u32 y, const SColor & color) +{ + ((CImage*)BackBuffer)->setPixel(x, y, color); +} + //! draw a 2d rectangle void CSoftwareDriver::draw2DRectangle(SColor color, const core::rect& pos, diff --git a/source/Irrlicht/CSoftwareDriver.h b/source/Irrlicht/CSoftwareDriver.h index b84b036d..7494ea2c 100644 --- a/source/Irrlicht/CSoftwareDriver.h +++ b/source/Irrlicht/CSoftwareDriver.h @@ -83,6 +83,9 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)); + //! Draws a single pixel + virtual void drawPixel(u32 x, u32 y, const SColor & color); + //! \return Returns the name of the video driver. Example: In case of the Direct3D8 //! driver, it would return "Direct3D8.1". virtual const wchar_t* getName() const; diff --git a/source/Irrlicht/CSoftwareDriver2.cpp b/source/Irrlicht/CSoftwareDriver2.cpp index 4db707ab..8f666c69 100644 --- a/source/Irrlicht/CSoftwareDriver2.cpp +++ b/source/Irrlicht/CSoftwareDriver2.cpp @@ -1578,6 +1578,11 @@ void CBurningVideoDriver::draw2DLine(const core::position2d& start, ((CImage*)BackBuffer)->drawLine(start, end, color ); } +//! Draws a pixel +void CBurningVideoDriver::drawPixel(u32 x, u32 y, const SColor & color) +{ + ((CImage*)BackBuffer)->setPixel(x, y, color); +} //! draw an 2d rectangle void CBurningVideoDriver::draw2DRectangle(SColor color, const core::rect& pos, diff --git a/source/Irrlicht/CSoftwareDriver2.h b/source/Irrlicht/CSoftwareDriver2.h index 12f7a186..3647111c 100644 --- a/source/Irrlicht/CSoftwareDriver2.h +++ b/source/Irrlicht/CSoftwareDriver2.h @@ -99,6 +99,9 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)); + //! Draws a single pixel + virtual void drawPixel(u32 x, u32 y, const SColor & color); + //! \return Returns the name of the video driver. Example: In case of the DirectX8 //! driver, it would return "Direct3D8.1". virtual const wchar_t* getName() const;