diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-04-08 02:16:08 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-04-08 04:38:23 +0200 |
commit | b6e5907f5a228b07824d61e90e668cda8e4079df (patch) | |
tree | 000e509898859cdbbab4d755f4ee37b084147e5d /vcl/source/opengl | |
parent | 0869626e2b29ad9b2e81c8f4eee7bd1b2372d91b (diff) |
temporarily render to a file
Change-Id: Ibfc8101f261489bf11f990ea3fe6ae2e74b99df9
Diffstat (limited to 'vcl/source/opengl')
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index eb800335fedb..29ac4d7c208b 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -11,6 +11,12 @@ #include <vcl/syschild.hxx> #include <vcl/sysdata.hxx> +#include <boost/scoped_array.hpp> +#include <vcl/pngwrite.hxx> +#include <vcl/bmpacc.hxx> +#include <vcl/graph.hxx> +#include <vcl/bitmapex.hxx> + using namespace com::sun::star; OpenGLContext::OpenGLContext(): @@ -470,6 +476,9 @@ void OpenGLContext::setWinSize(const Size& rSize) if(m_pWindow) m_pWindow->SetSizePixel(rSize); m_pChildWindow->SetSizePixel(rSize); + + m_aGLWin.Width = rSize.Width(); + m_aGLWin.Height = rSize.Height(); } GLWindow& OpenGLContext::getOpenGLWindow() @@ -477,6 +486,50 @@ GLWindow& OpenGLContext::getOpenGLWindow() return m_aGLWin; } +void OpenGLContext::renderToFile() +{ + int iWidth = m_aGLWin.Width; + int iHeight = m_aGLWin.Height; + boost::scoped_array<sal_uInt8> buf(new sal_uInt8[iWidth * iHeight * 4]); + glReadPixels(0, 0, iWidth, iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get()); + + Bitmap aBitmap( Size(iWidth, iHeight), 24 ); + AlphaMask aAlpha( Size(iWidth, iHeight) ); + + { + Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); + AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha ); + + size_t nCurPos = 0; + for( int y = 0; y < iHeight; ++y) + { + Scanline pScan = pWriteAccess->GetScanline(y); + Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y); + for( int x = 0; x < iWidth; ++x ) + { + *pScan++ = buf[nCurPos]; + *pScan++ = buf[nCurPos+1]; + *pScan++ = buf[nCurPos+2]; + + nCurPos += 3; + *pAlphaScan++ = static_cast<sal_uInt8>( 255 - buf[nCurPos++] ); + } + } + } + + BitmapEx aBmp(aBitmap, aAlpha); + static int nIdx = 0; + OUString aName = OUString( "file:///home/moggi/Documents/work/text" ) + OUString::number( nIdx++ ) + ".png"; + try { + vcl::PNGWriter aWriter( aBmp ); + SvFileStream sOutput( aName, STREAM_WRITE ); + aWriter.Write( sOutput ); + sOutput.Close(); + } catch (...) { + SAL_WARN("chart2.opengl", "Error writing png to " << aName); + } +} + #if defined( WNT ) bool OpenGLContext::initWindow() |