diff --git a/changes.txt b/changes.txt index 5df45f2c..63ce50e4 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,9 @@ Changes in version 1.4 (... 2007) + - OpenGL render targets now the same way up as the other drivers. If you have + written opengl shaders that use render targets then you'll need to change your + texture coordinates accordingly. + - Fixed some OpenGL renderstate stuff. setBasicRenderstate returns with active texture layer 0. The material renderer must return from OnUnset with the same active texture layer. The alpha test is disabled and the diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 123b5015..067cd6bd 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -34,7 +34,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d& screenSize, HWND wind : CNullDriver(io, screenSize), COpenGLExtensionHandler(), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(antiAlias), RenderTargetTexture(0), LastSetLight(-1), - CurrentRendertargetSize(0,0), + CurrentRendertargetSize(0,0), ClockwiseWinding(true), HDc(0), Window(window), HRc(0) { #ifdef _DEBUG @@ -157,7 +157,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d& screenSize, bool full : CNullDriver(io, screenSize), COpenGLExtensionHandler(), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(antiAlias), - RenderTargetTexture(0), LastSetLight(-1), + LastSetLight(-1), RenderTargetTexture(0), ClockwiseWinding(true), CurrentRendertargetSize(0,0), _device(device) { #ifdef _DEBUG @@ -177,7 +177,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d& screenSize, bool full : CNullDriver(io, screenSize), COpenGLExtensionHandler(), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(antiAlias), - RenderTargetTexture(0), LastSetLight(-1), + LastSetLight(-1), RenderTargetTexture(0), ClockwiseWinding(true), CurrentRendertargetSize(0,0) { #ifdef _DEBUG @@ -213,7 +213,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d& screenSize, bool full : CNullDriver(io, screenSize), COpenGLExtensionHandler(), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(antiAlias), - RenderTargetTexture(0), LastSetLight(-1), + LastSetLight(-1), RenderTargetTexture(0), ClockwiseWinding(true), CurrentRendertargetSize(0,0) { #ifdef _DEBUG @@ -448,6 +448,25 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri createGLMatrix(glmat, mat); // flip z to compensate OpenGLs right-hand coordinate system glmat[12] *= -1.0f; + // in render targets, flip the screen + if ( CurrentRendertargetSize.Width > 0 ) + { + glmat[5] *= -1.0f; + // because we flipped the screen, triangles are the wrong way around + if (ClockwiseWinding) + { + glFrontFace(GL_CCW); + ClockwiseWinding = false; + } + } + else + { + if (!ClockwiseWinding) + { + glFrontFace(GL_CW); + ClockwiseWinding = true; + } + } glMatrixMode(GL_PROJECTION); glLoadMatrixf(glmat); break; diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index 1c51c643..34ceedc5 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -329,6 +329,9 @@ namespace video s32 LastSetLight; core::dimension2d CurrentRendertargetSize; + //! bool to see if we are using clockwise or counter-clockwise winding, + //! render targets use opposite winding as their projection matrix is flipped. + bool ClockwiseWinding; #ifdef _IRR_WINDOWS_API_ HDC HDc; // Private GDI Device Context