Commit aeffa662 authored by Sylvain Thery's avatar Sylvain Thery

utilisation des nouvelles classes de rendu et de Qt

parent 604a068c
...@@ -2,6 +2,9 @@ SET(EXECUTABLE_OUTPUT_PATH ${CGoGN_ROOT_DIR}/bin) ...@@ -2,6 +2,9 @@ SET(EXECUTABLE_OUTPUT_PATH ${CGoGN_ROOT_DIR}/bin)
SET (COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} gzstream AntTweakBar openctm assimp) SET (COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} gzstream AntTweakBar openctm assimp)
SET(CGoGN_LIBS_D topologyD algoD containerD utilsD)
SET(CGoGN_LIBS_R topology algo container utils)
IF(WIN32) IF(WIN32)
add_subdirectory(Examples/Release) add_subdirectory(Examples/Release)
add_subdirectory(Tuto) add_subdirectory(Tuto)
......
...@@ -5,8 +5,16 @@ project(examples) ...@@ -5,8 +5,16 @@ project(examples)
SET(CMAKE_BUILD_TYPE Release) SET(CMAKE_BUILD_TYPE Release)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING")
# FOR Qt4
FIND_PACKAGE(Qt4 REQUIRED)
SET(QT_USE_QTOPENGL TRUE)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
# define includes path # define includes path
include_directories( include_directories(
${CMAKE_CURRENT_BINARY_DIR}
/usr/include/libxml2/ /usr/include/libxml2/
${CGoGN_ROOT_DIR}/include ${CGoGN_ROOT_DIR}/include
${CGoGN_ROOT_DIR}/ThirdParty/Numerical ${CGoGN_ROOT_DIR}/ThirdParty/Numerical
...@@ -58,13 +66,15 @@ add_executable( ter_meshes ../ter_meshes.cpp) ...@@ -58,13 +66,15 @@ add_executable( ter_meshes ../ter_meshes.cpp)
target_link_libraries( ter_meshes target_link_libraries( ter_meshes
container topology utils algo ${COMMON_LIBS} ) container topology utils algo ${COMMON_LIBS} )
add_executable( polyhedronsView ../polyhedronsView.cpp) QT4_WRAP_CPP(polyhedronsView_moc ../polyhedronsView.h)
add_executable( polyhedronsView ../polyhedronsView.cpp ${polyhedronsView_moc})
target_link_libraries( polyhedronsView target_link_libraries( polyhedronsView
container topology utils algo ${COMMON_LIBS} ) ${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} )
add_executable( extrusionView ../extrusionView.cpp) QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h)
add_executable( extrusionView ../extrusionView.cpp ${extrusionView_moc})
target_link_libraries( extrusionView target_link_libraries( extrusionView
container topology utils algo ${COMMON_LIBS} ) ${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} )
add_executable( scene ../scene.cpp) add_executable( scene ../scene.cpp)
target_link_libraries( scene target_link_libraries( scene
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <iostream> #include <iostream>
#include "Utils/glutwin.h" #include "extrusionView.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Topology/map/map2.h" #include "Topology/map/map2.h"
...@@ -33,12 +33,15 @@ ...@@ -33,12 +33,15 @@
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Geometry/matrix.h" #include "Geometry/matrix.h"
#include "Geometry/transfo.h" #include "Geometry/transfo.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/vbo_MapRender.h" #include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/extrusion.h" #include "Algo/Modelisation/extrusion.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/shaderFlat.h"
#include "Utils/shaderSimpleColor.h"
#include <vector> #include <vector>
using namespace CGoGN; using namespace CGoGN;
...@@ -55,147 +58,58 @@ struct PFP: public PFP_STANDARD ...@@ -55,147 +58,58 @@ struct PFP: public PFP_STANDARD
PFP::MAP myMap; PFP::MAP myMap;
class myGlutWin: public Utils::SimpleGlutWin void MyQT::cb_initGL()
{ {
public: // choose to use GL version 2
/** Utils::GLSLShader::setCurrentOGLVersion(2);
* position of object
*/
Geom::Vec3f gPosObj;
/**
* width of object
*/
float gWidthObj;
/**
* redraw CB
*/
void myRedraw();
/** // create the render
* keyboard CB m_render = new Algo::Render::GL2::MapRender();
*/
void myKeyboard(unsigned char keycode, int x, int y);
/** // create VBO for position
* Update VBO buffers for map m_positionVBO = new Utils::VBO();
*/
void updateRender();
/**
* GL initialization
*/
void init();
// position handler m_shader = new Utils::ShaderFlat();
PFP::TVEC3 position ; m_shader->setAttributePosition(m_positionVBO);
m_shader->setDiffuse(Geom::Vec4f(0.,1.,0.,0.));
// using simple shader with color
m_shader2 = new Utils::ShaderSimpleColor();
m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setColor(Geom::Vec4f(1.,1.,0.,0.));
/**
* render object
*/
Algo::Render::GL2::MapRender_VBO* m_render;
myGlutWin( int* argc, char **argv, int winX, int winY) :
SimpleGlutWin(argc,argv,winX,winY),
m_render(NULL)
{ }
~myGlutWin();
};
myGlutWin::~myGlutWin() registerRunning(m_shader);
{ registerRunning(m_shader2);
if (m_render)
delete m_render;
} }
void myGlutWin::init()
{
glClearColor(0.1f,0.1f,0.1f,0.0f);
glEnable(GL_DEPTH_TEST);
// glEnable(GL_NORMALIZE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glEnable(GL_LIGHT0);
}
void MyQT::cb_redraw()
void myGlutWin::updateRender()
{ {
SelectorTrue allDarts; glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
// create the renderer (first call only)
if (m_render == NULL)
m_render = new Algo::Render::GL2::MapRender_VBO() ;
// update buffer op vertices positions
m_render->updateData(Algo::Render::GL2::POSITIONS, position);
// update flat faces primtives (warning need position buffer)
m_render->initPrimitives<PFP>(myMap, SelectorTrue(), Algo::Render::GL2::FLAT_TRIANGLES);
// update lines primitives
m_render->initPrimitives<PFP>(myMap, SelectorTrue(), Algo::Render::GL2::LINES);
}
void myGlutWin::myRedraw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
// center the scene
float sc = 50./gWidthObj;
glScalef(sc,sc,sc);
glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);
// DRAW LINES OF OBJECTS m_render->draw(m_shader2, Algo::Render::GL2::LINES);
glDisable(GL_LIGHTING);
glColor3f(1.0f,1.0f,0.0f);
m_render->draw(Algo::Render::GL2::LINES) ;
//shit for nice line rendering
glEnable( GL_POLYGON_OFFSET_FILL ); glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 1.0f, 1.0f ); glPolygonOffset( 1.0f, 1.0f );
// DRAW FACES OF OBJECTS m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
glColor3f(0.0f,0.0f,0.9f);
m_render->draw(Algo::Render::GL2::FLAT_TRIANGLES) ;
glDisable( GL_POLYGON_OFFSET_FILL );
glPopMatrix(); glDisable(GL_POLYGON_OFFSET_FILL);
} }
void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
{
switch(keycode)
{
case 27:
exit(0);
default:
break;
}
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
/// init glut interface and // interface:
myGlutWin mgw(&argc,argv,800,800); QApplication app(argc, argv);
mgw.init(); MyQT sqt;
mgw.position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ; PFP::TVEC3 position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ;
// define the face extruded (here a cross) // define the face extruded (here a cross)
std::vector<PFP::VEC3> objV; std::vector<PFP::VEC3> objV;
...@@ -225,18 +139,31 @@ int main(int argc, char **argv) ...@@ -225,18 +139,31 @@ int main(int argc, char **argv)
} }
// extrusion // extrusion
Dart d = Algo::Modelisation::extrusion_scale<PFP>(myMap, mgw.position, objV, PFP::VEC3(0.0,0.0,0.0), PFP::VEC3(0.0,1.0,0.0),true, pathV, false, pathRadius); Dart d = Algo::Modelisation::extrusion_scale<PFP>(myMap, position, objV, PFP::VEC3(0.0,0.0,0.0), PFP::VEC3(0.0,1.0,0.0),true, pathV, false, pathRadius);
// update renderer // bounding box
mgw.updateRender(); Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
// envoit info BB a l'interface
sqt.setParamObject(lWidthObj,lPosObj.data());
// show 1 pour GL context
sqt.show();
// update du VBO position (context GL necessaire)
sqt.m_positionVBO->updateData(position);
// update des primitives du renderer
SelectorTrue allDarts;
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
// compute BB and store it for object positionning in screen // show final pour premier redraw
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap,mgw.position) ; sqt.show();
mgw.gWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
mgw.gPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
mgw.mainLoop(); // et on attend la fin.
return app.exec();
return 0;
} }
/*******************************************************************************
* 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 EXTRUSIONVIEW_H_
#define EXTRUSIONVIEW_H_
#include <iostream>
#include "Utils/qtSimple.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}}
namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { class ShaderFlat; } }
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
using namespace CGoGN ;
/**
* A class for a little interface and rendering
*/
class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
// render
Algo::Render::GL2::MapRender* m_render;
// VBO
Utils::VBO* m_positionVBO;
//2 shaders
Utils::ShaderFlat* m_shader;
Utils::ShaderSimpleColor* m_shader2;
MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL), m_shader2(NULL){}
// callbacks of simpleQT to overdefine:
void cb_redraw();
void cb_initGL();
};
#endif
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <iostream> #include <iostream>
#include "Utils/glutwin.h" #include "polyhedronsView.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Topology/map/map2.h" #include "Topology/map/map2.h"
...@@ -35,10 +35,13 @@ ...@@ -35,10 +35,13 @@
#include "Geometry/transfo.h" #include "Geometry/transfo.h"
#include "Algo/Geometry/boundingbox.h" #include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/vbo_MapRender.h"
#include "Algo/Modelisation/polyhedron.h" #include "Algo/Modelisation/polyhedron.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/shaderFlat.h"
#include "Utils/shaderSimpleColor.h"
using namespace CGoGN; using namespace CGoGN;
...@@ -53,156 +56,66 @@ struct PFP: public PFP_STANDARD ...@@ -53,156 +56,66 @@ struct PFP: public PFP_STANDARD
PFP::MAP myMap; PFP::MAP myMap;
class myGlutWin: public Utils::SimpleGlutWin void MyQT::cb_initGL()
{
public:
/**
* position of object
*/
Geom::Vec3f gPosObj;
/**
* width of object
*/
float gWidthObj;
/**
* redraw CB
*/
void myRedraw();
/**
* keyboard CB
*/
void myKeyboard(unsigned char keycode, int x, int y);
/**
* Update VBO buffers for map
*/
void updateRender();
/**
* GL initialization
*/
void init();
// position handler
PFP::TVEC3 position ;
/**
* render object
*/
Algo::Render::GL2::MapRender_VBO* m_render;
myGlutWin( int* argc, char **argv, int winX, int winY) :
SimpleGlutWin(argc,argv,winX,winY),
m_render(NULL)
{ }
~myGlutWin();
};
myGlutWin::~myGlutWin()
{
if (m_render)
delete m_render;
}
void myGlutWin::init()
{ {
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
glClearColor(0.1f,0.1f,0.1f,0.0f); // create the render
glEnable(GL_DEPTH_TEST); m_render = new Algo::Render::GL2::MapRender();
glEnable(GL_NORMALIZE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // create VBO for position
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); m_positionVBO = new Utils::VBO();
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glEnable(GL_LIGHT0);
}
void myGlutWin::updateRender() m_shader = new Utils::ShaderFlat();
{ m_shader->setAttributePosition(m_positionVBO);
SelectorTrue allDarts; m_shader->setDiffuse(Geom::Vec4f(0.,1.,0.,0.));
// create the renderer (first call only) // using simple shader with color
if (m_render == NULL) m_shader2 = new Utils::ShaderSimpleColor();
m_render = new Algo::Render::GL2::MapRender_VBO() ; m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setColor(Geom::Vec4f(1.,1.,0.,0.));
// update buffer op vertices positions
m_render->updateData(Algo::Render::GL2::POSITIONS, position);
// update flat faces primtives (warning need position buffer)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::FLAT_TRIANGLES);
// update lines primitives
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
registerRunning(m_shader);
registerRunning(m_shader2);
} }
void myGlutWin::myRedraw(void) void MyQT::cb_redraw()
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glPushMatrix(); glEnable(GL_LIGHTING);
// center the scene
float sc = 50./gWidthObj;
glScalef(sc,sc,sc);
glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);
// DRAW LINES OF OBJECTS m_render->draw(m_shader2, Algo::Render::GL2::LINES);
glDisable(GL_LIGHTING);
glColor3f(1.0f,1.0f,0.0f);
m_render->draw(Algo::Render::GL2::LINES) ;
//shit for nice line rendering
glEnable( GL_POLYGON_OFFSET_FILL ); glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 1.0f, 1.0f ); glPolygonOffset( 1.0f, 1.0f );
// DRAW FACES OF OBJECTS m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
glColor3f(0.0f,0.0f,0.9f);