diff options
-rw-r--r-- | chart2/Library_chartcore.mk | 2 | ||||
-rw-r--r-- | chart2/source/view/charttypes/3DBarChart.cxx | 2 | ||||
-rw-r--r-- | chart2/source/view/inc/3DChartObjects.hxx | 4 | ||||
-rw-r--r-- | chart2/source/view/main/3DChartObjects.cxx | 9 | ||||
-rw-r--r-- | include/vcl/OpenGLContext.hxx | 2 | ||||
-rw-r--r-- | vcl/Library_vclopengl.mk | 1 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 53 |
7 files changed, 70 insertions, 3 deletions
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk index e4b0051cfd6a..e027865c9e11 100644 --- a/chart2/Library_chartcore.mk +++ b/chart2/Library_chartcore.mk @@ -249,6 +249,4 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\ chart2/source/tools/XMLRangeHelper \ )) - - # vim: set noet sw=4 ts=4: diff --git a/chart2/source/view/charttypes/3DBarChart.cxx b/chart2/source/view/charttypes/3DBarChart.cxx index 3a13059be014..e8db5bfb47c0 100644 --- a/chart2/source/view/charttypes/3DBarChart.cxx +++ b/chart2/source/view/charttypes/3DBarChart.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <GL/glew.h> + #include "3DBarChart.hxx" #include <glm/glm.hpp> diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index f7eed23e8733..257653f5ecff 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -71,12 +71,16 @@ namespace temporary { class TemporaryContext { public: + TemporaryContext(); void init(); void render(); private: OpenGLContext maContext; + + int miWidth; + int miHeight; }; } diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 3c5a5b8b6138..c74b475babef 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -20,14 +20,21 @@ Bar::Bar(const glm::mat4& rPosition): namespace temporary { +TemporaryContext::TemporaryContext(): + miWidth(200), + miHeight(200) +{ +} + void TemporaryContext::init() { maContext.init(); + maContext.setWinSize(Size(miWidth, miHeight)); } void TemporaryContext::render() { - + maContext.renderToFile(); } } diff --git a/include/vcl/OpenGLContext.hxx b/include/vcl/OpenGLContext.hxx index 8c7eb5513c3b..b62448a2e241 100644 --- a/include/vcl/OpenGLContext.hxx +++ b/include/vcl/OpenGLContext.hxx @@ -103,6 +103,8 @@ public: void setWinSize(const Size& rSize); GLWindow& getOpenGLWindow(); + void renderToFile(); + private: SAL_DLLPRIVATE bool initWindow(); diff --git a/vcl/Library_vclopengl.mk b/vcl/Library_vclopengl.mk index 793f09f3fe8c..e14899baf3de 100644 --- a/vcl/Library_vclopengl.mk +++ b/vcl/Library_vclopengl.mk @@ -32,6 +32,7 @@ $(eval $(call gb_Library_use_libraries,vclopengl,\ cppu \ cppuhelper \ sal \ + tl \ vcl \ $(gb_UWINAPI) \ )) 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() |