Commit 9b8dfec0 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'fixCoreRulerPlugin' into 'master'

Fix core ruler plugin

Closes OpenFlipper-Free#152

See merge request !107
parents 5a097073 1119c1ea
......@@ -232,6 +232,11 @@ void
LineNode::
draw(GLState& _state , const DrawModes::DrawMode& _drawMode)
{
if(_state.compatibilityProfile())
drawCompat(_state, _drawMode);
else
{
/* //Node Based Drawing is not supported on Core profiles
if (_drawMode & DrawModes::WIREFRAME)
{
ACG::GLState::disable(GL_LIGHTING);
......@@ -343,6 +348,7 @@ draw(GLState& _state , const DrawModes::DrawMode& _drawMode)
}
//glEnd();
}*/
}
}
......@@ -364,13 +370,15 @@ leave(GLState& _state , const DrawModes::DrawMode& _drawMode)
void LineNode::pick(GLState& _state , PickTarget _target)
{
if(_state.compatibilityProfile())
pickCompat(_state, _target);
else
{
if (n_points() == 0)
return;
// Bind the vertex array
ACG::GLState::bindBuffer(GL_ARRAY_BUFFER_ARB, 0);
ACG::GLState::vertexPointer( &(points_)[0] );
ACG::GLState::enableClientState(GL_VERTEX_ARRAY);
const size_t n_edges = n_points() - 1;
......@@ -393,53 +401,14 @@ void LineNode::pick(GLState& _state , PickTarget _target)
default:
break;
}
//Disable the vertex array
ACG::GLState::disableClientState(GL_VERTEX_ARRAY);
}
}
//----------------------------------------------------------------------------
void LineNode::pick_edges(GLState& _state, unsigned int _offset)
{
// Check if we have any edges to draw (% 0 causes division by zero on windows)
if (n_points() < 2)
return;
const float line_width_old = _state.line_width();
_state.set_line_width(picking_line_width());
_state.pick_set_name (0);
glDepthRange(0.0, 0.99);
if (line_mode_ == PolygonMode)
{
const size_t n_edges = n_points() - 1;
for (size_t i = 0; i < n_edges; ++i)
{
_state.pick_set_name(i + _offset);
glBegin(GL_LINES);
glArrayElement(static_cast<GLint>(i));
glArrayElement(static_cast<GLint>(i + 1));
glEnd();
}
}
else if (line_mode_ == LineSegmentsMode)
{
const size_t n_edges = n_points() / 2;
for (size_t i = 0; i < n_edges; ++i)
{
_state.pick_set_name(i + _offset);
glBegin(GL_LINES);
glArrayElement(static_cast<GLint>(2*i));
glArrayElement(static_cast<GLint>(2*i + 1));
glEnd();
}
}
glDepthRange(0.0, 1.0);
_state.set_line_width(line_width_old);
//TODO: implement edge picking for lines in CoreProfile
}
//----------------------------------------------------------------------------
......
......@@ -136,12 +136,14 @@ public:
/// draw lines and normals
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
void drawCompat(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// reset depth function to what it was before enter()
void leave(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// Draw the line using the GL picking name stack
void pick(GLState& _state , PickTarget _target);
void pickCompat(GLState& _state , PickTarget _target);
/// reserve mem for _n lines
void reserve_lines(unsigned int _n) { points_.reserve(2*_n); }
......@@ -222,6 +224,7 @@ protected:
void pick_vertices(GLState& _state);
void pick_edges (GLState& _state, unsigned int _offset);
void pick_edgesCompat (GLState& _state, unsigned int _offset);
/// creates the vbo only if update was requested
void createVBO();
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS LineNode - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <ACG/GL/acg_glew.hh>
#include "LineNode.hh"
#include <ACG/GL/IRenderer.hh>
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
void
LineNode::
drawCompat(GLState& _state , const DrawModes::DrawMode& _drawMode)
{
if (_drawMode & DrawModes::WIREFRAME)
{
ACG::GLState::disable(GL_LIGHTING);
// if (line_mode_ == LineSegmentsMode)
// glBegin(GL_LINES);
// else
// glBegin(GL_LINE_STRIP);
if (line_mode_ == LineSegmentsMode)
{
// first check if (new standard) 4-channel colors are specified
if( (points_.size()/2 == colors4f_.size()) )
{
// enable blending of lines
GLboolean blendb;
glGetBooleanv( GL_BLEND, &blendb);
glEnable(GL_BLEND);
// blend ontop of prev. drawn mesh
GLboolean depthmaskb;
glGetBooleanv( GL_DEPTH_WRITEMASK, &depthmaskb);
glDepthMask(GL_FALSE);
glBegin(GL_LINES);
ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColor4fIter c_it=colors4f_.begin();
Color4f c(1.0f,1.0f,1.0f,1.0f);
if(c_it != colors4f_.end()) {
c = *c_it;
}
int cnt = 0;
for (; p_it!=p_end; ++p_it)
{
if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors4f_.end()) {
++c_it;
c = *c_it;
}
glColor(c);
glVertex(*p_it);
++cnt;
}
glEnd();
// disable blending of lines
if( blendb == GL_FALSE )
glDisable(GL_BLEND);
// enable depth mask
if( depthmaskb == GL_TRUE )
glDepthMask(GL_TRUE);
}
else if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors_.size()) )
{
glBegin(GL_LINES);
ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColorIter c_it=colors_.begin();
Color c((char)255, (char)255, (char)255);
if(c_it != colors_.end()) {
c = *c_it;
}
int cnt = 0;
for (; p_it!=p_end; ++p_it)
{
if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors_.end()) {
++c_it;
c = *c_it;
}
glColor(c);
glVertex(*p_it);
++cnt;
}
glEnd();
}
else
{
glBegin(GL_LINES);
ConstPointIter p_it=points_.begin(), p_end=points_.end();
for (; p_it!=p_end; ++p_it)
{
glVertex(*p_it);
}
glEnd();
}
}
else
{
_state.set_color(_state.base_color());
glBegin(GL_LINE_STRIP);
ConstPointIter p_it=points_.begin(), p_end=points_.end();
for (; p_it!=p_end; ++p_it)
glVertex(*p_it);
glEnd();
}
//glEnd();
}
}
//----------------------------------------------------------------------------
void LineNode::pickCompat(GLState& _state , PickTarget _target)
{
if (n_points() == 0)
return;
// Bind the vertex array
ACG::GLState::bindBuffer(GL_ARRAY_BUFFER_ARB, 0);
ACG::GLState::vertexPointer( &(points_)[0] );
ACG::GLState::enableClientState(GL_VERTEX_ARRAY);
const size_t n_edges = n_points() - 1;
switch (_target)
{
case PICK_EDGE:
{
_state.pick_set_maximum (n_edges);
pick_edgesCompat(_state, 0);
break;
}
case PICK_ANYTHING:
{
_state.pick_set_maximum (n_edges);
pick_edgesCompat(_state, 0);
break;
}
default:
break;
}
//Disable the vertex array
ACG::GLState::disableClientState(GL_VERTEX_ARRAY);
}
//----------------------------------------------------------------------------
void LineNode::pick_edgesCompat(GLState& _state, unsigned int _offset)
{
// Check if we have any edges to draw (% 0 causes division by zero on windows)
if (n_points() < 2)
return;
const float line_width_old = _state.line_width();
_state.set_line_width(picking_line_width());
_state.pick_set_name (0);
glDepthRange(0.0, 0.99);
if (line_mode_ == PolygonMode)
{
const size_t n_edges = n_points() - 1;
for (size_t i = 0; i < n_edges; ++i)
{
_state.pick_set_name(i + _offset);
glBegin(GL_LINES);
glArrayElement(static_cast<GLint>(i));
glArrayElement(static_cast<GLint>(i + 1));
glEnd();
}
}
else if (line_mode_ == LineSegmentsMode)
{
const size_t n_edges = n_points() / 2;
for (size_t i = 0; i < n_edges; ++i)
{
_state.pick_set_name(i + _offset);
glBegin(GL_LINES);
glArrayElement(static_cast<GLint>(2*i));
glArrayElement(static_cast<GLint>(2*i + 1));
glEnd();
}
}
glDepthRange(0.0, 1.0);
_state.set_line_width(line_width_old);
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
......@@ -246,31 +246,29 @@ createMap() {
void
TextNode::
enter(GLState& _state, const DrawModes::DrawMode& /*_drawmode*/) {
enter(GLState& _state, const DrawModes::DrawMode& _drawmode) {
if(_state.compatibilityProfile())
enterCompat(_state,_drawmode);
else
{
if (text_.empty())
return;
// store current gl state
cullFaceEnabled_ = glIsEnabled(GL_CULL_FACE);
texture2dEnabled_ = glIsEnabled(GL_TEXTURE_2D);
blendEnabled_ = glIsEnabled(GL_BLEND);
depthEnabled_ = glIsEnabled(GL_DEPTH_TEST);
alphaTest_ = glIsEnabled(GL_ALPHA_TEST);
if (alphaTest_)
ACG::GLState::getAlphaFunc(&alphaTestFunc_, &alphaTestValue_);
glGetIntegerv(GL_BLEND_SRC, &blendSrc_);
glGetIntegerv(GL_BLEND_DST, &blendDest_);
// set texture and drawing states
ACG::GLState::disable(GL_CULL_FACE);
ACG::GLState::enable(GL_TEXTURE_2D);
ACG::GLState::enable(GL_BLEND);
ACG::GLState::enable(GL_ALPHA_TEST);
ACG::GLState::alphaFunc(GL_GREATER, 0.2f);
ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (alwaysOnTop_)
ACG::GLState::disable(GL_DEPTH_TEST);
}
}
......@@ -280,27 +278,26 @@ enter(GLState& _state, const DrawModes::DrawMode& /*_drawmode*/) {
void
TextNode::
leave(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) {
leave(GLState& _state, const DrawModes::DrawMode& _drawmode) {
if(_state.compatibilityProfile())
leaveCompat(_state, _drawmode);
else
{
if (text_.empty())
return;
// restore the GLState as it was when entering TextNode
if (cullFaceEnabled_)
ACG::GLState::enable(GL_CULL_FACE);
if (!texture2dEnabled_)
ACG::GLState::disable(GL_TEXTURE_2D);
ACG::GLState::enable(GL_CULL_FACE);
if (!blendEnabled_)
ACG::GLState::disable(GL_BLEND);
if (depthEnabled_)
ACG::GLState::enable(GL_DEPTH_TEST);
else
ACG::GLState::disable(GL_DEPTH_TEST);
if (!alphaTest_)
ACG::GLState::disable(GL_ALPHA_TEST);
else
ACG::GLState::alphaFunc(alphaTestFunc_, alphaTestValue_);
ACG::GLState::disable(GL_DEPTH_TEST);
ACG::GLState::blendFunc(blendSrc_, blendDest_);
}
}
......@@ -322,7 +319,7 @@ draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
_state.push_modelview_matrix();
_state.scale(size_);
glDrawArrays(GL_QUADS, 0, int(text_.size() * 4) );
glDrawArrays(GL_TRIANGLES, 0, int(text_.size() * 6) );
_state.pop_modelview_matrix();
if (textMode_ == SCREEN_ALIGNED || textMode_ == SCREEN_ALIGNED_STATIC_SIZE) {
......@@ -500,6 +497,24 @@ updateVBO() {
vertexBuffer_.push_back(avgWidth*0.15);
vertexBuffer_.push_back(0.0f);
// texture coordinates
vertexBuffer_.push_back(rightTx);
vertexBuffer_.push_back(topTx);
// bottom left
vertexBuffer_.push_back(left);
vertexBuffer_.push_back(0.0f);
vertexBuffer_.push_back(0.0f);
// texture coordinates
vertexBuffer_.push_back(leftTx);
vertexBuffer_.push_back(bottomTx);
// top right
vertexBuffer_.push_back(right);
vertexBuffer_.push_back(avgWidth*0.15);
vertexBuffer_.push_back(0.0f);
// texture coordinates
vertexBuffer_.push_back(rightTx);
vertexBuffer_.push_back(topTx);
......@@ -626,7 +641,7 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
localMaterial.specularColor(ACG::Vec4f(0.0, 0.0, 0.0, 0.0 ));
ro.setMaterial(&localMaterial);
ro.glDrawArrays(GL_QUADS, 0, static_cast<GLsizei>(text_.size()) * 4);
ro.glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(text_.size()) * 6);
_renderer->addRenderObject(&ro);
}
......
......@@ -131,9 +131,11 @@ public:
/// set texture and drawing states
void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
void enterCompat(GLState& _state, const DrawModes::DrawMode& _drawmode);
/// restore texture and drawing states
void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
void leaveCompat(GLState& _state, const DrawModes::DrawMode& _drawmode);
/// set RenderObject for Shader pipeline renderer
void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS TextNode - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <ACG/GL/acg_glew.hh>
#include "TextNode.hh"
#include "../Utils/ImageConversion.hh"
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
void
TextNode::
enterCompat(GLState& _state, const DrawModes::DrawMode& /*_drawmode*/) {
if (text_.empty())
return;
// store current gl state
cullFaceEnabled_ = glIsEnabled(GL_CULL_FACE);
texture2dEnabled_ = glIsEnabled(GL_TEXTURE_2D);
blendEnabled_ = glIsEnabled(GL_BLEND);
depthEnabled_ = glIsEnabled(GL_DEPTH_TEST);
//alphaTest_ = glIsEnabled(GL_ALPHA_TEST);
if (alphaTest_)
ACG::GLState::getAlphaFunc(&alphaTestFunc_, &alphaTestValue_);
glGetIntegerv(GL_BLEND_SRC, &blendSrc_);
glGetIntegerv(GL_BLEND_DST, &blendDest_);
// set texture and drawing states
ACG::GLState::disable(GL_CULL_FACE);
ACG::GLState::enable(GL_TEXTURE_2D);
ACG::GLState::enable(GL_BLEND);
ACG::GLState::enable(GL_ALPHA_TEST);
ACG::GLState::alphaFunc(GL_GREATER, 0.2f);
ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (alwaysOnTop_)
ACG::GLState::disable(GL_DEPTH_TEST);
}
//----------------------------------------------------------------------------
void
TextNode::
leaveCompat(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) {
if (text_.empty())
return;
// restore the GLState as it was when entering TextNode
if (cullFaceEnabled_)
ACG::GLState::enable(GL_CULL_FACE);
if (!texture2dEnabled_)
ACG::GLState::disable(GL_TEXTURE_2D);
if (!blendEnabled_)
ACG::GLState::disable(GL_BLEND);
if (depthEnabled_)
ACG::GLState::enable(GL_DEPTH_TEST);
else
ACG::GLState::disable(GL_DEPTH_TEST);
if (!alphaTest_)
ACG::GLState::disable(GL_ALPHA_TEST);
else
ACG::GLState::alphaFunc(alphaTestFunc_, alphaTestValue_);
ACG::GLState::blendFunc(blendSrc_, blendDest_);
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment