The code basically is just the draw2dImage(... destRect ...) with the destRect replaced with 4 corner positions.
Code: Select all
virtual void draw2DImage(video::ITexture* texture,
const core::position2d<s32>& leftTop,
const core::position2d<s32>& rightTop,
const core::position2d<s32>& rightBottom,
const core::position2d<s32>& leftBottom,
const core::rect<s32>& sourceRect,
const core::rect<s32>* clipRect = 0,
video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
marvin
patch for:
IVideoDriver
CNullDriver
CD3D8Driver
CD3D9Driver
COpenGLDriver
Code: Select all
Index: include/IVideoDriver.h
===================================================================
--- include/IVideoDriver.h (revision 622)
+++ include/IVideoDriver.h (working copy)
@@ -536,6 +536,25 @@
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
video::SColor* colors=0, bool useAlphaChannelOfTexture=false) = 0;
+ //! Draws a part of the texture into the quad.
+ /**
+ \param texture: the texture to draw from
+ \param leftTop: upper left corner of the destination quad
+ \param rightTop: upper right corner of the destination quad
+ \param rightBottom: lower left corner of the destination quad
+ \param leftBottom: upper right corner of the destination quad
+ \param sourceRect: the rectangle denoting a part of the texture
+ \param clipRect: clips the destination rectangle (may be 0)
+ \param colors: array of 4 colors denoting the color values of the corners of the destRect
+ \param useAlphaChannelOfTexture: true if alpha channel will be blended. */
+ virtual void draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
+ video::SColor* colors=0, bool useAlphaChannelOfTexture=false) = 0;
+
//!Draws an 2d rectangle.
/** \param color: Color of the rectangle to draw. The alpha component will not
be ignored and specifies how transparent the rectangle will be.
Index: source/Irrlicht/CD3D8Driver.cpp
===================================================================
--- source/Irrlicht/CD3D8Driver.cpp (revision 622)
+++ source/Irrlicht/CD3D8Driver.cpp (working copy)
@@ -999,11 +999,37 @@
}
-
void CD3D8Driver::draw2DImage(video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
video::SColor* colors, bool useAlphaChannelOfTexture)
{
+ core::position2d<s32> leftTop(destRect.UpperLeftCorner);
+ core::position2d<s32> rightTop(destRect.UpperLeftCorner);
+ core::position2d<s32> rightBottom(destRect.LowerRightCorner);
+ core::position2d<s32> leftBottom(destRect.UpperLeftCorner);
+
+ rightTop.X+=destRect.getWidth();
+ leftBottom.Y+=destRect.getHeight();
+
+ draw2DImage(texture,
+ leftTop,
+ rightTop,
+ rightBottom,
+ leftBottom,
+ sourceRect,
+ clipRect,
+ colors,
+ useAlphaChannelOfTexture);
+}
+
+void CD3D8Driver::draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
+ video::SColor* colors, bool useAlphaChannelOfTexture)
+{
if(!texture)
return;
@@ -1015,14 +1041,14 @@
tcoords.LowerRightCorner.Y = (f32)sourceRect.LowerRightCorner.Y / (f32)ss.Height;
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
- core::rect<f32> npos;
f32 xFact = 2.0f / ( renderTargetSize.Width );
f32 yFact = 2.0f / ( renderTargetSize.Height );
- npos.UpperLeftCorner.X = ( destRect.UpperLeftCorner.X * xFact ) - 1.0f;
- npos.UpperLeftCorner.Y = 1.0f - ( destRect.UpperLeftCorner.Y * yFact );
- npos.LowerRightCorner.X = ( destRect.LowerRightCorner.X * xFact ) - 1.0f;
- npos.LowerRightCorner.Y = 1.0f - ( destRect.LowerRightCorner.Y * yFact );
+ core::position2d<f32> xy1(( leftTop.X * xFact ) - 1.0f, 1.0f - ( leftTop.Y * yFact ));
+ core::position2d<f32> xy2(( rightTop.X * xFact ) - 1.0f, 1.0f - ( rightTop.Y * yFact ));
+ core::position2d<f32> xy3(( rightBottom.X * xFact ) - 1.0f, 1.0f - ( rightBottom.Y * yFact ));
+ core::position2d<f32> xy4(( leftBottom.X * xFact ) - 1.0f, 1.0f - ( leftBottom.Y * yFact ));
+
video::SColor temp[4] =
{
0xFFFFFFFF,
@@ -1034,10 +1060,10 @@
video::SColor* useColor = colors ? colors : temp;
S3DVertex vtx[4]; // clock wise
- vtx[0] = S3DVertex(npos.UpperLeftCorner.X, npos.UpperLeftCorner.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
- vtx[1] = S3DVertex(npos.LowerRightCorner.X, npos.UpperLeftCorner.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
- vtx[2] = S3DVertex(npos.LowerRightCorner.X, npos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
- vtx[3] = S3DVertex(npos.UpperLeftCorner.X, npos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
+ vtx[0] = S3DVertex(xy1.X, xy1.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
+ vtx[1] = S3DVertex(xy2.X, xy2.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
+ vtx[2] = S3DVertex(xy3.X, xy3.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
+ vtx[3] = S3DVertex(xy4.X, xy4.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
s16 indices[6] = {0,1,2,0,2,3};
@@ -1053,6 +1079,7 @@
+
//!Draws an 2d rectangle with a gradient.
void CD3D8Driver::draw2DRectangle(const core::rect<s32>& position,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
Index: source/Irrlicht/CD3D8Driver.h
===================================================================
--- source/Irrlicht/CD3D8Driver.h (revision 622)
+++ source/Irrlicht/CD3D8Driver.h (working copy)
@@ -78,6 +78,15 @@
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+ //! Draws a part of the texture into a quad.
+ virtual void draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
+ video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+
//!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
Index: source/Irrlicht/CD3D9Driver.cpp
===================================================================
--- source/Irrlicht/CD3D9Driver.cpp (revision 622)
+++ source/Irrlicht/CD3D9Driver.cpp (working copy)
@@ -865,12 +865,37 @@
}
}
-
-
void CD3D9Driver::draw2DImage(video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
video::SColor* colors, bool useAlphaChannelOfTexture)
{
+ core::position2d<s32> leftTop(destRect.UpperLeftCorner);
+ core::position2d<s32> rightTop(destRect.UpperLeftCorner);
+ core::position2d<s32> rightBottom(destRect.LowerRightCorner);
+ core::position2d<s32> leftBottom(destRect.UpperLeftCorner);
+
+ rightTop.X+=destRect.getWidth();
+ leftBottom.Y+=destRect.getHeight();
+
+ draw2DImage(texture,
+ leftTop,
+ rightTop,
+ rightBottom,
+ leftBottom,
+ sourceRect,
+ clipRect,
+ colors,
+ useAlphaChannelOfTexture);
+}
+
+void CD3D9Driver::draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
+ video::SColor* colors, bool useAlphaChannelOfTexture)
+{
if(!texture)
return;
@@ -882,14 +907,14 @@
tcoords.LowerRightCorner.Y = (f32)sourceRect.LowerRightCorner.Y / (f32)ss.Height;
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
- core::rect<f32> npos;
f32 xFact = 2.0f / ( renderTargetSize.Width );
f32 yFact = 2.0f / ( renderTargetSize.Height );
- npos.UpperLeftCorner.X = ( destRect.UpperLeftCorner.X * xFact ) - 1.0f;
- npos.UpperLeftCorner.Y = 1.0f - ( destRect.UpperLeftCorner.Y * yFact );
- npos.LowerRightCorner.X = ( destRect.LowerRightCorner.X * xFact ) - 1.0f;
- npos.LowerRightCorner.Y = 1.0f - ( destRect.LowerRightCorner.Y * yFact );
+ core::position2d<f32> xy1(( leftTop.X * xFact ) - 1.0f, 1.0f - ( leftTop.Y * yFact ));
+ core::position2d<f32> xy2(( rightTop.X * xFact ) - 1.0f, 1.0f - ( rightTop.Y * yFact ));
+ core::position2d<f32> xy3(( rightBottom.X * xFact ) - 1.0f, 1.0f - ( rightBottom.Y * yFact ));
+ core::position2d<f32> xy4(( leftBottom.X * xFact ) - 1.0f, 1.0f - ( leftBottom.Y * yFact ));
+
video::SColor temp[4] =
{
0xFFFFFFFF,
@@ -901,10 +926,10 @@
video::SColor* useColor = colors ? colors : temp;
S3DVertex vtx[4]; // clock wise
- vtx[0] = S3DVertex(npos.UpperLeftCorner.X, npos.UpperLeftCorner.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
- vtx[1] = S3DVertex(npos.LowerRightCorner.X, npos.UpperLeftCorner.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
- vtx[2] = S3DVertex(npos.LowerRightCorner.X, npos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
- vtx[3] = S3DVertex(npos.UpperLeftCorner.X, npos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
+ vtx[0] = S3DVertex(xy1.X, xy1.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
+ vtx[1] = S3DVertex(xy2.X, xy2.Y , 0.0f, 0.0f, 0.0f, 0.0f, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
+ vtx[2] = S3DVertex(xy3.X, xy3.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
+ vtx[3] = S3DVertex(xy4.X, xy4.Y, 0.0f, 0.0f, 0.0f, 0.0f, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
s16 indices[6] = {0,1,2,0,2,3};
@@ -916,11 +941,8 @@
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &indices[0],
D3DFMT_INDEX16,&vtx[0], sizeof(S3DVertex));
-
}
-
-
//! draws a 2d image, using a color and the alpha channel of the texture if
//! desired. The image is drawn at pos and clipped against clipRect (if != 0).
void CD3D9Driver::draw2DImage(video::ITexture* texture,
Index: source/Irrlicht/CD3D9Driver.h
===================================================================
--- source/Irrlicht/CD3D9Driver.h (revision 622)
+++ source/Irrlicht/CD3D9Driver.h (working copy)
@@ -71,6 +71,15 @@
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+ //! Draws a part of the texture into a quad.
+ virtual void draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
+ video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+
//!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
Index: source/Irrlicht/CNullDriver.cpp
===================================================================
--- source/Irrlicht/CNullDriver.cpp (revision 622)
+++ source/Irrlicht/CNullDriver.cpp (working copy)
@@ -629,8 +629,16 @@
{
}
+//! Draws a part of the texture into a quad.
+void CNullDriver::draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
+ video::SColor* colors, bool useAlphaChannelOfTexture)
+{}
-
//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
void CNullDriver::draw2DImage(video::ITexture* texture, const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect,
Index: source/Irrlicht/CNullDriver.h
===================================================================
--- source/Irrlicht/CNullDriver.h (revision 622)
+++ source/Irrlicht/CNullDriver.h (working copy)
@@ -150,6 +150,15 @@
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+ //! Draws a part of the texture into a quad.
+ virtual void draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
+ video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+
//! draw an 2d rectangle
virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip = 0);
Index: source/Irrlicht/COpenGLDriver.cpp
===================================================================
--- source/Irrlicht/COpenGLDriver.cpp (revision 622)
+++ source/Irrlicht/COpenGLDriver.cpp (working copy)
@@ -1297,10 +1297,39 @@
+
void COpenGLDriver::draw2DImage(video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
video::SColor* colors, bool useAlphaChannelOfTexture)
{
+ core::position2d<s32> leftTop(destRect.UpperLeftCorner);
+ core::position2d<s32> rightTop(destRect.UpperLeftCorner);
+ core::position2d<s32> rightBottom(destRect.LowerRightCorner);
+ core::position2d<s32> leftBottom(destRect.UpperLeftCorner);
+
+ rightTop.X+=destRect.getWidth();
+ leftBottom.Y+=destRect.getHeight();
+
+ draw2DImage(texture,
+ leftTop,
+ rightTop,
+ rightBottom,
+ leftBottom,
+ sourceRect,
+ clipRect,
+ colors,
+ useAlphaChannelOfTexture);
+}
+
+//! Draws a part of the texture into a quad.
+void COpenGLDriver::draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
+ video::SColor* colors, bool useAlphaChannelOfTexture)
+{
if (!texture)
return;
@@ -1312,14 +1341,14 @@
tcoords.LowerRightCorner.Y = (f32)sourceRect.LowerRightCorner.Y / (f32)ss.Height;
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
- core::rect<f32> npos;
f32 xFact = 2.0f / ( renderTargetSize.Width );
f32 yFact = 2.0f / ( renderTargetSize.Height );
- npos.UpperLeftCorner.X = ( destRect.UpperLeftCorner.X * xFact ) - 1.0f;
- npos.UpperLeftCorner.Y = 1.0f - ( destRect.UpperLeftCorner.Y * yFact );
- npos.LowerRightCorner.X = ( destRect.LowerRightCorner.X * xFact ) - 1.0f;
- npos.LowerRightCorner.Y = 1.0f - ( destRect.LowerRightCorner.Y * yFact );
+ core::position2d<f32> xy1(( leftTop.X * xFact ) - 1.0f, 1.0f - ( leftTop.Y * yFact ));
+ core::position2d<f32> xy2(( rightTop.X * xFact ) - 1.0f, 1.0f - ( rightTop.Y * yFact ));
+ core::position2d<f32> xy3(( rightBottom.X * xFact ) - 1.0f, 1.0f - ( rightBottom.Y * yFact ));
+ core::position2d<f32> xy4(( leftBottom.X * xFact ) - 1.0f, 1.0f - ( leftBottom.Y * yFact ));
+
video::SColor temp[4] =
{
0xFFFFFFFF,
@@ -1335,39 +1364,28 @@
disableTextures(1);
setTexture(0, texture);
- if (clipRect)
- {
- glEnable(GL_SCISSOR_TEST);
- glScissor(clipRect->UpperLeftCorner.X,renderTargetSize.Height-clipRect->LowerRightCorner.Y,
- clipRect->getWidth(),clipRect->getHeight());
- }
-
glBegin(GL_QUADS);
glColor4ub(useColor[0].getRed(), useColor[0].getGreen(), useColor[0].getBlue(), useColor[0].getAlpha());
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
- glVertex2f(npos.UpperLeftCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(xy1.X, xy1.Y);
glColor4ub(useColor[3].getRed(), useColor[3].getGreen(), useColor[3].getBlue(), useColor[3].getAlpha());
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
- glVertex2f(npos.LowerRightCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(xy2.X, xy2.Y);
glColor4ub(useColor[2].getRed(), useColor[2].getGreen(), useColor[2].getBlue(), useColor[2].getAlpha());
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
- glVertex2f(npos.LowerRightCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(xy3.X, xy3.Y);
glColor4ub(useColor[1].getRed(), useColor[1].getGreen(), useColor[1].getBlue(), useColor[1].getAlpha());
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
- glVertex2f(npos.UpperLeftCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(xy4.X, xy4.Y);
glEnd();
-
- if (clipRect)
- glDisable(GL_SCISSOR_TEST);
}
-
//! draw a 2d rectangle
void COpenGLDriver::draw2DRectangle(SColor color, const core::rect<s32>& position,
const core::rect<s32>* clip)
Index: source/Irrlicht/COpenGLDriver.h
===================================================================
--- source/Irrlicht/COpenGLDriver.h (revision 622)
+++ source/Irrlicht/COpenGLDriver.h (working copy)
@@ -140,6 +140,15 @@
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+ //! Draws a part of the texture into a quad.
+ virtual void draw2DImage(video::ITexture* texture,
+ const core::position2d<s32>& leftTop,
+ const core::position2d<s32>& rightTop,
+ const core::position2d<s32>& rightBottom,
+ const core::position2d<s32>& leftBottom,
+ const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
+ video::SColor* colors=0, bool useAlphaChannelOfTexture=false);
+
//! draw an 2d rectangle
virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip = 0);