Commit f22dfb72 authored by Sylvain Thery's avatar Sylvain Thery

ajout classe Drawer pour affichage de debug a l'ancienne.

update de tp_master
parent aeffa662
......@@ -47,6 +47,8 @@
#include "Utils/shaderSimpleColor.h"
#include "Utils/shaderPhong.h"
#include "Utils/drawer.h"
/// pour simplifier l'ecriture du code
using namespace CGoGN;
......@@ -225,65 +227,69 @@ std::vector<Dart> d_vertices;
void MyQT::drawSelected()
{
/*
typedef Dart Dart;
// FACES
glLineWidth(5.0f);
m_ds->newList(GL_COMPILE_AND_EXECUTE);
m_ds->lineWidth(5.0f);
for(unsigned int i=0; i < d_faces.size(); ++i)
{
m_ds->begin(GL_POLYGON);
// fait varier la couleur du plus pres au plus loin
float c = float (i) / float (d_faces.size());
m_ds->color3f(1.0f - c , 0.0f, c);
glBegin(GL_LINE_LOOP);
glColor3f(1.0f - c , c ,0.);
Dart d = d_faces[i];
do
{
const PFP::VEC3& P = position[d];
glVertex3fv(P.data());
m_ds->vertex(P);
d = myMap.phi1(d);
} while (d!=d_faces[i]);
glEnd();
m_ds->end();
}
//edges
glLineWidth(7.0f);
glBegin(GL_LINES);
//edges
m_ds->begin(GL_LINES);
m_ds->lineWidth(5.0f);
for(unsigned int i=0; i < d_edges.size(); ++i)
{
// fait varier la couleur du plus pres au plus loin
float c = float (i) / float (d_edges.size());
glColor3f(1.0f - c , c ,0.);
m_ds->color3f(1.0f - c , c ,0.);
Dart d = d_edges[i];
const PFP::VEC3& P = position[d];
glVertex3fv(P.data());
m_ds->vertex(P);
d = myMap.phi1(d);
const PFP::VEC3& Q = position[d];
glVertex3fv(Q.data());
m_ds->vertex(Q);
}
glEnd();
m_ds->end();
//VERTICES
//edges
glPointSize(9.0f);
glBegin(GL_POINTS);
m_ds->pointSize(9.0f);
m_ds->begin(GL_POINTS);
for(unsigned int i=0; i < d_vertices.size(); ++i)
{
// fait varier la couleur du plus pres au plus loin
float c = float (i) / float (d_vertices.size());
glColor3f(1.0f - c , c ,0.);
m_ds->color3f(1.0f - c , 0., c);
Dart d = d_vertices[i];
const PFP::VEC3& P = position[d];
glVertex3fv(P.data());
m_ds->vertex(P);
}
glEnd();
m_ds->end();
m_ds->endList();
glLineWidth(7.0f);
*/
for(unsigned int i=0; i < selected_darts.size(); ++i)
{
// fait varier la couleur du plus pres au plus loin
......@@ -325,6 +331,8 @@ void MyQT::cb_initGL()
m_render = new Algo::Render::GL2::MapRender();
m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ;
m_ds = new Utils::Drawer();
// create VBO for position
m_positionVBO = new Utils::VBO();
m_normalVBO = new Utils::VBO();
......@@ -333,8 +341,7 @@ void MyQT::cb_initGL()
m_shader->setAttributePosition(m_positionVBO);
m_shader->setAttributeNormal(m_normalVBO);
m_shader->setDiffuse(Geom::Vec4f(0.,0.6,0.,0.));
// m_shader->setShininess(10000.0);
m_shader->setSpecular(Geom::Vec4f(0.,0.0,0.,0.));
m_shader->setSpecular(Geom::Vec4f(0.,0.0,0.,0.)); // no specular
// using simple shader with color
m_shader2 = new Utils::ShaderSimpleColor();
......@@ -351,20 +358,23 @@ void MyQT::cb_redraw()
{
drawSelected();
if (renderTopo)
{
glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 0.2f, 0.2f );
glPolygonOffset( 1.0f, 1.0f );
m_render_topo->drawTopo();
}
/// decalage pour surlignage non clignotant
glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 1.0f, 1.0f );
glPolygonOffset( 1.5f, 1.5f );
glPolygonOffset( 2.0f, 2.0f );
glLineWidth(1.0f);
m_render->draw(m_shader2,Algo::Render::GL2::LINES) ;
/// Rendu faces pleines
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
......@@ -378,6 +388,8 @@ void MyQT::cb_redraw()
void MyQT::cb_keyPress(int keycode)
{
typedef Dart Dart;
int x,y;
glMousePosition(x,y);
std::cout << x << " , "<< y << std::endl;
......@@ -470,6 +482,7 @@ void MyQT::cb_keyPress(int keycode)
std::stringstream ss;
ss << "Face " << d_faces[0].index/3;
statusMsg(ss.str().c_str());
updateGL();
}
break;
}
......@@ -494,6 +507,7 @@ void MyQT::cb_keyPress(int keycode)
if (dd != d_edges[0])
ss << std::endl<< " phi2: " << dd.index<<" phi1: "<< myMap.phi1(dd).index;
statusMsg(ss.str().c_str());
updateGL();
}
break;
......@@ -516,6 +530,8 @@ void MyQT::cb_keyPress(int keycode)
std::stringstream ss;
ss << "Sommet: dart: " << d_vertices[0].index << ": " << position[d_vertices[0]];
statusMsg(ss.str().c_str());
updateGL();
}
break;
......
......@@ -37,6 +37,7 @@ namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class Topo
namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { class ShaderPhong; } }
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
namespace CGoGN { namespace Utils { class Drawer; } }
using namespace CGoGN ;
......@@ -66,6 +67,11 @@ public:
bool renderTopo;
/**
* object that allow easy rendering
*/
Utils::Drawer* m_ds;
MyQT():
m_render(NULL), m_render_topo(NULL),
m_positionVBO(NULL), m_normalVBO(NULL),
......
......@@ -32,10 +32,12 @@
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/shaderSimpleColor.h"
#include "tuto2.h"
#include "Utils/drawer.h"
#include "tuto2.h"
Utils::DrawerSimple* ds;
using namespace CGoGN ;
......@@ -78,6 +80,8 @@ void MyQT::cb_initGL()
m_with_lines=true;
m_line_width=4.0;
ds = new Utils::DrawerSimple();
}
......@@ -92,6 +96,21 @@ void MyQT::cb_redraw()
glLineWidth(m_line_width);
m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
glPointSize(5.0f);
float c = 0.0f;
ds->globalColor(Geom::Vec4f(1.0f , 0.0 ,0.,0.));
ds->begin(GL_POINTS);
ds->vertex(Geom::Vec3f(-1,-1,0));
ds->vertex(Geom::Vec3f(-1,4,0));
ds->vertex(Geom::Vec3f(4,4,0));
ds->vertex(Geom::Vec3f(4,-1,0));
ds->end();
ds->draw();
}
glEnable(GL_POLYGON_OFFSET_FILL);
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _CGOGN_DRAWER_H_
#define _CGOGN_DRAWER_H_
#include <vector>
#include <GL/glew.h>
#include "Geometry/vector_gen.h"
namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { class ShaderColorPerVertex; } }
namespace CGoGN
{
namespace Utils
{
/**
* A class that allow easy drawing, allmost as easy as
* display lists in old school OpenGL 1.1
* Allow only position and color
* Drawing (callList) efficient after data has been finalized (endList)
*
*/
class Drawer
{
struct PrimParam
{
unsigned int begin;
GLenum mode;
float width;
unsigned int nb;
PrimParam(unsigned int b, GLenum m, float w): begin(b),mode(m),width(w),nb(0) {}
};
protected:
Utils::VBO* m_vboPos;
Utils::VBO* m_vboCol;
std::vector<Geom::Vec3f> m_dataPos;
std::vector<Geom::Vec3f> m_dataCol;
std::vector<PrimParam> m_begins;
float m_currentWidth;
GLenum m_compile;
Utils::ShaderColorPerVertex* m_shader;
public:
/**
* constructor, init all buffers (data and OpenGL) and shader
* @Warning need OpenGL context
*/
Drawer();
/**
* release buffers and shader
*/
~Drawer();
/**
* init the data structure
* @param com say if compile only, or compile and execute (GL_COMPILE/ GL_COMPILE_AND_EXECUTE)
*/
void newList(GLenum comp=GL_COMPILE);
/**
* as glBegin, but need a newList call before
* @param mode: POINTS, LINES, LINE_LOOP, TRIANGLES, QUADS, POLYGON, etc..
*/
void begin(GLenum mode);
/**
* as glEnd
*/
void end();
/**
* finalize the data initialization
* drawn is done if newList called with GL_COMPILE_AND_EXECUTE
*/
void endList();
/**
* use as glVertex
*/
void vertex(const Geom::Vec3f& v);
/**
* use as glVertex
*/
void vertex3f(float x, float y, float z);
/**
* use as glColor
*/
void color(const Geom::Vec3f& col);
/**
* use as glColor3f
*/
void color3f(float r, float g, float b);
/**
* use as a glCallList
*/
void callList();
/**
* use as glLineWidth
*/
void lineWidth(float lw);
/**
* usr as glPointSize
*/
void pointSize(float ps);
};
}
}
#endif /* DRAWER_H_ */
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Utils/drawer.h"
#include "Utils/shaderColorPerVertex.h"
#include "Utils/vbo.h"
namespace CGoGN
{
namespace Utils
{
Drawer::Drawer():
m_currentWidth(1.0f)
{
m_vboPos = new Utils::VBO();
m_vboPos->setDataSize(3);
m_vboCol = new Utils::VBO();
m_vboCol->setDataSize(3);
m_shader = new Utils::ShaderColorPerVertex();
m_shader->setAttributePosition(m_vboPos);
m_shader->setAttributeColor(m_vboCol);
Utils::GLSLShader::registerRunning(m_shader);
m_dataPos.reserve(128);
m_dataCol.reserve(128);
m_begins.reserve(16);
// m_modes.reserve(16);
}
Drawer::~Drawer()
{
Utils::GLSLShader::unregisterRunning(m_shader);
delete m_shader;
delete m_vboPos;
delete m_vboCol;
}
void Drawer::lineWidth(float lw)
{
m_currentWidth=lw;
}
void Drawer::pointSize(float ps)
{
m_currentWidth = ps;
}
void Drawer::begin(GLenum mode)
{
m_begins.push_back(PrimParam(m_dataPos.size(),mode, m_currentWidth));
}
void Drawer::end()
{
m_begins.back().nb = m_dataPos.size() - m_begins.back().begin;
}
void Drawer::color(const Geom::Vec3f& col)
{
if (m_dataPos.size() == m_dataCol.size())
m_dataCol.push_back(col);
else
m_dataCol.back() = col;
}
void Drawer::color3f(float r, float g, float b)
{
color(Geom::Vec3f(r,g,b));
}
void Drawer::vertex(const Geom::Vec3f& v)
{
if (m_dataPos.size() == m_dataCol.size())
{
if (m_dataCol.empty())
m_dataCol.push_back(Geom::Vec3f(1.,1.,1.));
else
m_dataCol.push_back( m_dataCol.back());
}
m_dataPos.push_back(v);
}
void Drawer::vertex3f(float r, float g, float b)
{
vertex(Geom::Vec3f(r,g,b));
}
void Drawer::newList(GLenum comp)
{
m_compile = comp;
m_dataPos.clear();
m_dataCol.clear();
m_begins.clear();
}
void Drawer::endList()
{
unsigned int nbElts = m_dataPos.size();
m_vboPos->bind();
glBufferData(GL_ARRAY_BUFFER, nbElts*sizeof(Geom::Vec3f), &(m_dataPos[0]), GL_STREAM_DRAW);
m_vboCol->bind();
glBufferData(GL_ARRAY_BUFFER, nbElts*sizeof(Geom::Vec3f), &(m_dataCol[0]), GL_STREAM_DRAW);
// free memory
std::vector<Geom::Vec3f> tempo;
tempo.swap(m_dataPos);
std::vector<Geom::Vec3f> tempo2;
tempo2.swap(m_dataCol);
if (m_compile != GL_COMPILE)
callList();
}
void Drawer::callList()
{
if (m_begins.empty())
return;
//draw
m_shader->enableVertexAttribs();
for (std::vector<PrimParam>::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp)
{
if (pp->mode == GL_POINTS)
glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP))
glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb);
}
m_shader->disableVertexAttribs();
}
}
}
......@@ -236,7 +236,9 @@ void SimpleQT::cb_updateMatrix()
for (std::set< std::pair<void*, GLSLShader*> >::iterator it=GLSLShader::m_registredRunning.begin(); it!=GLSLShader::m_registredRunning.end(); ++it)
{
if ((it->first == NULL) || (it->first == this))
{
it->second->updateMatrices(m_projection_matrix, m_modelView_matrix);
}
}
}
......
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