Sorry for the late reply, I've been busy on other projects and "real life" stuff.
The patch was a quick fix, involving just 4 lines, usually small patches are easier to review and are included faster.
Here is a more invasive patch, it's faster because the CPU doesn't have to process anything, and there is less code. But every function calling setRenderStates2DMode() is modified : draw2DImage() (3 functions), draw2DRectangle() (2 functions) and draw2DLine().
I don't know if the glScissor are handled correctly, it should be good but a test program would be handy.
Code: Select all
--- source/Irrlicht/COpenGLDriver.cpp.ori 2007-06-13 09:43:32.000000000 +0200
+++ source/Irrlicht/COpenGLDriver.cpp 2007-08-11 16:46:31.000000000 +0200
@@ -730,14 +730,6 @@ void COpenGLDriver::draw2DImage(video::I
tcoords.LowerRightCorner.Y = ((f32)sourcePos.Y + (f32)sourceSize.Height) / (f32)ss.Height;
core::rect<s32> poss(targetPos, sourceSize);
- core::rect<f32> npos;
- f32 xFact = 2.0f / ( renderTargetSize.Width );
- f32 yFact = 2.0f / ( renderTargetSize.Height );
-
- npos.UpperLeftCorner.X = ( poss.UpperLeftCorner.X * xFact ) - 1.0f;
- npos.UpperLeftCorner.Y = 1.0f - ( poss.UpperLeftCorner.Y * yFact );
- npos.LowerRightCorner.X = ( poss.LowerRightCorner.X * xFact ) - 1.0f;
- npos.LowerRightCorner.Y = 1.0f - ( poss.LowerRightCorner.Y * yFact );
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
disableTextures(1);
@@ -748,16 +740,16 @@ void COpenGLDriver::draw2DImage(video::I
glBegin(GL_QUADS);
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
- glVertex2f(npos.UpperLeftCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(poss.UpperLeftCorner.X, poss.UpperLeftCorner.Y);
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
- glVertex2f(npos.LowerRightCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(poss.LowerRightCorner.X, poss.UpperLeftCorner.Y);
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
- glVertex2f(npos.LowerRightCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(poss.LowerRightCorner.X, poss.LowerRightCorner.Y);
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
- glVertex2f(npos.UpperLeftCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(poss.UpperLeftCorner.X, poss.LowerRightCorner.Y);
glEnd();
}
@@ -779,7 +771,6 @@ void COpenGLDriver::draw2DImage(video::I
if (!texture)
return;
- const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
disableTextures(1);
if (!setTexture(0, texture))
@@ -789,7 +780,7 @@ void COpenGLDriver::draw2DImage(video::I
if (clipRect)
{
glEnable(GL_SCISSOR_TEST);
- glScissor(clipRect->UpperLeftCorner.X,renderTargetSize.Height-clipRect->LowerRightCorner.Y,
+ glScissor(clipRect->UpperLeftCorner.X,clipRect->LowerRightCorner.Y,
clipRect->getWidth(),clipRect->getHeight());
}
@@ -798,8 +789,6 @@ void COpenGLDriver::draw2DImage(video::I
core::position2d<s32> sourcePos;
core::dimension2d<s32> sourceSize;
core::rect<f32> tcoords;
- f32 xFact = 2.0f / ( renderTargetSize.Width );
- f32 yFact = 2.0f / ( renderTargetSize.Height );
for (u32 i=0; i<indices.size(); ++i)
{
@@ -815,27 +804,20 @@ void COpenGLDriver::draw2DImage(video::I
tcoords.LowerRightCorner.Y = (f32)sourceRects[currentIndex].LowerRightCorner.Y / (f32)ss.Height;
core::rect<s32> poss(targetPos, sourceSize);
- core::rect<f32> npos;
-
- npos.UpperLeftCorner.X = ( poss.UpperLeftCorner.X * xFact ) - 1.0f;
- npos.UpperLeftCorner.Y = 1.0f - ( poss.UpperLeftCorner.Y * yFact );
-
- npos.LowerRightCorner.X = ( poss.LowerRightCorner.X * xFact ) - 1.0f;
- npos.LowerRightCorner.Y = 1.0f - ( poss.LowerRightCorner.Y * yFact );
glBegin(GL_QUADS);
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
- glVertex2f(npos.UpperLeftCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(poss.UpperLeftCorner.X, poss.UpperLeftCorner.Y);
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
- glVertex2f(npos.LowerRightCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(poss.LowerRightCorner.X, poss.UpperLeftCorner.Y);
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
- glVertex2f(npos.LowerRightCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(poss.LowerRightCorner.X, poss.LowerRightCorner.Y);
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
- glVertex2f(npos.UpperLeftCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(poss.UpperLeftCorner.X, poss.LowerRightCorner.Y);
glEnd();
targetPos.X += sourceRects[currentIndex].getWidth();
@@ -860,15 +842,6 @@ void COpenGLDriver::draw2DImage(video::I
tcoords.LowerRightCorner.X = (f32)sourceRect.LowerRightCorner.X / (f32)ss.Width;
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 );
-
video::SColor temp[4] =
{
0xFFFFFFFF,
@@ -887,7 +860,7 @@ void COpenGLDriver::draw2DImage(video::I
if (clipRect)
{
glEnable(GL_SCISSOR_TEST);
- glScissor(clipRect->UpperLeftCorner.X,renderTargetSize.Height-clipRect->LowerRightCorner.Y,
+ glScissor(clipRect->UpperLeftCorner.X,clipRect->LowerRightCorner.Y,
clipRect->getWidth(),clipRect->getHeight());
}
@@ -895,19 +868,19 @@ void COpenGLDriver::draw2DImage(video::I
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(destRect.UpperLeftCorner.X, destRect.UpperLeftCorner.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(destRect.LowerRightCorner.X, destRect.UpperLeftCorner.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(destRect.LowerRightCorner.X, destRect.LowerRightCorner.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(destRect.UpperLeftCorner.X, destRect.LowerRightCorner.Y);
glEnd();
@@ -932,18 +905,9 @@ void COpenGLDriver::draw2DRectangle(SCol
if (!pos.isValid())
return;
- const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
- s32 xPlus = renderTargetSize.Width>>1;
- f32 xFact = 1.0f / (renderTargetSize.Width>>1);
-
- s32 yPlus = renderTargetSize.Height-(renderTargetSize.Height>>1);
- f32 yFact = 1.0f / (renderTargetSize.Height>>1);
-
glColor4ub(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
- glRectf((pos.UpperLeftCorner.X-xPlus) * xFact,
- (yPlus-pos.UpperLeftCorner.Y) * yFact,
- (pos.LowerRightCorner.X-xPlus) * xFact,
- (yPlus-pos.LowerRightCorner.Y) * yFact);
+ glRectf(pos.UpperLeftCorner.X,pos.UpperLeftCorner.Y,
+ pos.LowerRightCorner.X,pos.LowerRightCorner.Y);
}
@@ -961,19 +925,6 @@ void COpenGLDriver::draw2DRectangle(cons
if (!pos.isValid())
return;
- const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
- s32 xPlus = renderTargetSize.Width>>1;
- f32 xFact = 1.0f / (renderTargetSize.Width>>1);
-
- s32 yPlus = renderTargetSize.Height-(renderTargetSize.Height>>1);
- f32 yFact = 1.0f / (renderTargetSize.Height>>1);
-
- core::rect<f32> npos;
- npos.UpperLeftCorner.X = (f32)(pos.UpperLeftCorner.X-xPlus) * xFact;
- npos.UpperLeftCorner.Y = (f32)(yPlus-pos.UpperLeftCorner.Y) * yFact;
- npos.LowerRightCorner.X = (f32)(pos.LowerRightCorner.X-xPlus) * xFact;
- npos.LowerRightCorner.Y = (f32)(yPlus-pos.LowerRightCorner.Y) * yFact;
-
setRenderStates2DMode(colorLeftUp.getAlpha() < 255 ||
colorRightUp.getAlpha() < 255 ||
colorLeftDown.getAlpha() < 255 ||
@@ -984,19 +935,19 @@ void COpenGLDriver::draw2DRectangle(cons
glBegin(GL_QUADS);
glColor4ub(colorLeftUp.getRed(), colorLeftUp.getGreen(),
colorLeftUp.getBlue(), colorLeftUp.getAlpha());
- glVertex2f(npos.UpperLeftCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(pos.UpperLeftCorner.X, pos.UpperLeftCorner.Y);
glColor4ub(colorRightUp.getRed(), colorRightUp.getGreen(),
colorRightUp.getBlue(), colorRightUp.getAlpha());
- glVertex2f(npos.LowerRightCorner.X, npos.UpperLeftCorner.Y);
+ glVertex2f(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y);
glColor4ub(colorRightDown.getRed(), colorRightDown.getGreen(),
colorRightDown.getBlue(), colorRightDown.getAlpha());
- glVertex2f(npos.LowerRightCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(pos.LowerRightCorner.X, pos.LowerRightCorner.Y);
glColor4ub(colorLeftDown.getRed(), colorLeftDown.getGreen(),
colorLeftDown.getBlue(), colorLeftDown.getAlpha());
- glVertex2f(npos.UpperLeftCorner.X, npos.LowerRightCorner.Y);
+ glVertex2f(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y);
glEnd();
}
@@ -1008,31 +959,13 @@ void COpenGLDriver::draw2DLine(const cor
const core::position2d<s32>& end,
SColor color)
{
- // thanks to Vash TheStampede who sent in his implementation
-
- const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
- const s32 xPlus = renderTargetSize.Width>>1;
- const f32 xFact = 1.0f / (renderTargetSize.Width>>1);
-
- const s32 yPlus =
- renderTargetSize.Height-(renderTargetSize.Height>>1);
- const f32 yFact = 1.0f / (renderTargetSize.Height>>1);
-
- core::position2d<f32> npos_start;
- npos_start.X = (f32)(start.X - xPlus) * xFact;
- npos_start.Y = (f32)(yPlus - start.Y) * yFact;
-
- core::position2d<f32> npos_end;
- npos_end.X = (f32)(end.X - xPlus) * xFact;
- npos_end.Y = (f32)(yPlus - end.Y) * yFact;
-
setRenderStates2DMode(color.getAlpha() < 255, false, false);
disableTextures();
glBegin(GL_LINES);
glColor4ub(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
- glVertex2f(npos_start.X, npos_start.Y);
- glVertex2f(npos_end.X, npos_end.Y);
+ glVertex2f(start.X, start.Y);
+ glVertex2f(end.X, end.Y);
glEnd();
}
@@ -1485,6 +1418,10 @@ void COpenGLDriver::setRenderStates2DMod
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
+ // see http://www.opengl.org/resources/faq/technical/transformations.htm#tran0030
+ const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
+ gluOrtho2D(0, renderTargetSize.Width, renderTargetSize.Height, 0);
+ glTranslatef (0.375, 0.375, 0.);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();