From ad491f201ad35c8ab3a687f40dfc4d0680c61cb7 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Tue, 4 Feb 2014 22:01:37 +0100 Subject: make bar charts working Apparently the bar chart polygon points are clockwise and are therefore culled. Detect and change the front facing setting that case. Disabling culling does not work here. Change-Id: I5b243210d1febcbae2126f099455dd1330a5b7d6 --- chart2/source/view/main/OpenGLRender.cxx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'chart2/source') diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 5e1f5dda1dd0..74eb078f5bfc 100755 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -241,6 +241,7 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow) glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one @@ -1487,6 +1488,31 @@ int OpenGLRender::SetArea2DShapePoint(float x, float y, int listLength) return 0; } +namespace { + +// only 2D +bool checkCCW(const Area2DPointList& rPoints) +{ + if(rPoints.size() < 3) + return true; + + GLfloat sum = 0; + for(size_t i = 1; i < rPoints.size()/3; i += 3) + { + GLfloat x1 = rPoints[(i-1)*3]; + GLfloat x2 = rPoints[i*3]; + GLfloat y1 = rPoints[(i-1)*3 + 1]; + GLfloat y2 = rPoints[i*3 + 1]; + GLfloat prod = (x2-x1)*(y2+y1); + + sum += prod; + } + + return (sum <= 0); +} + +} + int OpenGLRender::RenderArea2DShape() { CHECK_GL_ERROR(); @@ -1501,6 +1527,9 @@ int OpenGLRender::RenderArea2DShape() for (size_t i = 0; i < listNum; ++i) { Area2DPointList &pointList = m_Area2DShapePointList.front(); + bool bIsCCW = checkCCW(pointList); // is it counter clockwise (CCW) or clockwise (CW) + if(!bIsCCW) + glFrontFace(GL_CW); //fill vertex buffer glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); glBufferData(GL_ARRAY_BUFFER, pointList.size() * sizeof(float), &pointList[0], GL_STATIC_DRAW); @@ -1522,9 +1551,12 @@ int OpenGLRender::RenderArea2DShape() 0, // stride (void*)0 // array buffer offset ); + // TODO: moggi: remove deprecated GL_POLYGON glDrawArrays(GL_POLYGON, 0, pointList.size() / 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(m_2DVertexID); glUseProgram(0); + if(!bIsCCW) + glFrontFace(GL_CCW); m_Area2DShapePointList.pop_front(); } glEnable(GL_MULTISAMPLE); -- cgit