diff options
author | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-09-21 08:13:54 +0200 |
---|---|---|
committer | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-09-21 15:49:53 +0200 |
commit | 3ef6bcc291df6d0c67709d1c97f4d55d75e77179 (patch) | |
tree | c92e6f83f7d2a4183f663979f94a1db7af58f8e2 /chart2 | |
parent | f5b24e71828fc6eb095fdd7167bdc8043525563d (diff) |
fdo#81237: 2D OpenGL charts have wrong size
So far the size unit was 100th mm \ OPENGL_SCALE_VALUE
which is an absolute value, independent from the actual
size of the OpenGL window.
To solve that I added the SetSizePixel() method with
which we can specify the size in pixels and which
method resize the whole scene accordingly.
Change-Id: Ibd19a1bd9484c7bc8f8ce0d8113f60b95619db39
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/inc/AbstractShapeFactory.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/inc/OpenglShapeFactory.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/inc/ShapeFactory.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/DummyXShape.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/OpenGLRender.cxx | 20 | ||||
-rw-r--r-- | chart2/source/view/main/OpenGLRender.hxx | 1 | ||||
-rw-r--r-- | chart2/source/view/main/OpenglShapeFactory.cxx | 4 |
8 files changed, 20 insertions, 15 deletions
diff --git a/chart2/source/view/inc/AbstractShapeFactory.hxx b/chart2/source/view/inc/AbstractShapeFactory.hxx index ffa99b7526d1..b684ae28a94b 100644 --- a/chart2/source/view/inc/AbstractShapeFactory.hxx +++ b/chart2/source/view/inc/AbstractShapeFactory.hxx @@ -240,7 +240,7 @@ public: */ virtual void render(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > xRootShape, bool bInitOpenGL = true) = 0; - virtual bool preRender(OpenGLWindow* pWindow) = 0; + virtual bool preRender(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > xRootShape, OpenGLWindow* pWindow) = 0; virtual void postRender(OpenGLWindow* pWindow) = 0; virtual void clearPage(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > xRootShape) = 0; diff --git a/chart2/source/view/inc/OpenglShapeFactory.hxx b/chart2/source/view/inc/OpenglShapeFactory.hxx index 6f236537b19b..9f0a360595dd 100644 --- a/chart2/source/view/inc/OpenglShapeFactory.hxx +++ b/chart2/source/view/inc/OpenglShapeFactory.hxx @@ -186,7 +186,7 @@ public: virtual void render(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > xDrawPage, bool bInitOpenGL = true) SAL_OVERRIDE; - virtual bool preRender(OpenGLWindow* pWindow) SAL_OVERRIDE; + virtual bool preRender(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > xRootShape, OpenGLWindow* pWindow) SAL_OVERRIDE; virtual void postRender(OpenGLWindow* pWindow) SAL_OVERRIDE; virtual void clearPage(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > xDrawPage) SAL_OVERRIDE; diff --git a/chart2/source/view/inc/ShapeFactory.hxx b/chart2/source/view/inc/ShapeFactory.hxx index 58076bdd61b3..d7973da941dd 100644 --- a/chart2/source/view/inc/ShapeFactory.hxx +++ b/chart2/source/view/inc/ShapeFactory.hxx @@ -199,7 +199,7 @@ public: */ virtual void render(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >, bool ) SAL_OVERRIDE {} - virtual bool preRender(OpenGLWindow*) SAL_OVERRIDE { return true; } + virtual bool preRender(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >, OpenGLWindow*) SAL_OVERRIDE { return true; } virtual void postRender(OpenGLWindow*) SAL_OVERRIDE {} virtual void clearPage(com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > ) SAL_OVERRIDE {} diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 3a6e6f5e06c7..9d75323de847 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -2555,7 +2555,7 @@ void ChartView::render() OpenGLWindow* pWindow = mrChartModel.getOpenGLWindow(); if(pWindow) pWindow->setRenderer(mp2DRenderer.get()); - bool bRender = pShapeFactory->preRender(pWindow); + bool bRender = pShapeFactory->preRender(mxRootShape, pWindow); if(bRender) { pShapeFactory->render(mxRootShape, pWindow != mp2DRenderer->getOpenGLWindow()); diff --git a/chart2/source/view/main/DummyXShape.hxx b/chart2/source/view/main/DummyXShape.hxx index 54f5df42f343..6b03733f39f8 100644 --- a/chart2/source/view/main/DummyXShape.hxx +++ b/chart2/source/view/main/DummyXShape.hxx @@ -398,6 +398,8 @@ public: void invalidateInit() { mbNotInit = true; } TextCache& getTextCache() { return maTextCache;} + OpenGLRender& getRenderer() { return m_GLRender; } + private: TextCache maTextCache; diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 6cdb5fd26268..64c94cbc0a6f 100644 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -106,14 +106,6 @@ int OpenGLRender::InitOpenGL() glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //Init the Projection matrix - m_Projection = glm::ortho(0.f, float(m_iWidth), -float(m_iHeight), 0.f, -1.f, 1.f); - m_Projection = m_Projection * glm::scale(glm::vec3(1.0f, -1.0f, 1.0f)); - m_View = glm::lookAt(glm::vec3(0,0,1), // Camera is at (4,3,-3), in World Space - glm::vec3(0,0,0), // and looks at the origin - glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) - ); - m_MVP = m_Projection * m_View * m_Model; glGenBuffers(1, &m_VertexBuffer); glGenBuffers(1, &m_ColorBuffer); @@ -357,8 +349,16 @@ void OpenGLRender::SetSize(int width, int height) { m_iWidth = width; m_iHeight = height; - m_Projection = glm::ortho(0.f, float(m_iWidth), -float(m_iHeight), 0.f, -4.f, 3.f); - m_Projection = m_Projection * glm::scale(glm::vec3(1.0f, -1.0f, 1.0f)); +} + +void OpenGLRender::SetSizePixel(int width, int height) +{ + m_Projection = glm::ortho(0.f, float(m_iWidth), 0.f, float(m_iHeight), -4.f, 3.f); + m_Projection = m_Projection * glm::scale((float)width / m_iWidth, -(float)height / m_iHeight, 1.0f); + + m_View = glm::lookAt(glm::vec3(0,m_iHeight,1), + glm::vec3(0,m_iHeight,0), + glm::vec3(0,1,0) ); } void OpenGLRender::SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b, sal_uInt8 nAlpha) diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx index 26f81c2b5922..6203b4307608 100644 --- a/chart2/source/view/main/OpenGLRender.hxx +++ b/chart2/source/view/main/OpenGLRender.hxx @@ -72,6 +72,7 @@ public: int InitOpenGL(); int MoveModelf(PosVecf3 trans, PosVecf3 angle, PosVecf3 scale); void SetSize(int width, int height); + void SetSizePixel(int width, int height); void Release(); int RenderLine2FBO(int wholeFlag); int SetLine2DShapePoint(float x, float y, int listLength); diff --git a/chart2/source/view/main/OpenglShapeFactory.cxx b/chart2/source/view/main/OpenglShapeFactory.cxx index 9443641e3d68..0f2dfe2b9930 100644 --- a/chart2/source/view/main/OpenglShapeFactory.cxx +++ b/chart2/source/view/main/OpenglShapeFactory.cxx @@ -456,7 +456,7 @@ void OpenglShapeFactory::render(uno::Reference< drawing::XShapes > xRootShape, b rChart.render(); } -bool OpenglShapeFactory::preRender(OpenGLWindow* pWindow) +bool OpenglShapeFactory::preRender(uno::Reference< drawing::XShapes > xRootShape, OpenGLWindow* pWindow) { if(!pWindow) return false; @@ -465,6 +465,8 @@ bool OpenglShapeFactory::preRender(OpenGLWindow* pWindow) pWindow->getContext().makeCurrent(); Size aSize = pWindow->GetSizePixel(); pWindow->getContext().setWinSize(aSize); + dummy::DummyChart& rChart = dynamic_cast<dummy::DummyChart&>(*xRootShape.get()); + rChart.getRenderer().SetSizePixel(aSize.Width(), aSize.Height()); return true; } |