diff --git a/Apps/CMakeLists.txt b/Apps/CMakeLists.txt index 49363caa2ad126cbc4eaa9b0005326ed348b52bc..af96e8c13ceb66213801bcceac5498009e5e0c3a 100644 --- a/Apps/CMakeLists.txt +++ b/Apps/CMakeLists.txt @@ -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(CGoGN_LIBS_D topologyD algoD containerD utilsD) +SET(CGoGN_LIBS_R topology algo container utils) + IF(WIN32) add_subdirectory(Examples/Release) add_subdirectory(Tuto) diff --git a/Apps/Examples/Release/CMakeLists.txt b/Apps/Examples/Release/CMakeLists.txt index 82730feb976b182ca93b3a55fd6ed3fb2c0e065f..d3a6a6fca261eeccdae9c131643048219e95f9d9 100644 --- a/Apps/Examples/Release/CMakeLists.txt +++ b/Apps/Examples/Release/CMakeLists.txt @@ -5,8 +5,16 @@ project(examples) SET(CMAKE_BUILD_TYPE Release) 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 include_directories( + ${CMAKE_CURRENT_BINARY_DIR} /usr/include/libxml2/ ${CGoGN_ROOT_DIR}/include ${CGoGN_ROOT_DIR}/ThirdParty/Numerical @@ -57,14 +65,16 @@ target_link_libraries( triangulation add_executable( ter_meshes ../ter_meshes.cpp) target_link_libraries( ter_meshes 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 - 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 - container topology utils algo ${COMMON_LIBS} ) + ${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} ) add_executable( scene ../scene.cpp) target_link_libraries( scene diff --git a/Apps/Examples/extrusionView.cpp b/Apps/Examples/extrusionView.cpp index 6a9d8ae513f346756f02c417fe155cd942329a5e..ec9fd161c46819bbd74dbd8e1ad8752f24197859 100644 --- a/Apps/Examples/extrusionView.cpp +++ b/Apps/Examples/extrusionView.cpp @@ -24,7 +24,7 @@ #include -#include "Utils/glutwin.h" +#include "extrusionView.h" #include "Topology/generic/parameters.h" #include "Topology/map/map2.h" @@ -33,12 +33,15 @@ #include "Geometry/vector_gen.h" #include "Geometry/matrix.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 "Topology/generic/parameters.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Utils/shaderFlat.h" +#include "Utils/shaderSimpleColor.h" + #include using namespace CGoGN; @@ -55,147 +58,58 @@ struct PFP: public PFP_STANDARD 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(); + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); - /** - * keyboard CB - */ - void myKeyboard(unsigned char keycode, int x, int y); + // create the render + m_render = new Algo::Render::GL2::MapRender(); - /** - * Update VBO buffers for map - */ - void updateRender(); + // create VBO for position + m_positionVBO = new Utils::VBO(); - /** - * GL initialization - */ - void init(); - // position handler - PFP::TVEC3 position ; + m_shader = new Utils::ShaderFlat(); + 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() -{ - if (m_render) - delete m_render; + registerRunning(m_shader); + registerRunning(m_shader2); } -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 myGlutWin::updateRender() +void MyQT::cb_redraw() { - SelectorTrue allDarts; - - // 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(myMap, SelectorTrue(), Algo::Render::GL2::FLAT_TRIANGLES); - // update lines primitives - m_render->initPrimitives(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]); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_LIGHTING); - // DRAW LINES OF OBJECTS - glDisable(GL_LIGHTING); - glColor3f(1.0f,1.0f,0.0f); - m_render->draw(Algo::Render::GL2::LINES) ; + m_render->draw(m_shader2, Algo::Render::GL2::LINES); - //shit for nice line rendering glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( 1.0f, 1.0f ); - // DRAW FACES OF OBJECTS - 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 ); + m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES); - 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) { - /// init glut interface and - myGlutWin mgw(&argc,argv,800,800); - mgw.init(); + // interface: + QApplication app(argc, argv); + MyQT sqt; - mgw.position = myMap.addAttribute(VERTEX_ORBIT, "position") ; + PFP::TVEC3 position = myMap.addAttribute(VERTEX_ORBIT, "position") ; // define the face extruded (here a cross) std::vector objV; @@ -225,18 +139,31 @@ int main(int argc, char **argv) } // extrusion - Dart d = Algo::Modelisation::extrusion_scale(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(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 - mgw.updateRender(); + // bounding box + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); + float lWidthObj = std::max(std::max(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(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); - // compute BB and store it for object positionning in screen - Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap,mgw.position) ; - mgw.gWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); - mgw.gPosObj = (bb.min() + bb.max()) / PFP::REAL(2); + // show final pour premier redraw + sqt.show(); - mgw.mainLoop(); + // et on attend la fin. + return app.exec(); - return 0; } diff --git a/Apps/Examples/extrusionView.h b/Apps/Examples/extrusionView.h new file mode 100644 index 0000000000000000000000000000000000000000..e0976d5d7d3531440a5e32482214b4c8eacddf4e --- /dev/null +++ b/Apps/Examples/extrusionView.h @@ -0,0 +1,68 @@ +/******************************************************************************* +* 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 + + +#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 + diff --git a/Apps/Examples/polyhedronsView.cpp b/Apps/Examples/polyhedronsView.cpp index 300bd3d9cc5410ffef284439f6d8c4d974978e9d..f5bf819dea08df075c21c6bad42e78f412bcd419 100644 --- a/Apps/Examples/polyhedronsView.cpp +++ b/Apps/Examples/polyhedronsView.cpp @@ -24,7 +24,7 @@ #include -#include "Utils/glutwin.h" +#include "polyhedronsView.h" #include "Topology/generic/parameters.h" #include "Topology/map/map2.h" @@ -35,10 +35,13 @@ #include "Geometry/transfo.h" #include "Algo/Geometry/boundingbox.h" -#include "Algo/Render/vbo_MapRender.h" #include "Algo/Modelisation/polyhedron.h" #include "Topology/generic/parameters.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Utils/shaderFlat.h" +#include "Utils/shaderSimpleColor.h" + using namespace CGoGN; @@ -53,156 +56,66 @@ struct PFP: public PFP_STANDARD PFP::MAP myMap; -class myGlutWin: public Utils::SimpleGlutWin -{ -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() +void MyQT::cb_initGL() { + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); - glClearColor(0.1f,0.1f,0.1f,0.0f); - glEnable(GL_DEPTH_TEST); - glEnable(GL_NORMALIZE); + // create the render + m_render = new Algo::Render::GL2::MapRender(); - 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); -} + // create VBO for position + m_positionVBO = new Utils::VBO(); -void myGlutWin::updateRender() -{ - SelectorTrue allDarts; + m_shader = new Utils::ShaderFlat(); + m_shader->setAttributePosition(m_positionVBO); + m_shader->setDiffuse(Geom::Vec4f(0.,1.,0.,0.)); - // create the renderer (first call only) - if (m_render == NULL) - m_render = new Algo::Render::GL2::MapRender_VBO() ; + // using simple shader with color + m_shader2 = new Utils::ShaderSimpleColor(); + 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(myMap, allDarts, Algo::Render::GL2::FLAT_TRIANGLES); - // update lines primitives - m_render->initPrimitives(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); - glPushMatrix(); - - // center the scene - float sc = 50./gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_LIGHTING); - // DRAW LINES OF OBJECTS - glDisable(GL_LIGHTING); - glColor3f(1.0f,1.0f,0.0f); - m_render->draw(Algo::Render::GL2::LINES) ; + m_render->draw(m_shader2, Algo::Render::GL2::LINES); - //shit for nice line rendering glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( 1.0f, 1.0f ); - // DRAW FACES OF OBJECTS - 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 ); + m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES); - 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) { - /// init glut interface and - myGlutWin mgw(&argc,argv,800,800); - mgw.init(); + // interface: + QApplication app(argc, argv); + MyQT sqt; - mgw.position = myMap.addAttribute(VERTEX_ORBIT, "position") ; + PFP::TVEC3 position = myMap.addAttribute(VERTEX_ORBIT, "position") ; // create a cylinder - Algo::Modelisation::Polyhedron prim1(myMap, mgw.position); + Algo::Modelisation::Polyhedron prim1(myMap, position); prim1.cylinder_topo(16,8, true, false); prim1.embedCylinder(30.0f, 10.0f, 70.0f); // create a sphere - Algo::Modelisation::Polyhedron prim2(myMap, mgw.position); + Algo::Modelisation::Polyhedron prim2(myMap, position); prim2.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder prim2.embedSphere(40.0f); @@ -214,7 +127,7 @@ int main(int argc, char **argv) prim2.transform(trf); // create a tore - Algo::Modelisation::Polyhedron prim3(myMap, mgw.position); + Algo::Modelisation::Polyhedron prim3(myMap, position); prim3.tore_topo(16, 12); prim3.embedTore(30.0f,10.0f); // transformation @@ -225,7 +138,7 @@ int main(int argc, char **argv) prim3.transform(trf); // create a subdivided cube - Algo::Modelisation::Polyhedron prim4(myMap, mgw.position); + Algo::Modelisation::Polyhedron prim4(myMap, position); prim4.cube_topo(4, 5, 6); prim4.embedCube(50.0f,50.0f, 50.0f); @@ -235,16 +148,32 @@ int main(int argc, char **argv) Geom::translate(270.0f,0.0,0.0,trf); prim4.transform(trf); - // update renderer - mgw.updateRender(); + // bounding box + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); + float lWidthObj = std::max(std::max(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(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + + // show final pour premier redraw + sqt.show(); - // compute BB and store it for object positionning in screen - Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap,mgw.position) ; - mgw.gWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); - mgw.gPosObj = (bb.min() + bb.max()) / PFP::REAL(2); + // et on attend la fin. + return app.exec(); - mgw.mainLoop(); return 0; } diff --git a/Apps/Examples/polyhedronsView.h b/Apps/Examples/polyhedronsView.h new file mode 100644 index 0000000000000000000000000000000000000000..fe0f6de07d72783fbcec7c9b76d3da05b0840220 --- /dev/null +++ b/Apps/Examples/polyhedronsView.h @@ -0,0 +1,67 @@ +/******************************************************************************* +* 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 POLYHEDRONSVIEW_H_ +#define POLYHEDRONSVIEW_H_ + +#include + + +#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 + diff --git a/Apps/Tuto/CMakeLists.txt b/Apps/Tuto/CMakeLists.txt index debba1ff18e19b4e83888e28f0c207def57364ff..839d45f19a9abfa9a969b94df11740a253e527a8 100644 --- a/Apps/Tuto/CMakeLists.txt +++ b/Apps/Tuto/CMakeLists.txt @@ -5,8 +5,8 @@ project(Tutos) #SET (COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} gzstream AntTweakBar openctm) -#SET (CMAKE_BUILD_TYPE Debug) -SET(CMAKE_BUILD_TYPE Release) +SET (CMAKE_BUILD_TYPE Debug) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING") @@ -28,51 +28,58 @@ include_directories( ${CGoGN_ROOT_DIR}/include ) + # define libs path -link_directories(${CGoGN_ROOT_DIR}/lib/Release) +link_directories(${CGoGN_ROOT_DIR}/lib/Release ${CGoGN_ROOT_DIR}/lib/Debug) #define exec to compile QT4_WRAP_CPP(tuto1_moc tuto1.h) add_executable( tuto1 tuto1.cpp ${tuto1_moc}) target_link_libraries( tuto1 - container topology utils algo ${COMMON_LIBS} ${QT_LIBRARIES}) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} gl2ps) QT4_WRAP_UI( tuto2_ui tuto2.ui ) QT4_WRAP_CPP(tuto2_moc tuto2.h) add_executable( tuto2 tuto2.cpp tuto2.h ${tuto2_ui} ${tuto2_moc}) target_link_libraries( tuto2 - container topology utils algo ${COMMON_LIBS} ${QT_LIBRARIES} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) -add_executable( tuto3 tuto3.cpp) +QT4_WRAP_CPP(tuto3_moc tuto3.h) +add_executable( tuto3 tuto3.cpp ${tuto3_moc}) target_link_libraries( tuto3 - container topology utils algo ${COMMON_LIBS} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES}) -add_executable( tuto4 tuto4.cpp) +QT4_WRAP_UI( tuto4_ui tuto4.ui ) +QT4_WRAP_CPP(tuto4_moc tuto4.h) +add_executable( tuto4 tuto4.cpp ${tuto4_ui} ${tuto4_moc}) target_link_libraries( tuto4 - container topology utils algo ${COMMON_LIBS} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) -add_executable( tuto5 tuto5.cpp) +QT4_WRAP_UI( tuto5_ui tuto5.ui ) +QT4_WRAP_CPP(tuto5_moc tuto5.h) +add_executable( tuto5 tuto5.cpp ${tuto5_ui} ${tuto5_moc}) target_link_libraries( tuto5 - container topology utils algo ${COMMON_LIBS} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) add_executable( tuto_subdivision tuto_subdivision.cpp) target_link_libraries( tuto_subdivision - container topology utils algo ${COMMON_LIBS} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ) -add_executable( tp_master tp_master.cpp) +QT4_WRAP_CPP(tp_master_moc tp_master.h) +add_executable( tp_master tp_master.cpp ${tp_master_moc}) target_link_libraries( tp_master - container topology utils algo ${COMMON_LIBS} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) add_executable( tuto_mt tuto_mt.cpp) target_link_libraries( tuto_mt - container topology utils algo ${COMMON_LIBS} boost_thread-mt) + ${CGoGN_LIBS_D} ${COMMON_LIBS} boost_thread-mt) QT4_WRAP_CPP(tuto_ogl3_moc tuto_ogl3.h) add_executable( tuto_ogl3 tuto_ogl3.cpp ${tuto_ogl3_moc}) target_link_libraries( tuto_ogl3 - container topology utils algo ${COMMON_LIBS} ${QT_LIBRARIES} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) add_executable( tuto_ogl2 tuto_ogl2.cpp) target_link_libraries( tuto_ogl2 - container topology utils algo ${COMMON_LIBS} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ) diff --git a/Apps/Tuto/tp_master.cpp b/Apps/Tuto/tp_master.cpp index 264bf21298c84c837db5a35cb882af1f052fc1f8..46cfd949dec72c2de0e63f273209d49f8719a4c7 100644 --- a/Apps/Tuto/tp_master.cpp +++ b/Apps/Tuto/tp_master.cpp @@ -26,8 +26,7 @@ #include #include -#include "Utils/GLSLShader.h" -#include "Utils/glutwin.h" +#include "tp_master.h" #include "Topology/generic/parameters.h" #include "Topology/map/map2.h" @@ -36,8 +35,8 @@ #include "Geometry/vector_gen.h" #include "Geometry/matrix.h" -#include "Algo/Render/vbo_MapRender.h" -#include "Algo/Render/topo_vboRender.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Algo/Render/GL2/topoRender.h" #include "Algo/Geometry/normal.h" #include "Algo/Selection/raySelector.h" @@ -45,6 +44,9 @@ #include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" +#include "Utils/shaderSimpleColor.h" +#include "Utils/shaderPhong.h" + /// pour simplifier l'ecriture du code using namespace CGoGN; @@ -211,67 +213,6 @@ void coupe_carre(Dart dd) -class myGlutWin: public Utils::SimpleGlutWin -{ -public: - - /** - * position of object - */ - PFP::VEC3 gPosObj; - - /** - * width of object - */ - float gWidthObj; - - Algo::Render::GL2::MapRender_VBO* m_render; - - Algo::Render::GL2::topo_VBORenderMapD* m_render_topo; - - /** - * redraw CB - */ - void myRedraw(); - - /** - * keyboard CB - */ - void myKeyboard(unsigned char keycode, int x, int y); - - /** - * GL initialization - */ - void myInitGL(); - - /** - * dessine les cellules et brins selectionne - */ - void drawSelected(); - - /** - * mise a jour des modifications de la carte dans les buffer OpenGL - */ - void updateRender(); - - - /** - * rendering topology ? - */ - bool renderTopo; - - /** - * rendering help ? - */ - bool aff_help; - - - myGlutWin( int* argc, char **argv, int winX, int winY) : - SimpleGlutWin(argc,argv,winX,winY), - m_render(NULL),m_render_topo(NULL),aff_help(true) {} -}; - - /// Variables pour le picking PFP::VEC3 rayA; PFP::VEC3 rayB; @@ -281,46 +222,10 @@ std::vector d_edges; std::vector d_vertices; -// fonction qui calcule la distance a utiliser pour la selection -float computeSelectRadius(int x, int y, int pixelRadius) -{ - GLint viewport[4]; - GLdouble modelview[16]; - GLdouble projection[16]; - GLfloat winX, winY, winZ; - GLdouble posX, posY, posZ; - - glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); - glGetDoublev( GL_PROJECTION_MATRIX, projection ); - glGetIntegerv( GL_VIEWPORT, viewport ); - - // get depth - glReadPixels( x, viewport[3]-y , 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); - - // if we have click on background, consider that we are in the middle of space - // to avoid too big radius - if (winZ == 1.0f) // depth vary in [0-1] - winZ = 0.5f; - - winX = (float)x; - winY = (float)viewport[3] - (float)y; - -// get first point in object space - gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); - PFP::VEC3 p(posX,posY,posZ); - -// get second point in object space - gluUnProject( winX+pixelRadius, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); - PFP::VEC3 q(posX,posY,posZ); - - // compute & return distance - q -= p; - return float(q.norm()); -} - -void myGlutWin::drawSelected() +void MyQT::drawSelected() { + /* typedef Dart Dart; // FACES @@ -378,6 +283,7 @@ void myGlutWin::drawSelected() glEnd(); glLineWidth(7.0f); + */ for(unsigned int i=0; i < selected_darts.size(); ++i) { // fait varier la couleur du plus pres au plus loin @@ -406,130 +312,101 @@ void myGlutWin::drawSelected() break; } } -} -void myGlutWin::myInitGL() -{ - glClearColor(0.2,0.2,0.2,0.); - 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 myGlutWin::updateRender() -{ - if (m_render == NULL) - m_render = new Algo::Render::GL2::MapRender_VBO() ; - - m_render->initPrimitives(myMap, SelectorTrue(),Algo::Render::GL2::TRIANGLES); -// m_render->initPrimitives(myMap, SelectorTrue(),Algo::Render::GL2::LINES); - m_render->updateData(Algo::Render::GL2::POSITIONS, position); - Algo::Geometry::computeNormalVertices(myMap, position, normal) ; - m_render->updateData(Algo::Render::GL2::NORMALS, normal); +void MyQT::cb_initGL() +{ + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); + + // create the render + m_render = new Algo::Render::GL2::MapRender(); + m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ; + + // create VBO for position + m_positionVBO = new Utils::VBO(); + m_normalVBO = new Utils::VBO(); + + m_shader = new Utils::ShaderPhong(); + 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.)); + + // using simple shader with color + m_shader2 = new Utils::ShaderSimpleColor(); + m_shader2->setAttributePosition(m_positionVBO); + m_shader2->setColor(Geom::Vec4f(0.,0.1,0.,0.)); + registerRunning(m_shader); + registerRunning(m_shader2); +} - if (m_render_topo == NULL) - m_render_topo = new Algo::Render::GL2::topo_VBORenderMapD() ; - m_render_topo->updateData(myMap,position,0.9f,0.9f); -} -void myGlutWin::myRedraw(void) +void MyQT::cb_redraw() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - /// centrage de la scene - glPushMatrix(); - float sc = 50./gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); - - /// Affichage de la topologie si demande - glDisable(GL_LIGHTING); drawSelected(); - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 0.2f, 0.2f ); - m_render_topo->drawTopo(); - - /// qq setup OpenGL - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_CULL_FACE); - glShadeModel(GL_FLAT); - glFrontFace(GL_CCW); - - /// Rendu faces surlignage -// glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); -// glLineWidth(2.0f); - /// Vert devant - glColorMaterial(GL_FRONT, GL_DIFFUSE); - glColor3f(0.0f,0.9f,0.3f); - /// Rouge derriere - glColorMaterial(GL_BACK, GL_DIFFUSE); - //glColor3f(0.9f,0.3f,0.3f); - glColor3f(0.0f,0.9f,0.3f); + if (renderTopo) + { + glEnable( GL_POLYGON_OFFSET_FILL ); + glPolygonOffset( 0.2f, 0.2f ); + m_render_topo->drawTopo(); + } /// decalage pour surlignage non clignotant glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( 1.0f, 1.0f ); + glLineWidth(1.0f); + m_render->draw(m_shader2,Algo::Render::GL2::LINES) ; /// Rendu faces pleines + glEnable(GL_CULL_FACE); + glFrontFace(GL_CCW); glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_BACK,GL_NONE); - /// Vert devant - glColorMaterial(GL_FRONT, GL_DIFFUSE); - glColor3f(0.1f,0.5f,0.1f); - /// Rouge derriere - glColorMaterial(GL_BACK, GL_DIFFUSE); - //glColor3f(0.5f,0.1f,0.1f); - glColor3f(0.1f,0.5f,0.1f); - - m_render->draw(Algo::Render::GL2::TRIANGLES) ; + m_render->draw(m_shader,Algo::Render::GL2::TRIANGLES) ; glDisable( GL_POLYGON_OFFSET_FILL ); - - glPopMatrix(); - - if (aff_help) - { - glColor3f(1.0f,1.0f,1.0f); - printString2D(10,20,"Keys:\nt: affichage topologie\nf: selection face (position souris)\na: selection aretes\ns: selection sommet\nd: selection brin\n0: vide la pile des brins selectionnes\nD: info brin"); - } } -void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) +void MyQT::cb_keyPress(int keycode) { + int x,y; + glMousePosition(x,y); + std::cout << x << " , "<< y << std::endl; + switch(keycode) { case 't': renderTopo = !renderTopo; - glutPostRedisplay(); + if (renderTopo) + statusMsg("Render Topology"); + else + statusMsg(""); + updateGL(); break; case '0': selected_darts.clear(); - glutPostRedisplay(); + statusMsg("Cleanning selected darts"); + updateGL(); break; case 'd': { if (selected_darts.size()>5) + { + statusMsg("Already six darts selected"); break; + } - glPushMatrix(); - - float sc = 50./gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); /// calcul du rayon getOrthoScreenRay(x,y,rayA,rayB); @@ -541,26 +418,14 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) d_vertices.clear(); std::vector darts; Algo::Selection::dartsRaySelection(myMap, position, rayA, AB, darts, SelectorTrue()); + selected_darts.push_back(darts[0]); - glPopMatrix(); - - if (!darts.empty()) - { - selected_darts.push_back(darts[0]); - redraw(); - glutSwapBuffers(); - } + updateGL(); break; } case 'D': { - glPushMatrix(); - - float sc = 50./gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); - /// calcul du rayon getOrthoScreenRay(x,y,rayA,rayB); PFP::VEC3 AB = rayB-rayA; @@ -572,11 +437,8 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) std::vector darts; Algo::Selection::dartsRaySelection(myMap, position, rayA, AB, darts, SelectorTrue()); - glPopMatrix(); - if (!darts.empty()) { - redraw(); std::stringstream ss; Dart d1 = myMap.phi1(darts[0]); Dart d2 = myMap.phi2(darts[0]); @@ -584,22 +446,13 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) const PFP::VEC3& P = position[darts[0]]; ss << " /Emb:" << P; - glColor3f(1.,1.,0.); - printString2D(x+8,y+8,ss.str()); - glutSwapBuffers(); + statusMsg(ss.str().c_str()); } break; } case 'f': { - glPushMatrix(); - - float sc = 50./gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); - - /// calcul du rayon getOrthoScreenRay(x,y,rayA,rayB); PFP::VEC3 AB = rayB-rayA; @@ -611,57 +464,36 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) Algo::Selection:: facesRaySelection(myMap, position, SelectorTrue(), rayA, AB, d_faces); - glPopMatrix(); - if (!d_faces.empty()) { - redraw(); + if (!d_faces.empty()) + { std::stringstream ss; - ss << "face " << d_faces[0].index/3; - glColor3f(1.,0.,0.); - printString2D(x+8,y+8,ss.str()); - glutSwapBuffers(); + ss << "Face " << d_faces[0].index/3; + statusMsg(ss.str().c_str()); } break; } case 'a': { - glPushMatrix(); - - float sc = 50./gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); - /// calcul du rayon - getOrthoScreenRay(x,y,rayA,rayB); + float dist = getOrthoScreenRay(x,y,rayA,rayB); PFP::VEC3 AB = rayB-rayA; d_faces.clear(); d_edges.clear(); d_vertices.clear(); - // compute distance threshold (depends on width of object and scale factor) - // not good selection vary with density of point -// float dist = gWidthObj/(100.0f*getScale()); - float dist = computeSelectRadius(x,y,4); - std::cout << "Distance obj = "<(myMap, position, SelectorTrue(), rayA, AB, d_edges,dist); - glPopMatrix(); - if (!d_edges.empty()) { - redraw(); std::stringstream ss; Dart dd = myMap.phi2(d_edges[0]); - ss << "dart: " << d_edges[0].index<<" phi1: "<< myMap.phi1(d_edges[0]).index; + ss << "Arete: dart: " << d_edges[0].index<<" phi1: "<< myMap.phi1(d_edges[0]).index; if (dd != d_edges[0]) - ss << std::endl<< "phi2: " << dd.index<<" phi1: "<< myMap.phi1(dd).index; - - glColor3f(1.,1.,0.); - printString2D(x+8,y+8,ss.str()); - glutSwapBuffers(); + ss << std::endl<< " phi2: " << dd.index<<" phi1: "<< myMap.phi1(dd).index; + statusMsg(ss.str().c_str()); } break; @@ -669,53 +501,31 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) case 's': { - glPushMatrix(); - - float sc = 50./gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); - /// Rayon - getOrthoScreenRay(x,y,rayA,rayB); + float dist = getOrthoScreenRay(x,y,rayA,rayB); PFP::VEC3 AB = rayB-rayA; d_faces.clear(); d_edges.clear(); d_vertices.clear(); - // compute distance threshold (depends on width of object and scale factor) - // not good selection vary with density of point -// float dist = gWidthObj/(100.0f*getScale()); - float dist = computeSelectRadius(x,y,6); - Algo::Selection::verticesRaySelection(myMap, position,rayA, AB, d_vertices,dist,SelectorTrue()); - std::cout << "Distance obj = "<=2) { Colle(selected_darts[0], selected_darts[1]); - glutPostRedisplay(); + updateGL(); } break; @@ -740,7 +550,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) if (selected_darts.size()>=2) { ColleMilieu(selected_darts[0], selected_darts[1]); - glutPostRedisplay(); + updateGL(); } break; @@ -748,7 +558,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) if (selected_darts.size()>=2) { Decoupage(selected_darts[0], selected_darts[1]); - glutPostRedisplay(); + updateGL(); } break; @@ -757,9 +567,10 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) int main(int argc, char **argv) { - /// init glut interface and - myGlutWin mgw(&argc,argv,800,800); - mgw.init(); + // interface: + QApplication app(argc, argv); + MyQT sqt; + if (argc == 2) { @@ -767,24 +578,43 @@ int main(int argc, char **argv) Algo::Import::importMesh(myMap, argv[1], attrNames) ; position = myMap.getAttribute(VERTEX_ORBIT, attrNames[0]) ; normal = myMap.addAttribute(VERTEX_ORBIT, "normal"); - mgw.updateRender(); + Algo::Geometry::computeNormalVertices(myMap, position, normal) ; } else { position = myMap.addAttribute(VERTEX_ORBIT, "position"); normal = myMap.addAttribute(VERTEX_ORBIT, "normal"); createMap(); - mgw.updateRender(); // ne pas oublier de mettre à jour openGL après chaque modif dans la carte } if (myMap.getNbDarts()==0) exit(0); - Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); - mgw.gWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); - mgw.gPosObj = (bb.min() + bb.max()) / PFP::REAL(2); + // caclul de la bounding box de la scene a afficher + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); + float lWidthObj = std::max(std::max(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 optenir le contexte GL + sqt.show(); + + // update du VBO position (contexte GL necessaire) + sqt.m_positionVBO->updateData(position); + sqt.m_normalVBO->updateData(normal); + + // update des primitives du renderer + SelectorTrue allDarts; + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + + sqt.m_render_topo->updateData(myMap, position, 0.9f, 0.9f); - mgw.mainLoop(); + // show final pour premier redraw + sqt.show(); - return 0; + // et on attend la fin. + return app.exec(); } diff --git a/Apps/Tuto/tp_master.h b/Apps/Tuto/tp_master.h new file mode 100644 index 0000000000000000000000000000000000000000..0f69e0c5431765fc6519a4d20b89ca7eff0fcfaa --- /dev/null +++ b/Apps/Tuto/tp_master.h @@ -0,0 +1,84 @@ +/******************************************************************************* +* 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 TP_MASTER_H_ +#define TP_MASTER_H_ + + +#include + + +#include "Utils/qtSimple.h" + +// forward definitions (minimize includes) +namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}} +namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class TopoRenderMapD; }}}} +namespace CGoGN { namespace Utils { class VBO; } } +namespace CGoGN { namespace Utils { class ShaderPhong; } } +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 + +protected: + bool m_drawTopo; + void drawSelected(); +public: + // render + Algo::Render::GL2::MapRender* m_render; + Algo::Render::GL2::TopoRenderMapD* m_render_topo; + + // VBO + Utils::VBO* m_positionVBO; + Utils::VBO* m_normalVBO; + + //2 shaders + Utils::ShaderPhong* m_shader; + Utils::ShaderSimpleColor* m_shader2; + + bool renderTopo; + + MyQT(): + m_render(NULL), m_render_topo(NULL), + m_positionVBO(NULL), m_normalVBO(NULL), + m_shader(NULL), m_shader2(NULL), + renderTopo(true) {} + + // callbacks of simpleQT to overdefine: + void cb_redraw(); + + void cb_initGL(); + + void cb_keyPress(int code); +}; + +#endif + diff --git a/Apps/Tuto/tuto1.cpp b/Apps/Tuto/tuto1.cpp index de74acf3d87e77f80077a4524cfd8ffc4203b697..99dbbb3738a7e2d46ae7ae756f640cf0cffd071c 100644 --- a/Apps/Tuto/tuto1.cpp +++ b/Apps/Tuto/tuto1.cpp @@ -21,6 +21,7 @@ * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ +#define GL3_PROTOTYPES #include @@ -37,6 +38,10 @@ #include "tuto1.h" +#include "Utils/gl2ps.h" +#include "Algo/Modelisation/polyhedron.h" +#include + using namespace CGoGN ; @@ -65,23 +70,17 @@ void MyQT::cb_initGL() // using simple shader with color m_shader = new Utils::ShaderSimpleColor(); - m_shader->setAttributePosition(*m_positionVBO); + m_shader->setAttributePosition(m_positionVBO); m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.)); - + registerRunning(m_shader); } -void MyQT::cb_updateMatrix() -{ - if (m_shader) - { - m_shader->updateMatrices(m_projection_matrix, m_modelView_matrix); - } -} void MyQT::cb_redraw() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); if (m_shader) { @@ -99,6 +98,7 @@ void MyQT::cb_redraw() } } + void MyQT::cb_keyPress(int code) { if ((code >65) && (code< 123 )) @@ -107,6 +107,30 @@ void MyQT::cb_keyPress(int code) if ((code >'0') && (code<='9')) std::cout << " key num " << code-'0' << "pressed"<< std::endl; + if (code =='a') + { + FILE *fp; + int state = GL2PS_OVERFLOW, buffsize = 0; + fp = fopen("out.svg", "wb"); + while(state == GL2PS_OVERFLOW) + { + buffsize += 1024*1024; + +// gl2psBeginPage("test", "tuto1", NULL, GL2PS_SVG, GL2PS_BSP_SORT, +// GL2PS_NO_PS3_SHADING | GL2PS_TIGHT_BOUNDING_BOX| GL2PS_BEST_ROOT | GL2PS_USE_CURRENT_VIEWPORT, +// GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.svg"); + gl2psBeginPage("test", "tuto1", NULL, GL2PS_SVG, GL2PS_BSP_SORT, + GL2PS_SIMPLE_LINE_OFFSET | GL2PS_TIGHT_BOUNDING_BOX| GL2PS_BEST_ROOT | GL2PS_USE_CURRENT_VIEWPORT, + GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.svg"); + + + cb_redraw(); + glFlush(); + state = gl2psEndPage(); + } + fclose(fp); + } + } @@ -115,6 +139,7 @@ int main(int argc, char **argv) // declaration of the map PFP::MAP myMap; + /* // creation of 2 new faces: 1 triangle and 1 square Dart d1 = myMap.newFace(3); Dart d2 = myMap.newFace(4); @@ -137,10 +162,18 @@ int main(int argc, char **argv) // add another triangle Dart d3 = myMap.newOrientedFace(3); - position[d3] = PFP::VEC3(4, 0, 0); - position[myMap.phi1(d3)] = PFP::VEC3(8, 0, 0); - position[myMap.phi_1(d3)] = PFP::VEC3(6, 3, 0); +// position[d3] = PFP::VEC3(4, 0, 0); +// position[myMap.phi1(d3)] = PFP::VEC3(2, 0, 0); +// position[myMap.phi_1(d3)] = PFP::VEC3(0, 3, 0); + position[d3] = PFP::VEC3(-1, -1, 1); + position[myMap.phi1(d3)] = PFP::VEC3(3, 0, 1); + position[myMap.phi_1(d3)] = PFP::VEC3(1, 3, 1); +*/ + AttributeHandler position = myMap.addAttribute(VERTEX_ORBIT, "position"); + Algo::Modelisation::Polyhedron prim3(myMap, position); + prim3.tore_topo(12, 24); + prim3.embedTore(1.0f,0.3f); // interface: QApplication app(argc, argv); diff --git a/Apps/Tuto/tuto1.h b/Apps/Tuto/tuto1.h index 6d5474781e07a66e40d956b9dcf5f6bd61246727..41f7fc4c76af3635ff93fe9c2c0a90657721597c 100644 --- a/Apps/Tuto/tuto1.h +++ b/Apps/Tuto/tuto1.h @@ -27,11 +27,14 @@ #include -#include "Algo/Render/GL2/mapRender.h" -#include "Utils/shaderSimpleColor.h" #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 ShaderSimpleColor; } } + using namespace CGoGN ; /** @@ -54,8 +57,6 @@ public: MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL) {} // callbacks of simpleQT to overdefine: - void cb_updateMatrix(); - void cb_redraw(); void cb_initGL(); diff --git a/Apps/Tuto/tuto2.cpp b/Apps/Tuto/tuto2.cpp index 6e583c2180e8fbff83807d6c2c753f4659c5ff34..0a76665a677bc9992b3370099ad7ac3ed103f880 100644 --- a/Apps/Tuto/tuto2.cpp +++ b/Apps/Tuto/tuto2.cpp @@ -28,10 +28,9 @@ #include "Topology/map/map2.h" #include "Topology/generic/mapBrowser.h" -#include "Geometry/matrix.h" -#include "Geometry/vector_gen.h" -#include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Utils/shaderSimpleColor.h" #include "tuto2.h" @@ -69,24 +68,18 @@ void MyQT::cb_initGL() // using simple shader with color m_shader = new Utils::ShaderSimpleColor(); - m_shader->setAttributePosition(*m_positionVBO); + m_shader->setAttributePosition(m_positionVBO); m_color = Geom::Vec4f(0.,1.,0.,0.); m_shader->setColor(m_color); + registerRunning(m_shader); + m_with_lines=true; m_line_width=4.0; } -void MyQT::cb_updateMatrix() -{ - if (m_shader) - { - m_shader->updateMatrices(m_projection_matrix, m_modelView_matrix); - } -} - void MyQT::cb_redraw() { diff --git a/Apps/Tuto/tuto2.h b/Apps/Tuto/tuto2.h index a27c4b78123d9fc87fa6b6dd4651bb4bb26c1071..f8b77d3a0243fdd712c81f3b3a532fb9b021a53a 100644 --- a/Apps/Tuto/tuto2.h +++ b/Apps/Tuto/tuto2.h @@ -27,14 +27,18 @@ #include -#include "Algo/Render/GL2/mapRender.h" -#include "Utils/shaderSimpleColor.h" #include "Utils/qtSimple.h" - #include "ui_tuto2.h" #include "Utils/qtui.h" +#include "Geometry/vector_gen.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 ShaderSimpleColor; } } + using namespace CGoGN ; /** @@ -65,8 +69,6 @@ public: MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL) {} - // callbacks of simpleQT to overdefine: - void cb_updateMatrix(); void cb_redraw(); diff --git a/Apps/Tuto/tuto2.ui b/Apps/Tuto/tuto2.ui index 1e1da0266063fc2be64f321980730fb02a64e6a8..cf38cd84b97cc5b497a214dbc0dbebd5145b5be5 100644 --- a/Apps/Tuto/tuto2.ui +++ b/Apps/Tuto/tuto2.ui @@ -7,7 +7,7 @@ 0 0 122 - 337 + 335 @@ -90,6 +90,22 @@ + + + + 10 + + + 2 + + + 4 + + + Qt::Horizontal + + + @@ -141,5 +157,38 @@ - + + + dial_line_width + valueChanged(int) + horizontalSlider + setValue(int) + + + 60 + 134 + + + 60 + 200 + + + + + horizontalSlider + valueChanged(int) + dial_line_width + setValue(int) + + + 60 + 200 + + + 60 + 134 + + + + diff --git a/Apps/Tuto/tuto3.cpp b/Apps/Tuto/tuto3.cpp index a3aa84ac0d38f94a1b42797296dd374ba5b43d2f..9814e6599ae011651ad8063fb3f2f8e4cf284b87 100644 --- a/Apps/Tuto/tuto3.cpp +++ b/Apps/Tuto/tuto3.cpp @@ -24,19 +24,20 @@ #include -#include "Utils/glutwin.h" - #include "Topology/generic/parameters.h" #include "Topology/map/map2.h" #include "Topology/generic/cellmarker.h" -#include "Geometry/matrix.h" #include "Geometry/vector_gen.h" -#include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" -#include "Algo/Render/map_glRender.h" -#include "Algo/Render/vbo_MapRender.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Utils/shaderSimpleColor.h" +#include "Utils/shaderColorPerVertex.h" + +#include "tuto3.h" +MyQT* sqt1_ptr; +MyQT* sqt2_ptr; using namespace CGoGN ; @@ -46,83 +47,101 @@ struct PFP: public PFP_STANDARD typedef Map2 MAP; }; -PFP::MAP myMap; - -SelectorTrue allDarts; -PFP::TVEC3 position ; -PFP::TVEC3 normal ; -AttributeHandler color ; -class myGlutWin: public Utils::SimpleGlutWin +void MyQT::cb_initGL() { -public: + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); - void myRedraw(); + // create the render + m_render = new Algo::Render::GL2::MapRender(); - float gWidthObj; - Geom::Vec3f gPosObj; + // create VBO for position + m_positionVBO = new Utils::VBO(); + m_colorVBO = new Utils::VBO(); - Algo::Render::GL2::MapRender_VBO* m_render; + // using simple shader with color + m_shader = new Utils::ShaderSimpleColor(); + m_shader->setAttributePosition(m_positionVBO); + + + m_shader2 = new Utils::ShaderColorPerVertex(); + m_shader2->setAttributePosition(m_positionVBO); + m_shader2->setAttributeColor(m_colorVBO); + + + registerRunning(m_shader); + registerRunning(m_shader2); +} - myGlutWin( int* argc, char **argv, int winX, int winY):SimpleGlutWin(argc,argv,winX,winY) {} -}; -void myGlutWin::myRedraw(void) +void MyQT::cb_redraw() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glPushMatrix(); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - // met l'objet au milieu de l'ecran a la bonne taille - float sc = 50.0f/gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); + glLineWidth(2.0f); + m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); + m_render->draw(m_shader, Algo::Render::GL2::LINES); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); + m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES); + glDisable(GL_POLYGON_OFFSET_FILL); - glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - glDisable(GL_LIGHTING); +} - // on trace les ligne devant - glDisable( GL_POLYGON_OFFSET_FILL ); - glColor3f(1.0f,1.0f,0.0f); - m_render->draw(Algo::Render::GL2::LINES); - // et on decale les faces vers l'arriere - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 1.0f, 1.0f ); +void MyQT::cb_keyPress(int code) +{ + switch(code) + { + case 's': + if (this == sqt2_ptr) + sqt1_ptr->synchronize(sqt2_ptr); + if (this == sqt1_ptr) + sqt2_ptr->synchronize(sqt1_ptr); + break; + } - glColor3f(0.0f,0.5f,0.0f); - m_render->draw(Algo::Render::GL2::TRIANGLES); - glDisable( GL_POLYGON_OFFSET_FILL ); - glPopMatrix(); } int main(int argc, char **argv) { - /// Utilisation des Marker - /// on reprend la carte de tuto1 + PFP::MAP myMap; + SelectorTrue allDarts; + + PFP::TVEC3 position ; + PFP::TVEC3 normal ; + AttributeHandler color ; Dart d2 = myMap.newOrientedFace(3); Dart d3 = myMap.newOrientedFace(4); myMap.sewFaces(d2,d3); - position = myMap.addAttribute(VERTEX_ORBIT, "position"); + position = myMap.addAttribute(VERTEX_ORBIT, "position"); + color = myMap.addAttribute(VERTEX_ORBIT, "couleur"); position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f); + color[d2] = PFP::VEC3(1.0f, 0.0f, 0.0f); d2 = myMap.phi1(d2); position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f); + color[d2] = PFP::VEC3(0.0f, 1.0f, 0.0f); d2 = myMap.phi1(d2); position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f); + color[d2] = PFP::VEC3(0.0f, 0.0f, 1.0f); d2 = myMap.phi1(d2); d3 = myMap.phi<11>(d3); position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f); + color[d3] = PFP::VEC3(1.0f, 0.0f, 1.0f); d3 = myMap.phi1(d3); position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f); + color[d3] = PFP::VEC3(0.0f, 1.0f, 1.0f); d3 = myMap.phi1(d3); @@ -150,30 +169,93 @@ int main(int argc, char **argv) std::cout << "Sommet de dart "<< d.label() << " marque par mcv"<< std::endl; } + //nettoyage cm.unmarkAll(); - // un peu d'interface - myGlutWin mgw(&argc,argv,800,800); - // calcul de la bounding box + // interface: + QApplication app(argc, argv); + + MyQT sqt; + sqt1_ptr= &sqt; + + MyQT sqt2; + sqt2_ptr= &sqt2; + + // message d'aide + sqt.setHelpMsg("Tuto3:\n" + "marker tuto\n" + "using two VBO & two shader"); + + // bounding box Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); - // pour l'affichage - mgw.gWidthObj = std::max( std::max(bb.size(0),bb.size(1)),bb.size(2)); - mgw.gPosObj = (bb.min() + bb.max()) /2.0f; + float lWidthObj = std::max(std::max(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 du VBO color + sqt.m_colorVBO->updateData(color); + + + // update des primitives du renderer + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + + // show final pour premier redraw + sqt.show(); + + // et pour le fun une deuxieme carte et une deuxieme interface: + + PFP::MAP myMap2; + PFP::TVEC3 position2 ; + AttributeHandler color2 ; + + Dart dx = myMap2.newOrientedFace(4); + + position2 = myMap2.addAttribute(VERTEX_ORBIT, "position"); + color2 = myMap2.addAttribute(VERTEX_ORBIT, "couleur"); + + position2[dx] = PFP::VEC3(0.0f, 0.0f, 0.0f); + color2[dx] = PFP::VEC3(1.0f, 1.0f, 0.0f); + dx = myMap.phi1(dx); + position2[dx] = PFP::VEC3(2.0f, 0.0f, 0.0f); + color2[dx] = PFP::VEC3(0.0f, 1.0f, 0.0f); + dx = myMap.phi1(dx); + position2[dx] = PFP::VEC3(2.0f, 2.0f, 0.0f); + color2[dx] = PFP::VEC3(1.0f, 0.0f, 1.0f); + dx = myMap.phi1(dx); + position2[dx] = PFP::VEC3(0.0f, 2.0f, 0.0f); + color2[dx] = PFP::VEC3(0.0f, 1.0f, 1.0f); + + + + sqt2.setHelpMsg("Fenetre 2!!"); + + sqt2.setParamObject(lWidthObj,lPosObj.data()); + + // show 1 pour GL context + sqt2.show(); + + // update du VBO position (context GL necessaire) + sqt2.m_positionVBO->updateData(position2); + // update du VBO color + sqt2.m_colorVBO->updateData(color2); - // allocation des objets necessaires pour le rendu - mgw.m_render = new Algo::Render::GL2::MapRender_VBO(); - // maj des donnees de position - mgw.m_render->updateData(Algo::Render::GL2::POSITIONS, position); - // creation des primitives de rendu a partir de la carte - mgw.m_render->initPrimitives(myMap, allDarts,Algo::Render::GL2::TRIANGLES); - mgw.m_render->initPrimitives(myMap, allDarts,Algo::Render::GL2::LINES); + // update des primitives du renderer + sqt2.m_render->initPrimitives(myMap2, allDarts, Algo::Render::GL2::TRIANGLES); + sqt2.m_render->initPrimitives(myMap2, allDarts, Algo::Render::GL2::LINES); - mgw.mainLoop(); - delete mgw.m_render; + // et on attend la fin. + return app.exec(); - return 0; } diff --git a/Apps/Tuto/tuto3.h b/Apps/Tuto/tuto3.h new file mode 100644 index 0000000000000000000000000000000000000000..047817776696ee78ee96dcf222cc8b3ce47aa43a --- /dev/null +++ b/Apps/Tuto/tuto3.h @@ -0,0 +1,66 @@ +/******************************************************************************* +* 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 _TUTO3_H_ +#define _TUTO3_H_ + +#include "Utils/qtSimple.h" + +// forward definition (minimize includes) +namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}} +namespace CGoGN { namespace Utils { class VBO; } } +namespace CGoGN { namespace Utils { class ShaderSimpleColor; class ShaderColorPerVertex; } } + +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; + Utils::VBO* m_colorVBO; + + // shader basic + Utils::ShaderSimpleColor* m_shader; + Utils::ShaderColorPerVertex* m_shader2; + + bool m_sync; + + MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL), m_sync(false) {} + + // callbacks of simpleQT to overdefine: + void cb_redraw(); + + void cb_initGL(); + + void cb_keyPress(int code); +}; + +#endif diff --git a/Apps/Tuto/tuto4.cpp b/Apps/Tuto/tuto4.cpp index a57fcac656fa64a44cdc79619fdda7a4b5f0d7ae..b6ed412893921bbe1065211d6daa94c77549bc7f 100644 --- a/Apps/Tuto/tuto4.cpp +++ b/Apps/Tuto/tuto4.cpp @@ -24,7 +24,7 @@ #include -#include "Utils/glutwin.h" +#include "tuto4.h" #include "Topology/generic/parameters.h" #include "Topology/map/map2.h" @@ -33,12 +33,14 @@ #include "Geometry/vector_gen.h" #include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" -#include "Algo/Render/map_glRender.h" -#include "Algo/Render/vbo_MapRender.h" -#include "Algo/Render/topo_vboRender.h" - #include "Topology/generic/cellmarker.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Algo/Render/GL2/topoRender.h" +#include "Utils/shaderSimpleColor.h" +#include "Utils/shaderFlat.h" + + using namespace CGoGN ; @@ -55,90 +57,92 @@ PFP::TVEC3 position ; PFP::TVEC3 normal ; AttributeHandler color ; -class myGlutWin: public Utils::SimpleGlutWin + +void MyQT::cb_initGL() { -public: - void myRedraw(); + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(3); - float gWidthObj; - Geom::Vec3f gPosObj; + // create the render + m_render = new Algo::Render::GL2::MapRender(); - bool render_obj; - bool render_topo; + m_render_topo = new Algo::Render::GL2::TopoRenderMapD(); - Algo::Render::GL2::MapRender_VBO* m_render; - Algo::Render::GL2::topo_VBORenderMapD* m_render_topo; + // create VBO for position + m_positionVBO = new Utils::VBO(); - myGlutWin( int* argc, char **argv, int winX, int winY):SimpleGlutWin(argc,argv,winX,winY) - { - render_obj = true; - render_topo = false; - } + // using simple shader with color + m_shader = new Utils::ShaderSimpleColor(); + m_shader->setAttributePosition(m_positionVBO); + m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.)); - void myKeyboard(unsigned char keycode, int x, int y); -}; + m_shader2 = new Utils::ShaderFlat(); + m_shader2->setAttributePosition(m_positionVBO); + + registerRunning(m_shader); + registerRunning(m_shader2); -/// Gestion des touches clavier -void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) -{ - switch(keycode) { - /** affichage **/ - case 'o' : { - render_obj = !render_obj; - glutPostRedisplay(); - break; - } - case 't' : { - render_topo = !render_topo; - glutPostRedisplay(); - break; - } - default : { - std::cout << "not yet implemented" << std::endl; - break; - } - - } } -void myGlutWin::myRedraw(void) +void MyQT::cb_redraw() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glPushMatrix(); - - // met l'objet au milieu de l'ecran a la bonne taille - float sc = 50.0f/gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); - - glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - glDisable(GL_LIGHTING); + if(render_topo) + { + m_render_topo->drawTopo(); + } if(render_obj) { - // on trace les ligne devant - glDisable( GL_POLYGON_OFFSET_FILL ); - glColor3f(1.0f,1.0f,0.0f); - m_render->draw(Algo::Render::GL2::LINES); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - // et on decale les faces vers l'arriere glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( 1.0f, 1.0f ); - - glColor3f(0.0f,0.5f,0.0f); - m_render->draw(Algo::Render::GL2::TRIANGLES); - glDisable( GL_POLYGON_OFFSET_FILL ); + m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES); + glDisable(GL_POLYGON_OFFSET_FILL); } - if(render_topo) +} + + +void MyQT::cb_keyPress(int code) +{ + switch(code) { - m_render_topo->drawTopo(); + case 'o': + render_obj = !render_obj; + updateGL(); + break; + + case 't': + render_topo = !render_topo; + updateGL(); + break; + } +} + +void MyQT::button_compile() +{ + QString st1 = dynamic_cast(dockWidget())->vertexEdit->toPlainText(); + QString st2 = dynamic_cast(dockWidget())->fragmentEdit->toPlainText(); + QString st3 = dynamic_cast(dockWidget())->geometryEdit->toPlainText(); - glPopMatrix(); + + m_shader2->reloadVertexShaderFromMemory(st1.toStdString().c_str()); + m_shader2->reloadFragmentShaderFromMemory(st2.toStdString().c_str()); + m_shader2->reloadGeometryShaderFromMemory(st3.toStdString().c_str()); + + m_shader2->recompile(); + updateGLMatrices(); +} + +void MyQT::slider_explode(int x) +{ + m_shader2->setExplode(0.01*x); + updateGL(); } @@ -147,25 +151,23 @@ int main(int argc, char **argv) { /// Utilisation des Marker - /// on reprend la carte de tuto1 - - Dart d2 = myMap.newOrientedFace(3); - Dart d3 = myMap.newOrientedFace(4); - myMap.sewFaces(d2,d3); - position = myMap.addAttribute(VERTEX_ORBIT, "position"); - position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f); - d2 = myMap.phi1(d2); - position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f); - d2 = myMap.phi1(d2); - position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f); - d2 = myMap.phi1(d2); - d3 = myMap.phi<11>(d3); - position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f); - d3 = myMap.phi1(d3); - position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f); - d3 = myMap.phi1(d3); + Algo::Modelisation::Polyhedron prim3(myMap, position); + Dart d2 = prim3.tore_topo(16, 24); + prim3.embedTore(1.0f,0.3f); + +// position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f); +// d2 = myMap.phi1(d2); +// position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f); +// d2 = myMap.phi1(d2); +// position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f); +// d2 = myMap.phi1(d2); +// d3 = myMap.phi<11>(d3); +// position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f); +// d3 = myMap.phi1(d3); +// position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f); +// d3 = myMap.phi1(d3); // unsigned int idAttV2 = myMap.addAttribute(VERTEX_ORBIT,"reel"); // PFP::AttributeHandler tableReels(idAttV2,VERTEX_ORBIT,myMap); @@ -193,37 +195,58 @@ int main(int argc, char **argv) CellMarkerStore cm(myMap, VERTEX_ORBIT); + Dart d3 = myMap.phi1(d2); cm.mark(d2); cm.mark(d3); cm.unmarkAll(); - // un peu d'interface - myGlutWin mgw(&argc,argv,800,800); + // interface: + QApplication app(argc, argv); + MyQT sqt; + + // interface de tuto5.ui + Utils::QT::uiDockInterface dock; + sqt.setDock(&dock); - // calcul de la bounding box + // message d'aide + sqt.setHelpMsg("Tuto4"); + + // bounding box Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); - // pour l'affichage - mgw.gWidthObj = std::max( std::max(bb.size(0),bb.size(1)),bb.size(2)); - mgw.gPosObj = (bb.min() + bb.max()) /2.0f; + float lWidthObj = std::max(std::max(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()); + + sqt.setCallBack( dock.compileButton, SIGNAL(clicked()), SLOT(button_compile()) ); + sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(slider_explode(int)) ); + + + // 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(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + sqt.m_render_topo->updateData(myMap, position, 0.9f, 0.9f); - // allocation des objets necessaires pour le rendu - mgw.m_render = new Algo::Render::GL2::MapRender_VBO(); - mgw.m_render_topo = new Algo::Render::GL2::topo_VBORenderMapD(); - // maj des donnees de position - mgw.m_render->updateData(Algo::Render::GL2::POSITIONS, position); - // creation des primitives de rendu a partir de la carte - mgw.m_render->initPrimitives(myMap, allDarts,Algo::Render::GL2::TRIANGLES); - mgw.m_render->initPrimitives(myMap, allDarts,Algo::Render::GL2::LINES); + dock.vertexEdit->setPlainText(QString(sqt.m_shader2->getVertexShaderSrc())); + dock.fragmentEdit->setPlainText(QString(sqt.m_shader2->getFragmentShaderSrc())); + dock.geometryEdit->setPlainText(QString(sqt.m_shader2->getGeometryShaderSrc())); - // creation des primitives de rendu de la topologie a partir de la carte - mgw.m_render_topo->updateData(myMap, position, 0.9f, 0.9f); + // show final pour premier redraw + sqt.show(); - mgw.mainLoop(); + // et on attend la fin. + return app.exec(); - delete mgw.m_render; - return 0; } diff --git a/Apps/Tuto/tuto4.h b/Apps/Tuto/tuto4.h new file mode 100644 index 0000000000000000000000000000000000000000..9271dbbd24a6f2608755b37f9ea9bbd6a4aa851c --- /dev/null +++ b/Apps/Tuto/tuto4.h @@ -0,0 +1,75 @@ +/******************************************************************************* +* 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 _TUTO4_H_ +#define _TUTO4_H_ + +#include "Utils/qtSimple.h" + +#include "ui_tuto4.h" +// inclure qtui.h juste après le ui_xxx.h +#include "Utils/qtui.h" + +// forward definitions (minimize includes) syntax a little bit tricky !! +namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; class TopoRenderMapD; }}}} +namespace CGoGN { namespace Utils { class VBO; } } +namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } +namespace CGoGN { namespace Utils { class ShaderFlat; } } + +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; + Algo::Render::GL2::TopoRenderMapD* m_render_topo; + + // VBO + Utils::VBO* m_positionVBO; + + // shader basic + Utils::ShaderSimpleColor* m_shader; + Utils::ShaderFlat* m_shader2; + + bool render_obj; + bool render_topo; + + MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL), render_obj(true), render_topo(false) {} + + void cb_redraw(); + + void cb_initGL(); + + void cb_keyPress(int code); + +public slots: + void button_compile(); + void slider_explode(int x); +}; + +#endif diff --git a/Apps/Tuto/tuto4.ui b/Apps/Tuto/tuto4.ui new file mode 100644 index 0000000000000000000000000000000000000000..f91457450027c1a1f2c6f47cc28c87ef5b6e6d4c --- /dev/null +++ b/Apps/Tuto/tuto4.ui @@ -0,0 +1,172 @@ + + + DockWidget + + + + 0 + 0 + 399 + 485 + + + + + 0 + 0 + + + + + 324 + 419 + + + + true + + + Interface ShaderFlat + + + + + 0 + 0 + + + + + 324 + 394 + + + + + 2 + + + 4 + + + + + 0 + + + QLayout::SetDefaultConstraint + + + 0 + + + + + Explode + + + + + + + + 1 + 0 + + + + 20 + + + 100 + + + 90 + + + 90 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Shaders editor + + + + + + + 0 + + + + Vertex + + + + + + + + + + Fragment + + + + + + + + + + Geometry + + + + + + + 1 + 1 + + + + + + + + + + + + + 0 + 0 + + + + recompile + + + + + + + + + + + diff --git a/Apps/Tuto/tuto5.cpp b/Apps/Tuto/tuto5.cpp index 28df0376a2061d30b14ce310eeb9a0af5cd0b00f..3306e08c4c2d1ca34bf8bd11b861ec3873788297 100644 --- a/Apps/Tuto/tuto5.cpp +++ b/Apps/Tuto/tuto5.cpp @@ -22,32 +22,31 @@ * * *******************************************************************************/ -#include +#include "tuto5.h" -#include "Utils/glutwin.h" +#include #include "Topology/generic/parameters.h" #include "Topology/map/map3.h" #include "Topology/generic/embeddedMap3.h" -#include "Geometry/matrix.h" + #include "Geometry/vector_gen.h" -#include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" -#include "Algo/Render/map_glRender.h" -#include "Algo/Render/vbo_MapRender.h" -#include "Algo/Modelisation/tetrahedron.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Utils/shaderSimpleColor.h" + #include "Algo/Modelisation/primitives3d.h" #include "Algo/Modelisation/polyhedron.h" #include "Algo/Modelisation/subdivision.h" -#include "Algo/Render/topo3_vboRender.h" +#include "Algo/Render/GL2/topo3Render.h" #include "Topology/generic/cellmarker.h" #include "Utils/text3d.h" -//#include "testMaps.h" - +#include "Utils/pointSprite.h" +#include "Utils/pointLine.h" using namespace CGoGN ; @@ -68,45 +67,51 @@ unsigned int idNorm; unsigned int idCol; - - - -class myGlutWin: public Utils::SimpleGlutWin +void MyQT::balls_onoff(bool x) { -public: - - void myRedraw(); - - float gWidthObj; - Geom::Vec3f gPosObj; - - bool aff_help; - bool render_line; - bool render_volume; - bool render_topo; + render_balls = !render_balls; + updateGL(); +} - Algo::Render::GL2::MapRender_VBO* m_render; - Algo::Render::GL2::topo3_VBORenderMapD* m_render_topo; +void MyQT::vectors_onoff(bool x) +{ + render_vectors = !render_vectors; + updateGL(); +} - Utils::Strings3D m_strings; +void MyQT::text_onoff(bool x) +{ + statusMsg(NULL); + render_text = !render_text; + updateGL(); +} - void updateVBO(); +void MyQT::topo_onoff(bool x) +{ + render_topo = !render_topo; + updateGL(); +} - void storeVerticesInfo(); +void MyQT::slider_balls(int x) +{ + m_sprite->setSize(0.05f*x); + updateGL(); +} - myGlutWin( int* argc, char **argv, int winX, int winY):SimpleGlutWin(argc,argv,winX,winY) - { - aff_help = false; - render_line = true; - render_volume = false; - render_topo = true; +void MyQT::slider_vectors(int x) +{ + m_lines->setScale(0.02*x); + updateGL(); +} - } +void MyQT::slider_text(int x) +{ + m_strings->setScale(0.02f*x); + updateGL(); +} - void myKeyboard(unsigned char keycode, int x, int y); -}; -void myGlutWin::storeVerticesInfo() +void MyQT::storeVerticesInfo() { CellMarker mv(myMap,VERTEX_CELL); @@ -117,359 +122,118 @@ void myGlutWin::storeVerticesInfo() mv.mark(d); std::stringstream ss; ss << d << " : "<< position[d]; - m_strings.addString(ss.str(),position[d]); + m_strings->addString(ss.str(),position[d]); } } } -void myGlutWin::myRedraw(void) +void MyQT::cb_initGL() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glPushMatrix(); + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); + + // create the render + m_render = new Algo::Render::GL2::MapRender(); - // met l'objet au milieu de l'ecran a la bonne taille - float sc = 50.0f/gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); + m_render_topo = new Algo::Render::GL2::Topo3RenderMapD(); - glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - glDisable(GL_LIGHTING); + // create VBO for position + m_positionVBO = new Utils::VBO(); + m_positionVBO->updateData(position); - glLineWidth(3.0); - glBegin(GL_LINES); - glColor3f(1.,0.,0.); - glVertex3f(0.0,0.0,0.0); - glVertex3f(1.0,0.0,0.0); + // using simple shader with color + m_shader = new Utils::ShaderSimpleColor(); + m_shader->setAttributePosition(m_positionVBO); + m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.)); - glColor3f(0.,1.,0.); - glVertex3f(0.0,0.0,0.0); - glVertex3f(0.0,1.0,0.0); + m_sprite = new Utils::PointSprite(); + m_sprite->setAttributePosition(m_positionVBO); - glColor3f(0.,0.,1.); - glVertex3f(0.0,0.0,0.0); - glVertex3f(0.0,0.0,1.0); - glEnd(); + m_strings = new Utils::Strings3D(true,Geom::Vec3f(0.1,0.,0.3)); + storeVerticesInfo(); + m_strings->sendToVBO(); - glColor3f(0.0f,1.0f,.0f); - m_render->draw(Algo::Render::GL2::POINTS); - if(render_line) + // copy de contenu de VBO a la creation + m_dataVBO = new Utils::VBO(*m_positionVBO); + + m_lines = new Utils::PointLine(); + m_lines->setAttributePosition(m_positionVBO); + m_lines->setAttributeData(m_dataVBO); + m_lines->setScale(0.2f); + m_lines->setColor(Geom::Vec3f(0.0f, 1.0f,0.2f)); + + // accede au buffer du VBO pour modification + PFP::VEC3* data = static_cast(m_dataVBO->lockPtr()); + for (unsigned int i=0; i< m_dataVBO->nbElts(); ++i) { - // on trace les ligne devant - glDisable( GL_POLYGON_OFFSET_FILL ); - glColor3f(1.0f,1.0f,0.0f); - m_render->draw(Algo::Render::GL2::LINES); + data[i].normalize(); } - // et on decale les faces vers l'arriere + m_dataVBO->releasePtr(); - if(render_volume) - { - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 1.0f, 1.0f ); - glColor3f(0.0f,0.5f,0.0f); - m_render->draw(Algo::Render::GL2::TRIANGLES); - glDisable( GL_POLYGON_OFFSET_FILL ); - } + registerRunning(m_shader); + registerRunning(m_strings); + registerRunning(m_sprite); + registerRunning(m_lines); - if(render_topo) - { - glDisable( GL_POLYGON_OFFSET_FILL ); - glColor3f(1.0f,1.0f,0.0f); - m_render_topo->drawTopo(); + SelectorTrue allDarts; - Dart d = myMap.phi2( myMap.begin()); - m_render_topo->overdrawDart(d,5,1.0f,0.0f,1.0f); + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::POINTS); - } + m_render_topo->updateData(myMap, allDarts, position, 0.9, 0.9, 0.9); +} -// m_strings.predraw(Geom::Vec3f(0.0,1.0,1.0)); -// m_strings.draw(0,Geom::Vec3f(0.5,0.5,0.5)); -// m_strings.draw(1,Geom::Vec3f(-0.5,0.5,0.5)); -// m_strings.draw(2,Geom::Vec3f(-0.5,-0.5,0.5)); -// m_strings.postdraw(); +void MyQT::cb_redraw() +{ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_LIGHTING); - m_strings.drawAll(Geom::Vec3f(0.0,1.0,1.0)); + m_render->draw(m_shader, Algo::Render::GL2::POINTS); - //affichage de l'aide - if (aff_help) { - glColor3f(1.0f,1.0f,1.0f); - printString2D(10,20,"Keys:\n\ - l: affichage des lignes de bordures\n\ - v: affichage des volumes\n\ - h: affiche cette aide\n\n\n\n\ - 1 : swap 2->2\n"); - } + glLineWidth(2.0f); + m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); + m_render->draw(m_shader, Algo::Render::GL2::LINES); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); - glPopMatrix(); + if (render_topo) + m_render_topo->drawTopo(); + Dart d = myMap.phi2( myMap.begin()); + m_render_topo->overdrawDart(d,5,1.0f,0.0f,1.0f); + d = myMap.phi1( myMap.begin()); + m_render_topo->overdrawDart(d,5,1.0f,0.0f,1.0f); -} -void myGlutWin::updateVBO() -{ - m_render->updateData(Algo::Render::GL2::POSITIONS, position ); - m_render->initPrimitives(myMap,allDarts,Algo::Render::GL2::LINES); - m_render->initPrimitives(myMap,allDarts,Algo::Render::GL2::POINTS); - m_render->initPrimitives(myMap,allDarts,Algo::Render::GL2::TRIANGLES); - m_render_topo->updateData(myMap, allDarts, position, 0.9, 0.9, 0.9); -} + glDisable(GL_POLYGON_OFFSET_FILL); -/// Gestion des touches clavier -void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) -{ - switch(keycode) { - /** affichage **/ - case 'D': - { - Dart d = myMap.begin(); - m_render_topo->setDartColor(d, 1.0f,0.0f,0.0f); - d = myMap.phi1(d); - m_render_topo->setDartColor(d, 0.0f,1.0f,0.0f); - d = myMap.phi1(d); - m_render_topo->setDartColor(d, 0.0f,0.0f,1.0f); - glutPostRedisplay(); - - } - break; - - case 'x': - { - // push/pop color is only needed for dart coloring conservation - // can bee long long huge meshes - m_render_topo->pushColors(); - - // setDartsIdColor can be done only once if dart coloring not used - m_render_topo->setDartsIdColor(myMap,allDarts); - - // transform as in drawing cb - glPushMatrix(); - float sc = 50.0f/gWidthObj; - glScalef(sc,sc,sc); - glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); - //pick - Dart d = m_render_topo->picking(x,H-y); - - glPopMatrix(); - - m_render_topo->popColors(); - - if (d != Dart::nil()) - { - m_render_topo->setDartColor(d,1.0,0.0,0.0); - redraw(); - std::stringstream ss; - ss << "Pick dart:" << d << std::endl<<"pos="<< position[d]; - glColor3f(1.,1.,0.); - printString2D(x+12,y+22,ss.str()); - glutSwapBuffers(); - std::cout << "Pick dart:" << d << " pos= "<< position[d] << std::endl; - } - - - break; - } - - case 'Q': - m_render_topo->setAllDartsColor(1.0f,1.0f,1.0f); - glutPostRedisplay(); - break; - - case 'c' : { //Cut Edge OK - Dart d = 9; - //Dart d = dglobal; - - Dart f = myMap.phi1(d); - myMap.cutEdge(d); - Dart e = myMap.phi1(d); - position[e] = position[d]; - position[e] += position[f]; - position[e] *= 0.5; - - m_render_topo->updateData(myMap, allDarts, position, 0.9, 0.9, 0.9); - m_render_topo->setDartColor(d, 0.0f,1.0f,0.0f); - glutPostRedisplay(); - break; - } - case 's' : { //Split Face OK - Dart d = 25; - //Dart d = dglobal; - - myMap.splitFace(d, myMap.phi1(myMap.phi1(d))); - - m_render_topo->updateData(myMap, allDarts, position, 0.9, 0.9, 0.9); - glutPostRedisplay(); - break; - } - case 'f' : { //Flip Edge - //Dart d = 25; - //Dart d = myMap.phi2(25); - Dart d = dglobal; - - Dart r = myMap.phi2(d); - Dart e = myMap.phi2(myMap.phi3(d)); - - unsigned int p1 = myMap.getDartEmbedding(VERTEX_ORBIT, myMap.phi_1(e)); - unsigned int p2 = myMap.getDartEmbedding(VERTEX_ORBIT, myMap.phi_1(r)); - - - myMap.flipFace(d); - - myMap.setDartEmbedding(VERTEX_ORBIT, r, p1 ); - myMap.setDartEmbedding(VERTEX_ORBIT, e, p2 ); - - Dart dd = d; - do { - Dart e = myMap.phi2(dd); - Dart e2= myMap.phi<32>(dd);//myMap.phi2(myMap.phi3(dd)); - myMap.setDartEmbedding(VERTEX_ORBIT, dd, myMap.getDartEmbedding(VERTEX_ORBIT,e)); - myMap.setDartEmbedding(VERTEX_ORBIT, myMap.phi3(dd), myMap.getDartEmbedding(VERTEX_ORBIT, e2)); - dd = myMap.phi1(dd); - } while( dd!=d); - - - m_render_topo->updateData(myMap, allDarts, position, 0.9, 0.9, 0.5); - glutPostRedisplay(); - break; - } - case 'b' : { - Dart d = dglobal; - //Dart d = myMap.phi<323>(myMap.phi_1(myMap.phi<232>(myMap.phi1(myMap.phi<112>(dglobal))))); - - - std::cout << "boundary : " << myMap.isBoundaryVolume(d) << std::endl; - - updateVBO(); - glutPostRedisplay(); - break; - } - case 'E' : { //Collapse Edge - //Dart d = 10; - //Dart d = myMap.phi2(25); - Dart d = dglobal; - - //Dart d = myMap.phi<23>(myMap.phi1(myMap.phi<232>(dglobal))); - -// Dart dd = myMap.phi2(d) ; -// -// PFP::VEC3 a = position[d]; -// PFP::VEC3 v2 = position[dd] ; -// -// // Compute the approximated position -// a = (a + v2) / PFP::REAL(2); -// -// position[d] = a; - - myMap.collapseEdge(d); - - updateVBO(); - glutPostRedisplay(); - break; - } - case 'F' : { //Collapse Face OK - Dart d = 10; - //Dart d = myMap.phi2(25); - //Dart d = myMap.phi<232>(myMap.phi1(myMap.phi<232>(dglobal))); - //Dart d = dglobal; - - -// Dart d1 = myMap.phi1(d); -// Dart d11 = myMap.phi1(myMap.phi1(d)); -// Dart d111 = myMap.phi1(myMap.phi1(myMap.phi1(d))); -// -// std::cout << "d=" << d << " d1=" << d1 << " d11=" << d11 << " d111=" << d111 << std::endl; - - myMap.collapseFace(d); - -// myMap.collapseEdge(d); -// myMap.collapseEdge(d1); -// myMap.collapseEdge(d11,false,false); - - updateVBO(); - glutPostRedisplay(); - break; - } - case 'V' : { //Collapse Volume - m_render_topo->updateData(myMap, allDarts, position, 0.9, 0.9, 0.9); - glutPostRedisplay(); - break; - } - case 'd' : { //Volume Degree OK - std::cout << "degree = " << myMap.volumeDegree(dglobal) << std::endl; - break; - } - case 'C' : { - Dart d = dglobal; - - Algo::Modelisation::hexaCutVolume, PFP::VEC3>(myMap,d , position); - - updateVBO(); - glutPostRedisplay(); - break; - } - case 'l' : { - render_line = !render_line; - glutPostRedisplay(); - break; - } - case 'v' : { - render_volume = !render_volume; - glutPostRedisplay(); - break; - } - case 't' : { - render_topo = !render_topo; - glutPostRedisplay(); - break; - } - case 'h': { - aff_help = !aff_help; - glutPostRedisplay(); - break; - } - case '1': { - Algo::Modelisation::Tetrahedron::swap2To2(myMap, dglobal, position); - updateVBO(); - glutPostRedisplay(); - break; - } - case '2' : { - Algo::Modelisation::Tetrahedron::swap4To4(myMap, dglobal, position); - updateVBO(); glutPostRedisplay(); - break; - } - case '3' : { - Algo::Modelisation::Tetrahedron::swap2To3(myMap, dglobal, position); - updateVBO(); - glutPostRedisplay(); - break; - } - case '4' : { - Algo::Modelisation::Tetrahedron::swap3To2(myMap, dglobal, position); - updateVBO(); - glutPostRedisplay(); - break; - } - default : { - std::cout << "not implemented" << std::endl; - break; - } - - } + if (render_text) + m_strings->drawAll(Geom::Vec3f(0.0,1.0,1.0)); + + if (render_balls) + { + m_sprite->predraw(Geom::Vec3f(1.,0.,0.)); + m_render->draw(m_sprite, Algo::Render::GL2::POINTS); + m_sprite->postdraw(); + } + + if (render_vectors) + m_render->draw(m_lines, Algo::Render::GL2::POINTS); + } int main(int argc, char **argv) { -// std::vector attrNames ; -// Algo::Import::importInESS(myMap, argv[1], attrNames); -// position = myMap.getAttribute(VERTEX_ORBIT, attrNames[0]) ; position = myMap.addAttribute(VERTEX_ORBIT,"position"); @@ -482,70 +246,46 @@ int main(int argc, char **argv) prim.embedHexaGrid(1.0f,1.0f,1.0f); -// Geom::Matrix44f mat; -// mat.identity(); -// Geom::scale(2.0f, 2.0f,2.0f,mat); -// prim.transform(mat); - -// Dart d = Algo::Modelisation::Polyhedron::createOrientedPolyhedron(myMap,6); -// dglobal=d; -// -// position[d] = PFP::VEC3(0); -// position[myMap.phi1(d)] = PFP::VEC3(1,0,0); -// position[myMap.phi1(myMap.phi1(d))] = PFP::VEC3(1,0,1); -// position[myMap.phi_1(d)] = PFP::VEC3(0,0,1); -// -// d = myMap.phi_1(myMap.phi2(myMap.phi_1(myMap.phi_1(myMap.phi2(myMap.phi_1(d)))))); -// position[d] = PFP::VEC3(1,1,0); -// position[myMap.phi1(d)] = PFP::VEC3(0,1,0); -// position[myMap.phi1(myMap.phi1(d))] = PFP::VEC3(0,1,1); -// position[myMap.phi_1(d)] = PFP::VEC3(1,1,1); - -// Dart d = Algo::Modelisation::Polyhedron::createOrientedPolyhedron(myMap,4); -// dglobal=d; -// -// Dart t1 = d; -// position[t1] = PFP::VEC3(0.0f, 0.0f, 3.0f); -// t1 = myMap.phi1(t1); -// position[t1] = PFP::VEC3(0.0f, 1.0f, 3.0f); -// t1 = myMap.phi1(t1); -// position[t1] = PFP::VEC3(1.0f, 0.5f, 3.0f); -// t1 = myMap.phi_1(myMap.phi2(d)); -// position[t1] = PFP::VEC3(0.5f, 0.5f, 4.0f); + // un peu d'interface + QApplication app(argc, argv); + MyQT sqt; - //Dart d = Algo::Modelisation::Polyhedron::createOrientedPrism(myMap); -// Algo::Modelisation::Polyhedron p(myMap, position); -// dglobal = p.cube_topo(3,1,1); -// p.embedCube(1.0f,1.0f,1.0f); + // interface de tuto5.ui + Utils::QT::uiDockInterface dock; + sqt.setDock(&dock); + // message d'aide + sqt.setHelpMsg(""); - //dglobal = createMap9(myMap,position); + sqt.statusMsg("3Map with topo rendering & attribute shader utilization"); + // bounding box + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); + float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); + Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); - // un peu d'interface - myGlutWin mgw(&argc,argv,800,800); + // envoit info BB a l'interface + sqt.setParamObject(lWidthObj,lPosObj.data()); - // calcul de la bounding box - Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap,position); - // pour l'affichage - mgw.gWidthObj = std::max( std::max(bb.size(0),bb.size(1)),bb.size(2)); - mgw.gPosObj = (bb.min() + bb.max()) /2.0f; + sqt.setCallBack( dock.checkBox_balls, SIGNAL(toggled(bool)), SLOT(balls_onoff(bool)) ); + sqt.setCallBack( dock.checkBox_vectors, SIGNAL(toggled(bool)), SLOT(vectors_onoff(bool)) ); + sqt.setCallBack( dock.checkBox_text, SIGNAL(toggled(bool)), SLOT(text_onoff(bool)) ); + sqt.setCallBack( dock.checkBox_topo, SIGNAL(toggled(bool)), SLOT(topo_onoff(bool)) ); + sqt.setCallBack( dock.slider_balls, SIGNAL(valueChanged(int)), SLOT(slider_balls(int)) ); + sqt.setCallBack( dock.slider_vectors, SIGNAL(valueChanged(int)), SLOT(slider_vectors(int)) ); + sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) ); - // allocation des objets necessaires pour le rendu - mgw.m_render = new Algo::Render::GL2::MapRender_VBO(); - mgw.m_render_topo = new Algo::Render::GL2::topo3_VBORenderMapD(); + sqt.show(); - mgw.updateVBO(); + sqt.slider_balls(50); + sqt.slider_vectors(50); + sqt.slider_text(50); - mgw.m_strings.init(); - mgw.storeVerticesInfo(); - mgw.m_strings.sendToVBO(); - mgw.mainLoop(); - delete mgw.m_render; + // et on attend la fin. + return app.exec(); - return 0; } diff --git a/Apps/Tuto/tuto5.h b/Apps/Tuto/tuto5.h new file mode 100644 index 0000000000000000000000000000000000000000..04c1d64594050e592612b600a12914808bb59689 --- /dev/null +++ b/Apps/Tuto/tuto5.h @@ -0,0 +1,110 @@ +/******************************************************************************* +* 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 __TUTO5_ +#define __TUTO5_ + + +#include + + +#include "Utils/qtSimple.h" + +#include "ui_tuto5.h" +// inclure qtui.h juste après le ui_xxx.h +#include "Utils/qtui.h" + +// forward definitions (minimize includes) +namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}} +namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class Topo3RenderMapD; }}}} +namespace CGoGN { namespace Utils { class VBO; } } +namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } +namespace CGoGN { namespace Utils { class Strings3D; } } +namespace CGoGN { namespace Utils { class PointSprite; } } +namespace CGoGN { namespace Utils { class PointLine; } } + +using namespace CGoGN ; + +/** + * Utilisation de designer-qt4: + * Faire un DockWiget (laisser le nom par defaut + * dans le Contents ajouter le layout choisi (vertical classiquement) + * Ajouter les widgets necessaires, mettre des noms clairs pour + * les utiliser dans le .cpp (pour les call back principalement) + */ + +class MyQT: public Utils::QT::SimpleQT +{ + Q_OBJECT + + bool render_text; + bool render_balls; + bool render_vectors; + bool render_topo; + + Algo::Render::GL2::MapRender* m_render; + Algo::Render::GL2::Topo3RenderMapD* m_render_topo; + + Utils::VBO* m_positionVBO; + Utils::VBO* m_dataVBO; + + Utils::ShaderSimpleColor* m_shader; + Utils::Strings3D* m_strings; + Utils::PointSprite* m_sprite; + Utils::PointLine* m_lines; +public: + + + + MyQT(): + render_text(true),render_balls(true),render_vectors(true),render_topo(true), + m_render(NULL), m_positionVBO(NULL), m_shader(NULL) + {} + + +protected: +// void updateVBO(); + + void storeVerticesInfo(); + + void cb_redraw(); + + void cb_initGL(); + +// slots locaux +public slots: + void balls_onoff(bool x); + void vectors_onoff(bool x); + void text_onoff(bool x); + void topo_onoff(bool x); + + void slider_balls(int x); + void slider_vectors(int x); + void slider_text(int x); + + + +}; + +#endif + diff --git a/Apps/Tuto/tuto5.ui b/Apps/Tuto/tuto5.ui new file mode 100644 index 0000000000000000000000000000000000000000..410d5b6b2d8384af6f9cebc678b6428c67a45b92 --- /dev/null +++ b/Apps/Tuto/tuto5.ui @@ -0,0 +1,207 @@ + + + DockWidget + + + + 0 + 0 + 150 + 250 + + + + + 150 + 250 + + + + Interface + + + + true + + + + 0 + 0 + + + + + 150 + 200 + + + + + 2 + + + 4 + + + + + + + Balls + + + true + + + + + + + 50 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Vectors + + + true + + + + + + + 50 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Text + + + true + + + + + + + 50 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Topo + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + checkBox_balls + toggled(bool) + slider_balls + setVisible(bool) + + + 95 + 37 + + + 95 + 63 + + + + + checkBox_text + toggled(bool) + slider_text + setVisible(bool) + + + 95 + 157 + + + 95 + 183 + + + + + checkBox_vectors + toggled(bool) + slider_vectors + setVisible(bool) + + + 95 + 97 + + + 95 + 123 + + + + + diff --git a/Apps/Tuto/tuto_ogl3.cpp b/Apps/Tuto/tuto_ogl3.cpp index 15fbdba4050487889118d030c5f35e7b864c1ace..addb693074b8c6d22b725506872d14667a08f872 100644 --- a/Apps/Tuto/tuto_ogl3.cpp +++ b/Apps/Tuto/tuto_ogl3.cpp @@ -25,10 +25,7 @@ #include #include "tuto_ogl3.h" -#include -#include -#include "Utils/shaderPhong.h" using namespace CGoGN ; @@ -78,22 +75,17 @@ void MyQT::cb_initGL() shader1 = new Utils::ShaderPhong(); - shader1->setAttributePosition(*positionVBO); - shader1->setAttributeNormal(*normalVBO); + shader1->setAttributePosition(positionVBO); + shader1->setAttributeNormal(normalVBO); + registerRunning(shader1); currentShader = shader1; -} -void MyQT::cb_updateMatrix() -{ - if (currentShader) - { - currentShader->bind(); - currentShader->updateMatrices(m_projection_matrix, m_modelView_matrix); - } } + + void MyQT::cb_redraw() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); diff --git a/Apps/Tuto/tuto_ogl3.h b/Apps/Tuto/tuto_ogl3.h new file mode 100644 index 0000000000000000000000000000000000000000..063a74e98c5a4614aa3f3ed356e8b0d404922483 --- /dev/null +++ b/Apps/Tuto/tuto_ogl3.h @@ -0,0 +1,85 @@ +/****************************************************************************** +* 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 __TUTO_OGL3_ +#define __TUTO_OGL3_ + +#include + +#include "Topology/generic/parameters.h" +#include "Topology/map/map2.h" +#include "Topology/generic/embeddedMap2.h" +#include "Geometry/vector_gen.h" +#include "Algo/Geometry/boundingbox.h" +#include "Algo/Modelisation/polyhedron.h" +#include "Algo/Geometry/normal.h" + + +#include "Algo/Render/GL2/mapRender.h" +#include "Geometry/vector_gen.h" + + +#include "Utils/shaderPhong.h" +#include +#include +#include +#include +#include +#include "Utils/qtSimple.h" +#include "Utils/qtgl.h" + +using namespace CGoGN; + +struct PFP: public PFP_STANDARD +{ + // definition of the type of the map + typedef EmbeddedMap2 MAP; +}; + + + +class MyQT: public Utils::QT::SimpleQT +{ + Q_OBJECT +public slots: + void sliderFocale_cb(int x); + void color_cb(); +public: + MyQT(); + ~MyQT(); + + void cb_redraw(); + + Algo::Render::GL2::MapRender* m_render; + + Utils::VBO* positionVBO; + Utils::VBO* normalVBO; + + Utils::ShaderPhong* shader1; + Utils::GLSLShader* currentShader; + void cb_initGL(); + + +}; + +#endif diff --git a/include/Algo/Render/GL2/mapRender.h b/include/Algo/Render/GL2/mapRender.h index 398c7b2fab1db8b2a3b9573c0bfb205fbe7334dc..b963e9a7c772ba7f0d9a640b8184fdad11272016 100644 --- a/include/Algo/Render/GL2/mapRender.h +++ b/include/Algo/Render/GL2/mapRender.h @@ -37,6 +37,8 @@ #include "Utils/vbo.h" +// forward def +namespace CGoGN { namespace Utils { class GLSLShader;} } namespace CGoGN { @@ -63,13 +65,9 @@ enum bufferIndex { TRIANGLE_INDICES = 0, LINE_INDICES = 1, POINT_INDICES = 2, - FLAT_BUFFER = 3, + FLAT_BUFFER = 3 } ; -//const unsigned int NB_BUFFERS = 16 ; - -// forward def -class Utils::GLSLShader; class MapRender { diff --git a/include/Algo/Render/GL2/topo3Render.h b/include/Algo/Render/GL2/topo3Render.h index aefe79ebe243e6b082657aa962fd2667f8b1b03e..b6c0f8dbfb21b64ef6f5c6013037544b4645cff9 100644 --- a/include/Algo/Render/GL2/topo3Render.h +++ b/include/Algo/Render/GL2/topo3Render.h @@ -34,6 +34,12 @@ #include "Topology/generic/attributeHandler.h" #include "Topology/generic/functor.h" +#include "Utils/vbo.h" + +// forward +namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } +namespace CGoGN { namespace Utils { class ShaderColorPerVertex; } } + namespace CGoGN { @@ -47,7 +53,7 @@ namespace GL2 { -class topo3Render +class Topo3Render { protected: @@ -58,7 +64,17 @@ protected: * 2: vertices phi2 * 3: vertices phi3 */ - GLuint m_VBOBuffers[5]; + Utils::VBO* m_vbo0; + Utils::VBO* m_vbo1; + Utils::VBO* m_vbo2; + Utils::VBO* m_vbo3; + Utils::VBO* m_vbo4; + + unsigned int m_vaId; + + Utils::ShaderSimpleColor* m_shader1; + Utils::ShaderColorPerVertex* m_shader2; + /** *number of darts to draw @@ -129,12 +145,12 @@ public: * @param good functor that return true for darts of part to draw * @param type_vbo vbo to alloc ( VBO_P, VBO_PN, VBO_PNC, VBO_PC ..) */ - topo3Render(); + Topo3Render(); /** * Destructor */ - ~topo3Render(); + ~Topo3Render(); /** * update all drawing buffers @@ -268,7 +284,7 @@ public: -class topo3RenderMapD: public topo3Render +class Topo3RenderMapD: public Topo3Render { public: /** @@ -285,7 +301,7 @@ public: }; // // -//class topo3RenderGMap: public topo3Render +//class Topo3RenderGMap: public Topo3Render //{ //public: // /** diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index b634d2d63079f73019537ce282b3fd19e738feeb..b0abfed452096ed1678b42a9bfb69fb703bb6f4a 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -458,7 +458,7 @@ namespace GL2 template -void topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float ke, float kf, float kv) +void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float ke, float kf, float kv) { typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -534,14 +534,14 @@ void topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go AutoAttributeHandler fv2(map, DART_ORBIT); AutoAttributeHandler fv2x(map, DART_ORBIT); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); - GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo4->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo0->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionDartBuf = reinterpret_cast(PositionDartsBuffer); unsigned int posDBI=0; @@ -606,22 +606,22 @@ void topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go } } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[0]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo0->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); // phi1 - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + m_vbo1->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer1 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); //phi2 - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + m_vbo2->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); //phi3 - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + m_vbo3->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer3 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionF1 = reinterpret_cast(PositionBuffer1); @@ -662,17 +662,17 @@ void topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go } while (d != *face ); } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[1]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo3->bind(); + glUnmapBufferARB(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[2]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo2->bind(); + glUnmapBufferARB(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[3]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo1->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[4]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo4->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); } // // @@ -892,11 +892,11 @@ void topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go template -void topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good) +void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good) { - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); - float* colorBuffer = reinterpret_cast(glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE)); + m_vbo4->bind(); + float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); unsigned int nb=0; for (Dart d = map.begin(); d != map.end(); map.next(d)) @@ -924,7 +924,7 @@ void topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g d = map.end(); } } - glUnmapBufferARB(GL_ARRAY_BUFFER); + glUnmapBuffer(GL_ARRAY_BUFFER); } diff --git a/include/Algo/Render/GL2/topoRender.h b/include/Algo/Render/GL2/topoRender.h index a428106f6c40eda94de3544eb6d50137ff409ed1..e3fb87e3f27ec6f2ee1e42ce8feb5d33a690d8e1 100644 --- a/include/Algo/Render/GL2/topoRender.h +++ b/include/Algo/Render/GL2/topoRender.h @@ -22,8 +22,8 @@ * * *******************************************************************************/ -#ifndef _TOPO_VBO_RENDER -#define _TOPO_VBO_RENDER +#ifndef _GL2_TOPO_RENDER_ +#define _GL2_TOPO_RENDER_ #include @@ -34,6 +34,12 @@ #include "Topology/generic/attributeHandler.h" #include "Topology/generic/functor.h" +#include "Utils/vbo.h" + +// forward +namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } +namespace CGoGN { namespace Utils { class ShaderColorPerVertex; } } + namespace CGoGN { @@ -46,7 +52,7 @@ namespace Render namespace GL2 { -class topoRender +class TopoRender { protected: /** @@ -56,7 +62,12 @@ protected: * 2: vertices relation 2 * 3: color */ - GLuint m_VBOBuffers[4]; + Utils::VBO* m_vbo0; + Utils::VBO* m_vbo1; + Utils::VBO* m_vbo2; + Utils::VBO* m_vbo3; + + unsigned int m_vaId; /** *number of darts to draw @@ -82,6 +93,14 @@ protected: */ AttributeHandler m_attIndex; + Utils::ShaderSimpleColor* m_shader1; + Utils::ShaderColorPerVertex* m_shader2; + + + Dart colToDart(float* color); + + void dartToCol(Dart d, float& r, float& g, float& b); + public: /** * Constructor @@ -90,12 +109,12 @@ public: * @param type_vbo vbo to alloc ( VBO_P, VBO_PN, VBO_PNC, VBO_PC ..) */ - topoRender(); + TopoRender(); /** * Destructor */ - ~topoRender(); + ~TopoRender(); /** * set the with of line use to draw darts (default val is 2) @@ -155,9 +174,19 @@ public: * @param b blue ! */ void overdrawDart(Dart d, float width, float r, float g, float b); + + + /** + * pick dart with color set bey setDartsIdColor + * Do not forget to apply same transformation to scene before picking than before drawing ! + * @param x position of mouse (x) + * @param y position of mouse (pass H-y, classic pb of origin) + * @return the dart or NIL + */ + Dart picking(unsigned int x, unsigned int y); }; -class topoRenderMapD : public topoRender +class TopoRenderMapD : public TopoRender { public: /** @@ -172,7 +201,7 @@ public: void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = SelectorTrue()); }; -class topoRenderGMap : public topoRender +class TopoRenderGMap : public TopoRender { public: /** diff --git a/include/Algo/Render/GL2/topoRender.hpp b/include/Algo/Render/GL2/topoRender.hpp index 3ab7bc7a60a86da34b400dd2b126fc663fbe0fbd..a34208cd2f8ce923bfba68b7fca61d805aa752d5 100644 --- a/include/Algo/Render/GL2/topoRender.hpp +++ b/include/Algo/Render/GL2/topoRender.hpp @@ -39,7 +39,7 @@ namespace GL2 { template -void topoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) +void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) { typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -68,15 +68,14 @@ void topoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC // phi2 AutoAttributeHandler fv2(map, DART_ORBIT); - - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); - GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo3->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo0->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionDartBuf = reinterpret_cast(PositionDartsBuffer); unsigned int posDBI = 0; @@ -135,19 +134,19 @@ void topoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC } } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[0]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo0->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[3]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo3->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer1 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo1->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + GLvoid* PositionBuffer1 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo2->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + GLvoid* PositionBuffer2 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionF1 = reinterpret_cast(PositionBuffer1); VEC3* positionF2 = reinterpret_cast(PositionBuffer2); @@ -171,16 +170,19 @@ void topoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC *positionF1++ = fv11[e]; } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[1]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo1->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); + + m_vbo2->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[2]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); } + template -void topoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) +void TopoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) { + /* typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -333,7 +335,7 @@ void topoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[2]); glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); - +*/ } }//end namespace GL2 diff --git a/include/Container/convert.h b/include/Container/convert.h index a56da6d126a3a97fa954e72cc64059bbdd8da254..362760724f230a529162b984d4f692218eefdb85 100644 --- a/include/Container/convert.h +++ b/include/Container/convert.h @@ -74,6 +74,10 @@ public: */ unsigned int sizeElt() { return m_size/m_nb;} + /** + * get the size of buffer in bytes + */ + unsigned int nbElt() { return m_nb;} }; diff --git a/include/Utils/GLSLShader.h b/include/Utils/GLSLShader.h index 878a077d1325956f60b49af84f994ba9d333ff0c..6a6b5e128fd2e94ef8dbe5080e60ebd6264d7bf7 100644 --- a/include/Utils/GLSLShader.h +++ b/include/Utils/GLSLShader.h @@ -38,6 +38,8 @@ #include #include #include +#include + namespace CGoGN { @@ -67,6 +69,7 @@ public: static unsigned int CURRENT_OGL_VERSION; + static std::set< std::pair > m_registredRunning; protected: @@ -76,6 +79,9 @@ protected: static std::string* DEFINES_GL; + static std::string defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert); + + /** * handle of vertex shader */ @@ -97,6 +103,20 @@ protected: GLhandleARB m_program_object; + GLint m_uniMat_Proj; + GLint m_uniMat_Model; + GLint m_uniMat_ModelProj; + GLint m_uniMat_Normal; + + + char* m_vertex_shader_source; + char* m_fragment_shader_source; + char* m_geom_shader_source; + + GLint m_geom_inputPrimitives; + GLint m_geom_outputPrimitives; + + /** * a set of pair VA_id / VBO_id */ @@ -206,6 +226,12 @@ public: static bool init(); + static void registerRunning(GLSLShader* ptr); + + static void unregisterRunning(GLSLShader* ptr); +// +// static void updateMatricesRunningShaders(const glm::mat4& projection, const glm::mat4& modelview); + /** * load shaders (compile and link) * @param vs vertex shader source file @@ -221,7 +247,7 @@ public: * @param inputGeometryPrimitive primitives used in geometry shader as input * @param outputGeometryPrimitive primitives generated in geometry shader as output */ - bool loadShaders(const std::string& vs, const std::string& fs, const std::string& gs, GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES); + bool loadShaders(const std::string& vs, const std::string& fs, const std::string& gs, GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLE_STRIP); /** @@ -244,6 +270,19 @@ public: bool loadShadersFromMemory(const char* vs, const char* fs, const char* gs, GLint inputGeometryPrimitive,GLint outputGeometryPrimitive); + const char* getVertexShaderSrc() {return m_vertex_shader_source;} + const char* getFragmentShaderSrc() {return m_fragment_shader_source;} + const char* getGeometryShaderSrc() {return m_geom_shader_source;} + + + bool reloadVertexShaderFromMemory(const char* vs); + + bool reloadFragmentShaderFromMemory(const char* fs); + + bool reloadGeometryShaderFromMemory(const char* gs); + + bool recompile(); + /** * Link the shader do it just after binding the attributes */ @@ -255,9 +294,14 @@ public: bool isBinded(); - virtual bool bind(); + virtual bool bind() const; + + virtual void unbind() const; - virtual void unbind(); + /** + * restore all uniforms and vertex attributes after recompiling + */ + virtual void restoreUniformsAttribs() {std::cerr << "Warning restoreUniformsAttribs not implemented"<< std::endl;} /** @@ -329,8 +373,14 @@ public: /** * associate an attribute name of shader with a vbo + * @return the index in vector of pair binding, negative if fail */ - void bindVA_VBO(const std::string& name, VBO& vbo); + unsigned int bindVA_VBO(const std::string& name, VBO* vbo); + + /** + * change the vbo of id case of binding vector + */ + void changeVA_VBO(unsigned int id, VBO* vbo); /** * get binding VA VBO @@ -338,12 +388,25 @@ public: const std::vector& getVA_VBO_Bindings() { return m_va_vbo_binding;} + + void bindAttrib(unsigned int att, const char* name) const; /** * update projection, modelview, ... matrices */ void updateMatrices(const glm::mat4& projection, const glm::mat4& modelview); + + /** + * bind, enable, and set all vertex attrib pointers + * @param stride: the stride parameter, number osf byte between two consecutive attributes + */ + void enableVertexAttribs(unsigned int stride=0) const; + + /** + * disenable all vertex attribs + */ + void disableVertexAttribs() const; }; diff --git a/include/Utils/pointLine.h b/include/Utils/pointLine.h new file mode 100644 index 0000000000000000000000000000000000000000..941215ccc34fffb5901df97c9fd1f1f203da0e49 --- /dev/null +++ b/include/Utils/pointLine.h @@ -0,0 +1,79 @@ +/******************************************************************************* +* 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 __POINT_LINE_3D__ +#define __POINT_LINE_3D__ + +#include "Utils/GLSLShader.h" +#include "Geometry/vector_gen.h" + +namespace CGoGN +{ +namespace Utils +{ + +class PointLine : public GLSLShader +{ +protected: + static std::string vertexShaderText; + + static std::string geometryShaderText; + + static std::string fragmentShaderText; + + GLuint m_uniform_scale; + + GLuint m_uniform_color; + +public: + /** + * init shaders and variables + */ + PointLine(float scale=1.0f, const Geom::Vec3f& color = Geom::Vec3f(1.0f,1.0f,1.0f)); + + /** + * set the radius of sphere + * @param radius + */ + void setScale(float scale); + + /** + * set the color + */ + void setColor(const Geom::Vec3f& color); + + /** + * set attribute for position + */ + unsigned int setAttributePosition(VBO* vbo); + + /** + * set attribute for data (drawn vector) + */ + unsigned int setAttributeData(VBO* vbo); + +}; +} +} +#endif diff --git a/include/Utils/pointSprite.h b/include/Utils/pointSprite.h new file mode 100644 index 0000000000000000000000000000000000000000..7f96a48a5ef4137f6f7d70c2debf5df070db63fa --- /dev/null +++ b/include/Utils/pointSprite.h @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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 __POINT_SPRITE_3D__ +#define __POINT_SPRITE_3D__ + +#include "Utils/GLSLShader.h" +#include "Geometry/vector_gen.h" +#include +#include + +namespace CGoGN { namespace Utils { class VBO; } } + +namespace CGoGN +{ +namespace Utils +{ + +class PointSprite: public Utils::GLSLShader +{ +protected: + static const unsigned int WIDTHSPRITE = 64; + + static std::string vertexShaderText; + + static std::string geometryShaderText; + + static std::string fragmentShaderText; + + static GLuint m_idTexture; + + static GLuint m_uniform_texture; + + static unsigned char* m_ptrSphere; + + // compute the sphere instead of storing it in image file. + static void computeSphere(); + + GLuint m_uniform_size; + + GLuint m_uniform_color; +public: + /** + * init shaders, texture and variables + */ + PointSprite(float radius=1.0f); + + /** + * clean shaders, texture and variables + */ + ~PointSprite(); + + /** + * call once before sending points to gpu + */ + void predraw(const Geom::Vec3f& color); + + /** + * call once after sending points to gpu + */ + void postdraw(); + + /** + * set the radius of sphere + * @param radius + */ + void setSize(float radius); + + /** + * set position attribute + */ + unsigned int setAttributePosition(VBO* vbo); + + +}; +} +} +#endif diff --git a/include/Utils/qtSimple.h b/include/Utils/qtSimple.h index 9ffe0def5092f1832ddcff132375e3ef101cc3ae..9f867f30dae8b9fb8bf8a1b116357cee75abbed6 100644 --- a/include/Utils/qtSimple.h +++ b/include/Utils/qtSimple.h @@ -31,8 +31,12 @@ #include #include #include "Utils/qtgl.h" +#include #include +#include "Geometry/vector_gen.h" +namespace CGoGN { namespace Utils { class GLSLShader;}} +//namespace CGoGN { namespace Geom { class Vec3f;}} namespace CGoGN { @@ -83,6 +87,11 @@ public: */ void dockTitle(const char* dockTitle); + + /** + * draw a message in status bar + */ + void statusMsg(const char* msg); /** * add an empty dock to the window */ @@ -112,20 +121,32 @@ public: // void contextMenuEvent(QContextMenuEvent *event); protected: - GLWidget *m_glWidget; + QDockWidget *m_dock; - void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *e); + bool m_dockOn; + + // mouse & matrix glm::mat4 m_projection_matrix; glm::mat4 m_modelView_matrix; + float m_curquat[4]; + float m_lastquat[4]; + float m_trans_x; + float m_trans_y; + float m_trans_z; - std::vector m_popup_actions; QMenu* m_fileMenu; + QMenu* m_appMenu; + std::string m_helpString; + void keyPressEvent(QKeyEvent *event); + + void keyReleaseEvent(QKeyEvent *e); + + public: /** @@ -134,6 +155,22 @@ public: void setParamObject(float width, float* pos) { m_glWidget->setParamObject(width,pos);} + /** + * get the mouse position in GL widget + */ + void glMousePosition(int& x, int& y); + + /** + * get a ray (2 points) from a pick point in GL area + * @param x mouse position + * @param y mouse position + * @param rayA first computed point + * @param rayA second computed point + * @param radius radius on pixel for clicking precision + * @return the distance in modelview world corresponding to radius pixel in screen + */ + GLfloat getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB, int radius=4); + /** * current modelview matrix */ @@ -144,6 +181,28 @@ public: */ glm::mat4& projectionMatrix () { return m_projection_matrix;} + float * curquat() { return m_curquat;} + + float * lastquat() { return m_lastquat;} + + float& trans_x() { return m_trans_x;} + float& trans_y() { return m_trans_y;} + float& trans_z() { return m_trans_z;} + + + void synchronize(SimpleQT* sqt); + + /** + * Register a shader as running in this Widget. + * Needed for automatic matrices update + */ + void registerRunning(GLSLShader* ptr); + + /** + * Unregister a shader as running in this Widget. + */ + void unregisterRunning(GLSLShader* ptr); + /** * GL initialization CB (context is ok) */ @@ -182,7 +241,7 @@ public: /** * matrices need to be updated (context is ok) */ - virtual void cb_updateMatrix() {} + virtual void cb_updateMatrix(); /** * end of program, some things to clean ? @@ -197,6 +256,12 @@ public: */ void updateGL(); + /** + * Ask to Qt to update matrices and then the GL widget. + */ + void updateGLMatrices(); + + public slots: virtual void cb_New() { std::cout << "callback not implemented"<< std::endl;} virtual void cb_Open() { std::cout << "callback not implemented"<< std::endl;} diff --git a/include/Utils/qtgl.h b/include/Utils/qtgl.h index 1a6d3dcfa46c54f332b11863901bf698709b489a..1fee7f8f6fbdc70f767dc55201638c39685e7211 100644 --- a/include/Utils/qtgl.h +++ b/include/Utils/qtgl.h @@ -74,8 +74,8 @@ protected: int m_current_button; int beginx; int beginy; - float curquat[4]; - float lastquat[4]; +// float curquat[4]; +// float lastquat[4]; int newModel; int moving; @@ -89,10 +89,6 @@ protected: glm::vec3 m_obj_pos; - float trans_x; - float trans_y; - float trans_z; - // width and height of windows int W; int H; @@ -128,6 +124,8 @@ public: bool Alt() { return m_state_modifier & Qt::AltModifier; } + int getHeight() const { return H;} + /** * set the focale distance (for a screen width of 2), default value is 1 */ @@ -138,6 +136,8 @@ public: */ float getFocal() {return foc;} + void modelModified() {newModel=1;} + protected: /** * equivalent to old school glRotate diff --git a/include/Utils/shaderColorPerVertex.h b/include/Utils/shaderColorPerVertex.h new file mode 100644 index 0000000000000000000000000000000000000000..380ff0312ee4ac48acae84ea1f3c1fc2828dfc17 --- /dev/null +++ b/include/Utils/shaderColorPerVertex.h @@ -0,0 +1,60 @@ +/******************************************************************************* +* 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_SHADER_CPV_ +#define __CGOGN_SHADER_CPV_ + +#include "Utils/GLSLShader.h" +#include "Geometry/vector_gen.h" + +namespace CGoGN +{ +namespace Utils +{ + +class ShaderColorPerVertex : public GLSLShader +{ +protected: + // shader sources + static std::string vertexShaderText; + static std::string fragmentShaderText; + + VBO* m_vboPos; + VBO* m_vboCol; + + void restoreUniformsAttribs(); + +public: + + ShaderColorPerVertex(); + + unsigned int setAttributePosition(VBO* vbo); + + unsigned int setAttributeColor(VBO* vbo); + +}; + +} +} +#endif diff --git a/include/Utils/shaderFlat.h b/include/Utils/shaderFlat.h index 757a2c2b8f49f28dcf3bd670513bcf5f04ddbdd3..e62a05b14471260703c58239e2072cccfeaf391a 100644 --- a/include/Utils/shaderFlat.h +++ b/include/Utils/shaderFlat.h @@ -40,22 +40,38 @@ protected: static std::string vertexShaderText; static std::string fragmentShaderText; static std::string geometryShaderText; + // uniform locations GLuint m_unif_ambiant; GLuint m_unif_diffuse; GLuint m_unif_lightPos; GLuint m_unif_explode; + float m_explode; + Geom::Vec4f m_ambiant; + Geom::Vec4f m_diffuse; + Geom::Vec3f m_light_pos; + + VBO* m_vboPos; + + void getLocations(); + + void restoreUniformsAttribs(); + public: ShaderFlat(); - void setAmbiant(float explode) {this->bind(); glUniform1f (m_unif_explode, explode);} - void setAmbiant(const Geom::Vec4f& ambiant) {this->bind(); glUniform4fv(m_unif_ambiant,1, ambiant.data());} - void setDiffuse(const Geom::Vec4f& diffuse) {this->bind(); glUniform4fv(m_unif_diffuse,1, diffuse.data());} - void setLightPosition( Geom::Vec3f lp) {this->bind(); glUniform3fv(m_unif_lightPos,1,lp.data());} + + void setExplode(float explode); + + void setAmbiant(const Geom::Vec4f& ambiant); + + void setDiffuse(const Geom::Vec4f& diffuse); + + void setLightPosition(const Geom::Vec3f& lp); void setParams(float explode, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos); - void setAttributePosition(VBO& vbo) {this->bindVA_VBO("VertexPosition", vbo);} + void setAttributePosition(VBO* vbo); }; diff --git a/include/Utils/shaderPhong.h b/include/Utils/shaderPhong.h index 1ee8bc24f632a9699c8b1395791ed9eb06b1f083..ab4e25189596d5b2d1be3a6eb4e7bc4611b56e8d 100644 --- a/include/Utils/shaderPhong.h +++ b/include/Utils/shaderPhong.h @@ -60,12 +60,18 @@ protected: float m_shininess; Geom::Vec3f m_lightPos; + VBO* m_vboPos; + VBO* m_vboNormal; + VBO* m_vboColor; + protected: void getLocations(); void sendParams(); + void restoreUniformsAttribs(); + public: ShaderPhong(); @@ -97,11 +103,12 @@ public: // attributes - void setAttributePosition(VBO& vbo) {this->bindVA_VBO("VertexPosition", vbo);} - void setAttributeNormal(VBO& vbo) {this->bindVA_VBO("VertexNormal", vbo);} + unsigned int setAttributePosition(VBO* vbo); + + unsigned int setAttributeNormal(VBO* vbo); // optionnal attributes - void setAttributeColor(VBO& vbo); + unsigned int setAttributeColor(VBO* vbo); void unsetAttributeColor(); }; diff --git a/include/Utils/shaderSimpleColor.h b/include/Utils/shaderSimpleColor.h index 4e87ef7e58acabc820704878c52bcf8ad85240cd..892eebc2e941f3a54d377c41720ce1916b687e2b 100644 --- a/include/Utils/shaderSimpleColor.h +++ b/include/Utils/shaderSimpleColor.h @@ -42,12 +42,18 @@ protected: // uniform locations GLuint m_unif_color; + Geom::Vec4f m_color; + + VBO* m_vboPos; + + void restoreUniformsAttribs(); + public: ShaderSimpleColor(); void setColor(const Geom::Vec4f& color); - void setAttributePosition(VBO& vbo); + unsigned int setAttributePosition(VBO* vbo); }; } diff --git a/include/Utils/text3d.h b/include/Utils/text3d.h index 39b6b71b55863430c6d47587927ce2c7e1746853..507d0c6ebfd3a16c3cb7175c19481742089f4c94 100644 --- a/include/Utils/text3d.h +++ b/include/Utils/text3d.h @@ -35,7 +35,7 @@ namespace CGoGN namespace Utils { -class Strings3D +class Strings3D: public GLSLShader { protected: static const unsigned int WIDTHFONT = 32; @@ -50,7 +50,14 @@ protected: static const unsigned int CHARSPERCOL = HEIGHTTEXTURE/WIDTHFONT; - ILuint m_imgName; + static std::string vertexShaderText; + + static std::string fragmentShaderText1; + static std::string fragmentShaderText2; + + static ILuint m_imgName; + + static GLuint m_idTexture; std::vector m_strings; @@ -60,15 +67,11 @@ protected: std::vector< Geom::Vec3f > m_strTranslate; - /** - * VBO (4f: x,y,u,v) - */ - GLuint m_vbo1; - unsigned int sendOneStringToVBO(const std::string& str, float **buffer); + Utils::VBO* m_vbo1; + unsigned int sendOneStringToVBO(const std::string& str, float **buffer); - GLuint m_idTexture; GLuint m_uniform_texture; @@ -78,21 +81,12 @@ protected: GLuint m_uniform_color; - Utils::GLSLShader m_shader; - public: - Strings3D(); + Strings3D(bool withBackground=true, const Geom::Vec3f& bgc=Geom::Vec3f(0.0f,0.0f,0.0f)); ~Strings3D(); - /** - * initialization step - * OpenGL context must be opened - * @param scale factor for font rendering - */ - void init(float scale=1.0f); - /** * add astring * @param string to add to pool of string diff --git a/include/Utils/vbo.h b/include/Utils/vbo.h index aae63a8fcb8ab29a8928232479272f3d1ed73c43..201d5e259e93b9707c078cdc6a658f8e5bf0636c 100644 --- a/include/Utils/vbo.h +++ b/include/Utils/vbo.h @@ -54,14 +54,19 @@ protected: unsigned int m_data_size; // shaders that ref this vbo std::vector m_refs; - - + unsigned int m_nbElts; + bool m_lock; public: /** * constructor: allocate the OGL VBO */ VBO(); + /** + * copy constructor, new VBO copy content + */ + VBO(const VBO& vbo); + /** * destructor: release the OGL VBO and clean references between VBO/Shaders */ @@ -82,6 +87,10 @@ public: */ void setDataSize(unsigned int ds) { m_data_size = ds;} + /** + * bind array vbo + */ + void bind() const { glBindBuffer(GL_ARRAY_BUFFER,m_id); } /** * reference vbo as used by shader sh */ @@ -98,6 +107,13 @@ public: */ template void updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv); + + + void* lockPtr(); + + void releasePtr(); + + unsigned int nbElts() {return m_nbElts;} }; } diff --git a/include/Utils/vbo.hpp b/include/Utils/vbo.hpp index 626eb3b51aa32a44df9ceb8cb87ef0418f7ee6a1..22976c236d399821cb2a899500cf5f636d4b1b12 100644 --- a/include/Utils/vbo.hpp +++ b/include/Utils/vbo.hpp @@ -31,6 +31,11 @@ namespace Utils template void VBO::updateData(const ATTR_HANDLER& attrib) { + if (m_lock) + { + std::cerr <<" Error locked VBO"<< std::endl; + return; + } m_data_size = sizeof(typename ATTR_HANDLER::DATA_TYPE) / sizeof(float); AttributeMultiVector* mv = attrib.getDataVector() ; @@ -41,6 +46,8 @@ void VBO::updateData(const ATTR_HANDLER& attrib) glBindBuffer(GL_ARRAY_BUFFER, m_id); glBufferData(GL_ARRAY_BUFFER, nbb * byteTableSize, 0, GL_STREAM_DRAW); + m_nbElts = nbb * byteTableSize / sizeof(typename ATTR_HANDLER::DATA_TYPE); + unsigned int offset = 0; for (unsigned int i = 0; i < nbb; ++i) @@ -53,6 +60,11 @@ void VBO::updateData(const ATTR_HANDLER& attrib) template void VBO::updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv) { + if (m_lock) + { + std::cerr <<" Error locked VBO"<< std::endl; + return; + } m_data_size = conv->sizeElt(); AttributeMultiVector* mv = attrib.getDataVector() ; @@ -67,6 +79,8 @@ void VBO::updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv) glBindBuffer(GL_ARRAY_BUFFER, m_id); glBufferData(GL_ARRAY_BUFFER, nbb * conv->sizeBuffer(), 0, GL_STREAM_DRAW); + m_nbElts = nbb * conv->nbElt(); + unsigned int offset = 0; for (unsigned int i = 0; i < nbb; ++i) diff --git a/src/Algo/Render/mapRender.cpp b/src/Algo/Render/mapRender.cpp index b6477c09db64e7eab4ae49b1976aa12e8846214e..4263511ca32d2076e0284b57ae9e62f2cb0b3d8c 100644 --- a/src/Algo/Render/mapRender.cpp +++ b/src/Algo/Render/mapRender.cpp @@ -88,14 +88,15 @@ void MapRender::initPrimitives(int prim, std::vector& tableIndices) void MapRender::draw(Utils::GLSLShader* sh, int prim) { - const std::vector& vastr = sh->getVA_VBO_Bindings(); - - for (std::vector::const_iterator it= vastr.begin(); it != vastr.end(); ++it) - { - glBindBuffer(GL_ARRAY_BUFFER, it->vbo_ptr->id()); - glEnableVertexAttribArray(it->va_id); - glVertexAttribPointer(it->va_id ,it->vbo_ptr->dataSize(), GL_FLOAT, false, 0, 0); - } + sh->enableVertexAttribs(); +// const std::vector& vastr = sh->getVA_VBO_Bindings(); +// +// for (std::vector::const_iterator it= vastr.begin(); it != vastr.end(); ++it) +// { +// glBindBuffer(GL_ARRAY_BUFFER, it->vbo_ptr->id()); +// glEnableVertexAttribArray(it->va_id); +// glVertexAttribPointer(it->va_id ,it->vbo_ptr->dataSize(), GL_FLOAT, false, 0, 0); +// } switch(prim) { @@ -115,10 +116,11 @@ void MapRender::draw(Utils::GLSLShader* sh, int prim) break; } - for (std::vector::const_iterator it= vastr.begin(); it != vastr.end(); ++it) - { - glDisableVertexAttribArray(it->va_id); - } +// for (std::vector::const_iterator it= vastr.begin(); it != vastr.end(); ++it) +// { +// glDisableVertexAttribArray(it->va_id); +// } + sh->disableVertexAttribs(); } diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp index 9e88133e528ae3cdf713234ee579d98f423a323b..fdd746a51e794c21836c5f027722386391fa72f5 100644 --- a/src/Algo/Render/topo3Render.cpp +++ b/src/Algo/Render/topo3Render.cpp @@ -24,6 +24,8 @@ #include "Algo/Render/GL2/topo3Render.h" #include "Topology/generic/dart.h" +#include "Utils/shaderSimpleColor.h" +#include "Utils/shaderColorPerVertex.h" #include @@ -40,16 +42,51 @@ namespace GL2 { -topo3Render::topo3Render(): +Topo3Render::Topo3Render(): m_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL) { - glGenBuffersARB(5, m_VBOBuffers); + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + m_vbo3 = new Utils::VBO(); + m_vbo4 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + m_vbo3->setDataSize(3); + m_vbo4->setDataSize(3); + + m_shader1 = new Utils::ShaderSimpleColor(); + m_shader2 = new Utils::ShaderColorPerVertex(); + + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + m_shader2->setAttributePosition(m_vbo0); + m_shader2->setAttributeColor(m_vbo4); + + // registering for auto matrices update + Utils::GLSLShader::registerRunning(m_shader1); + Utils::GLSLShader::registerRunning(m_shader2); + } -topo3Render::~topo3Render() +Topo3Render::~Topo3Render() { - glDeleteBuffersARB(5, m_VBOBuffers); + Utils::GLSLShader::unregisterRunning(m_shader2); + Utils::GLSLShader::unregisterRunning(m_shader1); + + delete m_shader2; + delete m_shader1; + delete m_vbo4; + delete m_vbo3; + delete m_vbo2; + delete m_vbo1; + delete m_vbo0; + if (m_attIndex.map() != NULL) static_cast(m_attIndex.map())->removeAttribute(m_attIndex); @@ -60,29 +97,29 @@ topo3Render::~topo3Render() } -void topo3Render::setDartWidth(float dw) +void Topo3Render::setDartWidth(float dw) { m_topo_dart_width = dw; } -void topo3Render::setRelationWidth(float pw) +void Topo3Render::setRelationWidth(float pw) { m_topo_relation_width = pw; } -void topo3Render::setDartColor(Dart d, float r, float g, float b) +void Topo3Render::setDartColor(Dart d, float r, float g, float b) { float RGB[6]; RGB[0]=r; RGB[1]=g; RGB[2]=b; RGB[3]=r; RGB[4]=g; RGB[5]=b; - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); + m_vbo4->bind(); glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); } -void topo3Render::setAllDartsColor(float r, float g, float b) +void Topo3Render::setAllDartsColor(float r, float g, float b) { - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); + m_vbo4->bind(); GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); for (unsigned int i=0; i < 2*m_nbDarts; ++i) @@ -92,97 +129,118 @@ void topo3Render::setAllDartsColor(float r, float g, float b) *colorDartBuf++ = b; } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[4]); + m_vbo4->bind(); glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); } -void topo3Render::drawDarts() +void Topo3Render::drawDarts() { -// glColor3f(1.0f,1.0f,1.0f); - glLineWidth(m_topo_dart_width); - glPointSize(2.0f*m_topo_dart_width); - - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); - glColorPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_COLOR_ARRAY); + m_shader2->enableVertexAttribs(); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); + glLineWidth(m_topo_dart_width); glDrawArrays(GL_LINES, 0, m_nbDarts*2); - glVertexPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); + // change the stride to take 1/2 vertices + m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); - glColorPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); - glDrawArrays(GL_POINTS, 0, m_nbDarts) - ; - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glPointSize(2.0f*m_topo_dart_width); + glDrawArrays(GL_POINTS, 0, m_nbDarts); + + m_shader2->disableVertexAttribs(); + +// +//// glColor3f(1.0f,1.0f,1.0f); +// glLineWidth(m_topo_dart_width); +// glPointSize(2.0f*m_topo_dart_width); +// +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); +// glColorPointer(3, GL_FLOAT, 0, 0); +// glEnableClientState(GL_COLOR_ARRAY); +// +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_LINES, 0, m_nbDarts*2); +// +// glVertexPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); +// +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); +// glColorPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); +// glDrawArrays(GL_POINTS, 0, m_nbDarts) +// ; +// glDisableClientState(GL_COLOR_ARRAY); +// glDisableClientState(GL_VERTEX_ARRAY); } -void topo3Render::overdrawDart(Dart d, float width, float r, float g, float b) -{ - unsigned int indexDart = m_attIndex[d]; - - glColor3f(r,g,b); - glLineWidth(width); - glPointSize(2.0f*width); - - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); - - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); - glDrawArrays(GL_LINES, indexDart, 2); - - glVertexPointer(3, GL_FLOAT, 0, 0); - glDrawArrays(GL_POINTS, indexDart, 1); - - glDisableClientState(GL_VERTEX_ARRAY); -} -void topo3Render::drawRelation1() +void Topo3Render::drawRelation1() { glLineWidth(m_topo_relation_width); - glColor3f(0.0f,1.0f,1.0f); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); + m_shader1->changeVA_VBO(m_vaId, m_vbo1); + m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); + m_shader1->enableVertexAttribs(); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); - glDisableClientState(GL_VERTEX_ARRAY); + + m_shader1->disableVertexAttribs(); + +// glLineWidth(m_topo_relation_width); +// glColor3f(0.0f,1.0f,1.0f); +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_LINES, 0, m_nbDarts*2); +// glDisableClientState(GL_VERTEX_ARRAY); } -void topo3Render::drawRelation2() +void Topo3Render::drawRelation2() { - glLineWidth(m_topo_relation_width); - glColor3f(1.0f,0.0f,0.0f); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); - glVertexPointer(3, GL_FLOAT, 0, 0); + m_shader1->changeVA_VBO(m_vaId, m_vbo2); + m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shader1->enableVertexAttribs(); - glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_QUADS, 0, m_nbRel2*4); - glDisableClientState(GL_VERTEX_ARRAY); + + m_shader1->disableVertexAttribs(); + +// glLineWidth(m_topo_relation_width); +// glColor3f(1.0f,0.0f,0.0f); +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_QUADS, 0, m_nbRel2*4); +// glDisableClientState(GL_VERTEX_ARRAY); } -void topo3Render::drawRelation3() +void Topo3Render::drawRelation3() { - glLineWidth(m_topo_relation_width); - glColor3f(1.0f,1.0f,0.0f); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); - glVertexPointer(3, GL_FLOAT, 0, 0); + m_shader1->changeVA_VBO(m_vaId, m_vbo3); + m_shader1->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shader1->enableVertexAttribs(); - glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_QUADS, 0, m_nbRel3*4); - glDisableClientState(GL_VERTEX_ARRAY); + + m_shader1->disableVertexAttribs(); + +// glLineWidth(m_topo_relation_width); +// glColor3f(1.0f,1.0f,0.0f); +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_QUADS, 0, m_nbRel3*4); +// glDisableClientState(GL_VERTEX_ARRAY); } -void topo3Render::drawTopo() +void Topo3Render::drawTopo() { drawDarts(); drawRelation1(); @@ -190,10 +248,31 @@ void topo3Render::drawTopo() drawRelation3(); } -void topo3Render::pushColors() + +void Topo3Render::overdrawDart(Dart d, float width, float r, float g, float b) +{ + unsigned int indexDart = m_attIndex[d]; + + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); + m_shader1->enableVertexAttribs(); + + glLineWidth(width); + glDrawArrays(GL_LINES, indexDart, 2); + + glPointSize(2.0f*width); + glDrawArrays(GL_POINTS, indexDart, 1); + + m_shader2->disableVertexAttribs(); + + +} + + +void Topo3Render::pushColors() { m_color_save = new float[6*m_nbDarts]; - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); + m_vbo4->bind(); void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); @@ -201,9 +280,9 @@ void topo3Render::pushColors() } -void topo3Render::popColors() +void Topo3Render::popColors() { - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); + m_vbo4->bind(); void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); @@ -214,7 +293,7 @@ void topo3Render::popColors() } -Dart topo3Render::colToDart(float* color) +Dart Topo3Render::colToDart(float* color) { unsigned int r = (unsigned int)(color[0]*255.0f); unsigned int g = (unsigned int)(color[1]*255.0f); @@ -228,7 +307,7 @@ Dart topo3Render::colToDart(float* color) } -void topo3Render::dartToCol(Dart d, float& r, float& g, float& b) +void Topo3Render::dartToCol(Dart d, float& r, float& g, float& b) { unsigned int lab = d.index + 1; // add one to avoid picking the black of screen @@ -240,7 +319,7 @@ void topo3Render::dartToCol(Dart d, float& r, float& g, float& b) } -Dart topo3Render::picking(unsigned int x, unsigned int y) +Dart Topo3Render::picking(unsigned int x, unsigned int y) { //more easy picking for unsigned int dw = m_topo_dart_width; diff --git a/src/Algo/Render/topoRender.cpp b/src/Algo/Render/topoRender.cpp index 8a44ab9090b1f79a4530ec356632f0265c9b4bd4..38608ac716b9afb3f2ce44f6cbc310c2d9f08c9f 100644 --- a/src/Algo/Render/topoRender.cpp +++ b/src/Algo/Render/topoRender.cpp @@ -24,7 +24,8 @@ #include "Algo/Render/GL2/topoRender.h" - +#include "Utils/shaderSimpleColor.h" +#include "Utils/shaderColorPerVertex.h" namespace CGoGN { @@ -38,43 +39,75 @@ namespace Render namespace GL2 { -topoRender::topoRender(): +TopoRender::TopoRender(): m_topo_dart_width(2.0f), m_topo_relation_width(3.0f) { - glGenBuffersARB(4, m_VBOBuffers); + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + m_vbo3 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + m_vbo3->setDataSize(3); + + m_shader1 = new Utils::ShaderSimpleColor(); + m_shader2 = new Utils::ShaderColorPerVertex(); + + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + m_shader2->setAttributePosition(m_vbo0); + m_shader2->setAttributeColor(m_vbo3); + + // registering for auto matrices update + Utils::GLSLShader::registerRunning(m_shader1); + Utils::GLSLShader::registerRunning(m_shader2); } -topoRender::~topoRender() +TopoRender::~TopoRender() { - glDeleteBuffersARB(4, m_VBOBuffers); + Utils::GLSLShader::unregisterRunning(m_shader2); + Utils::GLSLShader::unregisterRunning(m_shader1); + + delete m_shader2; + delete m_shader1; + delete m_vbo3; + delete m_vbo2; + delete m_vbo1; + delete m_vbo0; + if (m_attIndex.map() != NULL) static_cast(m_attIndex.map())->removeAttribute(m_attIndex); + } -void topoRender::setDartWidth(float dw) +void TopoRender::setDartWidth(float dw) { m_topo_dart_width = dw; } -void topoRender::setRelationWidth(float pw) +void TopoRender::setRelationWidth(float pw) { m_topo_relation_width = pw; } -void topoRender::setDartColor(Dart d, float r, float g, float b) +void TopoRender::setDartColor(Dart d, float r, float g, float b) { float RGB[6]; RGB[0]=r; RGB[1]=g; RGB[2]=b; RGB[3]=r; RGB[4]=g; RGB[5]=b; - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); + m_vbo3->bind(); glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); } -void topoRender::setAllDartsColor(float r, float g, float b) +void TopoRender::setAllDartsColor(float r, float g, float b) { - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); - GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo3->bind(); + GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); for (unsigned int i=0; i < 2*m_nbDarts; ++i) { @@ -83,62 +116,55 @@ void topoRender::setAllDartsColor(float r, float g, float b) *colorDartBuf++ = b; } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[3]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo3->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); } -void topoRender::drawDarts() +void TopoRender::drawDarts() { - glColor3f(1.0f,1.0f,1.0f); - glLineWidth(m_topo_dart_width); - glPointSize(2.0f*m_topo_dart_width); - - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); - glColorPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_COLOR_ARRAY); - - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); + m_shader2->enableVertexAttribs(); + glLineWidth(m_topo_dart_width); glDrawArrays(GL_LINES, 0, m_nbDarts*2); - glVertexPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); - glColorPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); + // change the stride to take 1/2 vertices + m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); + glPointSize(2.0f*m_topo_dart_width); glDrawArrays(GL_POINTS, 0, m_nbDarts); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); + + m_shader2->disableVertexAttribs(); } -void topoRender::drawRelation1() +void TopoRender::drawRelation1() { glLineWidth(m_topo_relation_width); - glColor3f(0.0f,1.0f,1.0f); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); + m_shader1->changeVA_VBO(m_vaId, m_vbo1); + m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); + m_shader1->enableVertexAttribs(); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); - glDisableClientState(GL_VERTEX_ARRAY); + + m_shader1->disableVertexAttribs(); } -void topoRender::drawRelation2() +void TopoRender::drawRelation2() { glLineWidth(m_topo_relation_width); - glColor3f(1.0f,0.0f,0.0f); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); - glDrawArrays(GL_LINES, 0, m_nbRel2*2); - glDisableClientState(GL_VERTEX_ARRAY); + m_shader1->changeVA_VBO(m_vaId, m_vbo2); + m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + m_shader1->disableVertexAttribs(); } -void topoRender::drawTopo() +void TopoRender::drawTopo() { drawDarts(); drawRelation1(); @@ -147,27 +173,87 @@ void topoRender::drawTopo() -void topoRender::overdrawDart(Dart d, float width, float r, float g, float b) +void TopoRender::overdrawDart(Dart d, float width, float r, float g, float b) { unsigned int indexDart = m_attIndex[d]; - glColor3f(r,g,b); + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); + m_shader1->enableVertexAttribs(); + glLineWidth(width); + glDrawArrays(GL_LINES, indexDart, 2); + glPointSize(2.0f*width); + glDrawArrays(GL_POINTS, indexDart, 1); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); + m_shader2->disableVertexAttribs(); +} - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); - glDrawArrays(GL_LINES, indexDart, 2); - glVertexPointer(3, GL_FLOAT, 0, 0); - glDrawArrays(GL_POINTS, indexDart, 1); - glDisableClientState(GL_VERTEX_ARRAY); +Dart TopoRender::colToDart(float* color) +{ + unsigned int r = (unsigned int)(color[0]*255.0f); + unsigned int g = (unsigned int)(color[1]*255.0f); + unsigned int b = (unsigned int)(color[2]*255.0f); + + unsigned int id = r + 255*g +255*255*b; + + if (id==0) + return Dart::nil(); + return Dart(id-1); + +} + +void TopoRender::dartToCol(Dart d, float& r, float& g, float& b) +{ + unsigned int lab = d.index + 1; // add one to avoid picking the black of screen + + r = float(lab%255) / 255.0f; lab = lab/255; + g = float(lab%255) / 255.0f; lab = lab/255; + b = float(lab%255) / 255.0f; lab = lab/255; + if (lab!=0) + std::cerr << "Error picking color, too many darts"<< std::endl; } +Dart TopoRender::picking(unsigned int x, unsigned int y) +{ + //more easy picking for + unsigned int dw = m_topo_dart_width; + m_topo_dart_width+=2; + + // save clear color and set to zero + float cc[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); + + glClearColor(0.0f,0.0f,0.0f,0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glDisable(GL_LIGHTING); + // draw in back buffer (not shown on screen) + drawDarts(); + + // restore dart with + m_topo_dart_width = dw; + + // read the pixel under the mouse in back buffer + glReadBuffer(GL_BACK); + float color[3]; + glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); + + glClearColor(cc[0], cc[1], cc[2], cc[3]); + + return colToDart(color); +} + + + + + + + }//end namespace GL2 diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index 5ed1c2c94b29103056098163308b011e2d039141..d777c1b5360c37eed995ae1ad7bc017c3a273e63 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -83,8 +83,11 @@ GenericMap::~GenericMap() if(isOrbitEmbedded(i)) m_attribs[i].clear(true) ; } - if(m_attributes_registry_map) + if (m_attributes_registry_map) + { delete m_attributes_registry_map; + m_attributes_registry_map = NULL; + } } /**************************************** diff --git a/src/Utils/GLSLShader.cpp b/src/Utils/GLSLShader.cpp index ddb8797b06480f08d8a439e1b8c14649d8928b00..fac0a86583680788692ef45dfc2478c9a24879ff 100644 --- a/src/Utils/GLSLShader.cpp +++ b/src/Utils/GLSLShader.cpp @@ -36,11 +36,11 @@ namespace CGoGN namespace Utils { -unsigned int GLSLShader::CURRENT_OGL_VERSION=3; +unsigned int GLSLShader::CURRENT_OGL_VERSION=2; std::string GLSLShader::DEFINES_GL2=\ "#version 110\n" -"#define PRECISON \n" +"#define PRECISON\n" "#define ATTRIBUTE attribute\n" "#define VARYING_VERT varying\n" "#define VARYING_FRAG varying\n" @@ -49,7 +49,7 @@ std::string GLSLShader::DEFINES_GL2=\ std::string GLSLShader::DEFINES_GL3=\ -"#version 330\n" +"#version 150\n" "#define PRECISON precision highp float;\n" "#define ATTRIBUTE in\n" "#define VARYING_VERT smooth out\n" @@ -61,17 +61,73 @@ std::string* GLSLShader::DEFINES_GL =NULL; std::vector GLSLShader::m_pathes; +std::set< std::pair > GLSLShader::m_registredRunning; + GLSLShader::GLSLShader(): m_vertex_shader_object(0), m_fragment_shader_object(0), m_geom_shader_object(0), - m_program_object(0) + m_program_object(0), + m_uniMat_Proj(-1), + m_uniMat_Model(-1), + m_uniMat_ModelProj(-1), + m_uniMat_Normal(-1), + m_vertex_shader_source(NULL), + m_fragment_shader_source(NULL), + m_geom_shader_source(NULL) { if (DEFINES_GL==NULL) DEFINES_GL = &DEFINES_GL3; } +void GLSLShader::registerRunning(GLSLShader* ptr) +{ + m_registredRunning.insert(std::pair(NULL,ptr)); +} + +void GLSLShader::unregisterRunning(GLSLShader* ptr) +{ + m_registredRunning.erase(std::pair(NULL,ptr)); +} + + +std::string GLSLShader::defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert) +{ + if (CURRENT_OGL_VERSION==3) + { + std::string str("#version 150\n"); + str.append("precision highp float;\n"); + str.append("layout ("); + str.append(primitivesIn); + str.append(") in;\n"); + + str.append("layout ("); + str.append(primitivesOut); + str.append(", max_vertices = "); + std::stringstream ss; + ss << maxVert; + str.append(ss.str()); + str.append(") out;\n"); + str.append("#define VARYING_IN in\n"); + str.append("#define VARYING_OUT smooth out\n"); + str.append("#define POSITION_IN(X) gl_in[X].gl_Position\n"); + return str; + } + else + { + std::string str("#extension GL_EXT_geometry_shader4 : enable\n"); + str.append("#define PRECISION\n"); + str.append("#define ATTRIBUTE attribute\n"); + str.append("#define VARYING_IN varying in\n"); + str.append("#define VARYING_OUT varying out\n"); + str.append("#define POSITION_IN(X) gl_PositionIn[X]\n"); + return str; + } +} + + + bool GLSLShader::areGeometryShadersSupported() { if ( ! glewGetExtension("GL_EXT_geometry_shader4")) return false; @@ -147,21 +203,22 @@ char* GLSLShader::loadSourceFile( const std::string& filename) bool GLSLShader::loadVertexShader( const std::string& filename ) { bool flag; - char *vertex_shader_source; +// char *vertex_shader_source; + if (m_vertex_shader_source) + delete [] m_vertex_shader_source; - vertex_shader_source = loadSourceFile( filename ); + m_vertex_shader_source = loadSourceFile( filename ); - if( !vertex_shader_source ) + if( !m_vertex_shader_source ) { std::cerr << "ERROR - GLSLShader::loadVertexShader() - error occured while loading source file." << std::endl; return false; } - flag = loadVertexShaderSourceString( vertex_shader_source ); - delete [] vertex_shader_source; - + flag = loadVertexShaderSourceString( m_vertex_shader_source ); +// delete [] vertex_shader_source; return flag; } @@ -170,20 +227,22 @@ bool GLSLShader::loadVertexShader( const std::string& filename ) bool GLSLShader::loadFragmentShader(const std::string& filename ) { bool flag; - char *fragment_shader_source; +// char *fragment_shader_source; + if (m_fragment_shader_source) + delete [] m_fragment_shader_source; - fragment_shader_source = loadSourceFile( filename ); + m_fragment_shader_source = loadSourceFile( filename ); - if( !fragment_shader_source ) + if( !m_fragment_shader_source ) { std::cerr << "ERROR - GLSLShader::loadFragmentShader() - error occured while loading source file." << std::endl; return false; } - flag = loadFragmentShaderSourceString( fragment_shader_source ); - delete [] fragment_shader_source; + flag = loadFragmentShaderSourceString( m_fragment_shader_source ); +// delete [] fragment_shader_source; return flag; @@ -193,20 +252,24 @@ bool GLSLShader::loadFragmentShader(const std::string& filename ) bool GLSLShader::loadGeometryShader(const std::string& filename ) { bool flag; - char *geom_shader_source; +// char *geom_shader_source; - geom_shader_source = loadSourceFile( filename ); + if (m_geom_shader_source) + delete [] m_geom_shader_source; + m_geom_shader_source = loadSourceFile( filename ); - if( !geom_shader_source ) + + + if( !m_geom_shader_source ) { std::cerr << "ERROR - GLSLShader::loadGeometryShader() - error occured while loading source file." << std::endl; return false; } - flag = loadGeometryShaderSourceString( geom_shader_source ); - delete [] geom_shader_source; + flag = loadGeometryShaderSourceString( m_geom_shader_source ); +// delete [] geom_shader_source; return flag; @@ -410,6 +473,8 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti int status; char *info_log; + m_geom_inputPrimitives = inputGeometryPrimitive; + m_geom_outputPrimitives = outputGeometryPrimitive; /*** check if shaders are loaded ***/ if( !m_vertex_shader_object || !m_fragment_shader_object ) @@ -465,6 +530,11 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti return false; } + m_uniMat_Proj = glGetUniformLocation(m_program_object,"ProjectionMatrix"); + m_uniMat_Model = glGetUniformLocation(m_program_object,"ModelViewMatrix"); + m_uniMat_ModelProj = glGetUniformLocation(m_program_object,"ModelViewProjectionMatrix"); + m_uniMat_Normal = glGetUniformLocation(m_program_object,"NormalMatrix"); + return true; } @@ -502,7 +572,7 @@ bool GLSLShader::link() -bool GLSLShader::bind() +bool GLSLShader::bind() const { if( m_program_object ) { @@ -514,7 +584,7 @@ bool GLSLShader::bind() } -void GLSLShader::unbind() +void GLSLShader::unbind() const { if( m_program_object ) { @@ -553,6 +623,8 @@ GLSLShader::~GLSLShader() glDeleteObjectARB( m_program_object ); } + +// m_registredRunning.erase(this); } @@ -619,6 +691,7 @@ bool GLSLShader::init() bool GLSLShader::loadShaders(const std::string& vs, const std::string& ps) { + std::string vss = findFile(vs); if(!loadVertexShader(vss)) return false; @@ -664,6 +737,22 @@ bool GLSLShader::loadShaders(const std::string& vs, const std::string& ps, const bool GLSLShader::loadShadersFromMemory(const char* vs, const char* fs) { + if (m_vertex_shader_source) + delete [] m_vertex_shader_source; + + unsigned int sz = strlen(vs); + m_vertex_shader_source = new char[sz+1]; + strcpy(m_vertex_shader_source,vs); + + + if (m_fragment_shader_source) + delete [] m_fragment_shader_source; + + sz = strlen(fs); + m_fragment_shader_source = new char[sz+1]; + strcpy(m_fragment_shader_source,fs); + + if(!loadVertexShaderSourceString(vs)) return false; if(!loadFragmentShaderSourceString(fs)) return false; @@ -678,11 +767,32 @@ bool GLSLShader::loadShadersFromMemory(const char* vs, const char* fs) bool GLSLShader::loadShadersFromMemory(const char* vs, const char* fs, const char* gs, GLint inputGeometryPrimitive,GLint outputGeometryPrimitive) { + + if (m_vertex_shader_source) + delete [] m_vertex_shader_source; + + unsigned int sz = strlen(vs); + m_vertex_shader_source = new char[sz+1]; + strcpy(m_vertex_shader_source,vs); + + if (m_fragment_shader_source) + delete [] m_fragment_shader_source; + + sz = strlen(fs); + m_fragment_shader_source = new char[sz+1]; + strcpy(m_fragment_shader_source,fs); + + if (m_geom_shader_source) + delete [] m_geom_shader_source; + + sz = strlen(gs); + m_geom_shader_source = new char[sz+1]; + strcpy(m_geom_shader_source,gs); + if(!loadVertexShaderSourceString(vs)) return false; if(!loadFragmentShaderSourceString(fs)) return false; -// bool geomShaderLoaded = loadGeometryShaderSourceString(gs); if(!loadGeometryShaderSourceString(gs)) return false; if(!create(inputGeometryPrimitive,outputGeometryPrimitive)) @@ -695,6 +805,76 @@ bool GLSLShader::loadShadersFromMemory(const char* vs, const char* fs, const cha } +bool GLSLShader::reloadVertexShaderFromMemory(const char* vs) +{ + + if (m_vertex_shader_source) + delete [] m_vertex_shader_source; + + unsigned int sz = strlen(vs); + m_vertex_shader_source = new char[sz+1]; + strcpy(m_vertex_shader_source,vs); + + if(!loadVertexShaderSourceString(vs)) return false; + return true; +} + +bool GLSLShader::reloadFragmentShaderFromMemory(const char* fs) +{ + if (m_fragment_shader_source) + delete [] m_fragment_shader_source; + + unsigned int sz = strlen(fs); + m_fragment_shader_source = new char[sz+1]; + strcpy(m_fragment_shader_source,fs); + + if(!loadFragmentShaderSourceString(fs)) return false; + return true; +} + +bool GLSLShader::reloadGeometryShaderFromMemory(const char* gs) +{ + if (m_geom_shader_source) + delete [] m_geom_shader_source; + + unsigned int sz = strlen(gs); + m_geom_shader_source = new char[sz+1]; + strcpy(m_geom_shader_source,gs); + + if(!loadGeometryShaderSourceString(gs)) return false; + return true; +} + +bool GLSLShader::recompile() +{ + std::cout << "Recomp: "<< m_vertex_shader_source << std::endl; + + if (m_vertex_shader_source) + if(!loadVertexShaderSourceString(m_vertex_shader_source)) return false; + + if (m_fragment_shader_source) + if(!loadFragmentShaderSourceString(m_fragment_shader_source)) return false; + + if (m_geom_shader_source) + if(!loadGeometryShaderSourceString(m_geom_shader_source)) return false; + + if(!create(m_geom_inputPrimitives,m_geom_outputPrimitives)) + { + std::cout << "Unable to create the shaders !" << std::endl; + return false; + } + + m_uniMat_Proj = glGetUniformLocation(m_program_object,"ProjectionMatrix"); + m_uniMat_Model = glGetUniformLocation(m_program_object,"ModelViewMatrix"); + m_uniMat_ModelProj = glGetUniformLocation(m_program_object,"ModelViewProjectionMatrix"); + m_uniMat_Normal = glGetUniformLocation(m_program_object,"NormalMatrix"); + + restoreUniformsAttribs(); + + return true; +} + + bool GLSLShader::validateProgram() { if(!m_program_object) @@ -792,33 +972,40 @@ void GLSLShader::unbindVBO(VBO* ptr) } } -void GLSLShader::bindVA_VBO(const std::string& name, VBO& vbo) +unsigned int GLSLShader::bindVA_VBO(const std::string& name, VBO* vbo) { - vbo.ref(this); + vbo->ref(this); GLint idVA = glGetAttribLocation(this->m_program_object, name.c_str()); //valid ? if (idVA < 0) { std::cerr << "GLSLShader: Attribute "<::iterator it = m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) { if (it->va_id == idVA) { - it->vbo_ptr = &vbo; - return; + it->vbo_ptr = vbo; + return (it - m_va_vbo_binding.begin()); } } // new one: VAStr temp; temp.va_id = idVA; - temp.vbo_ptr = &vbo; + temp.vbo_ptr = vbo; m_va_vbo_binding.push_back(temp); + return (m_va_vbo_binding.size() -1); +} + +void GLSLShader::changeVA_VBO(unsigned int id, VBO* vbo) +{ + m_va_vbo_binding[id].vbo_ptr = vbo; } + void GLSLShader::unbindVA(const std::string& name) { GLint idVA = glGetAttribLocation(this->m_program_object, name.c_str()); @@ -864,13 +1051,36 @@ void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& mo { this->bind(); glm::mat4 PMV = projection*modelview; - this->setuniformf<16>("ModelViewProjectionMatrix", &PMV[0][0]); + glm::mat4 normalMatrix = glm::gtx::inverse_transpose::inverseTranspose(modelview); - this->setuniformf<16>("ModelViewMatrix", &modelview[0][0]); - glm::mat4 normalMatrix = glm::gtx::inverse_transpose::inverseTranspose(modelview); - this->setuniformf<16>("NormalMatrix", &normalMatrix[0][0]); + if (m_uniMat_Proj>=0) + glUniformMatrix4fv(m_uniMat_Proj, 1 , false, &projection[0][0]); + if (m_uniMat_Model>=0) + glUniformMatrix4fv(m_uniMat_Model, 1 , false, &modelview[0][0]); + if (m_uniMat_ModelProj>=0) + glUniformMatrix4fv(m_uniMat_ModelProj, 1 , false, &PMV[0][0]); + if (m_uniMat_Normal>=0) + glUniformMatrix4fv(m_uniMat_Normal, 1 , false, &normalMatrix[0][0]); + +} + +void GLSLShader::enableVertexAttribs(unsigned int stride) const +{ + this->bind(); + for (std::vector::const_iterator it= m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) + { + glBindBuffer(GL_ARRAY_BUFFER, it->vbo_ptr->id()); + glEnableVertexAttribArray(it->va_id); + glVertexAttribPointer(it->va_id ,it->vbo_ptr->dataSize(), GL_FLOAT, false, stride, 0); + + } +} +void GLSLShader::disableVertexAttribs() const +{ + for (std::vector::const_iterator it= m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) + glEnableVertexAttribArray(it->va_id); } } // namespace Utils diff --git a/src/Utils/pointLine.cpp b/src/Utils/pointLine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8720f973bc103b9473bb4e60568b8356a92bc016 --- /dev/null +++ b/src/Utils/pointLine.cpp @@ -0,0 +1,120 @@ +/******************************************************************************* +* 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/pointLine.h" + +namespace CGoGN +{ +namespace Utils +{ + + +std::string PointLine::vertexShaderText = +"ATTRIBUTE vec3 VertexPosition;\n" +"ATTRIBUTE vec3 Data\n;" +"VARYING_VERT vec3 DataVector;\n" +"void main()\n" +"{\n" +" gl_Position = vec4(VertexPosition,1.0);\n" +" DataVector = Data;\n" +"}"; + + + +std::string PointLine::geometryShaderText = +"uniform float scale;\n" +"uniform mat4 ModelViewProjectionMatrix;\n" +"VARYING_IN vec3 DataVector[];\n" +"void main()\n" +"{\n" +" gl_Position = ModelViewProjectionMatrix * POSITION_IN(0);\n" +" EmitVertex();\n" +" vec4 P2 = POSITION_IN(0)+vec4(scale*DataVector[0],0.0);\n" +" gl_Position = ModelViewProjectionMatrix * P2;\n" +" EmitVertex();\n" +" EndPrimitive();\n" +"}"; + + +std::string PointLine::fragmentShaderText = +"uniform vec3 color;\n" +"void main(void)\n" +"{\n" +" gl_FragColor = vec4(color,0.0);\n" +"}"; + + + +PointLine::PointLine(float scale, const Geom::Vec3f& color) +{ + std::string glxvert(*GLSLShader::DEFINES_GL); + glxvert.append(vertexShaderText); + + std::string glxgeom = GLSLShader::defines_Geom("points","line_strip",4); + glxgeom.append(geometryShaderText); + + std::string glxfrag(*GLSLShader::DEFINES_GL); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_POINTS, GL_LINE_STRIP); + + bind(); + m_uniform_scale = glGetUniformLocation(program_handler(),"scale"); + m_uniform_color = glGetUniformLocation(program_handler(),"color"); + glUniform1f(m_uniform_scale, scale); + glUniform3fv(m_uniform_color, 1, color.data()); + unbind(); + +} + + +unsigned int PointLine::setAttributePosition(VBO* vbo) +{ + return bindVA_VBO("VertexPosition", vbo); +} + + +unsigned int PointLine::setAttributeData(VBO* vbo) +{ + return bindVA_VBO("Data", vbo); +} + + + +void PointLine::setScale(float scale) +{ + bind(); + glUniform1f(m_uniform_scale, scale); + unbind(); +} + +void PointLine::setColor(const Geom::Vec3f& color) +{ + bind(); + glUniform3fv(m_uniform_color, 1, color.data()); + unbind(); +} + +} +} diff --git a/src/Utils/pointSprite.cpp b/src/Utils/pointSprite.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bd335cc7c7e4c5e3a40090e7489a3150a317131 --- /dev/null +++ b/src/Utils/pointSprite.cpp @@ -0,0 +1,218 @@ +/******************************************************************************* +* 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/pointSprite.h" + +namespace CGoGN +{ +namespace Utils +{ + +GLuint PointSprite::m_idTexture=0; +GLuint PointSprite::m_uniform_texture=0; + +unsigned char* PointSprite::m_ptrSphere=NULL; + + +std::string PointSprite::vertexShaderText = +"ATTRIBUTE vec3 VertexPosition;\n" +"void main ()\n" +"{\n" +" gl_Position = vec4(VertexPosition,1.0);\n" +"}"; + + + +std::string PointSprite::geometryShaderText = +"uniform float size;\n" +"uniform mat4 ModelViewMatrix;\n" +"uniform mat4 ProjectionMatrix;\n" +"VARYING_OUT vec2 texCoord;\n" +"VARYING_OUT vec2 positionFragIn;\n" +"VARYING_OUT vec4 mvpFragIn;\n" +"void main()\n" +"{\n" +" vec4 posCenter = ModelViewMatrix * POSITION_IN(0);\n" +" vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);\n" +" positionFragIn = posCenter.zw;\n" +" mvpFragIn.x = ProjectionMatrix[2][2];\n" +" mvpFragIn.y = ProjectionMatrix[3][2];\n" +" mvpFragIn.z = ProjectionMatrix[2][3];\n" +" mvpFragIn.w = ProjectionMatrix[3][3];\n" +" texCoord = vec2(0.0,1.0);\n" +" gl_Position = ProjectionMatrix * pos;\n" +" EmitVertex();\n" +" pos = posCenter + vec4(-size, -size, 0.0, 0.0);\n" +" texCoord = vec2(0.0,0.0);\n" +" gl_Position = ProjectionMatrix * pos;\n" +" EmitVertex();\n" +" pos = posCenter + vec4( size, size, 0.0, 0.0);\n" +" texCoord = vec2(1.0,1.0);\n" +" gl_Position = ProjectionMatrix * pos;\n" +" EmitVertex();\n" +" pos = posCenter + vec4( size,-size, 0.0, 0.0);\n" +" texCoord = vec2(1.0,0.0);\n" +" gl_Position = ProjectionMatrix * pos;\n" +" EmitVertex();\n" +" EndPrimitive();\n" +"}"; + + +std::string PointSprite::fragmentShaderText = +"uniform sampler2D SpriteTexture;\n" +"uniform float size;\n" +"uniform vec3 color;\n" +"VARYING_FRAG vec2 texCoord;\n" +"VARYING_FRAG vec2 positionFragIn;\n" +"VARYING_FRAG vec4 mvpFragIn;\n" +"void main(void)\n" +"{\n" +" float lum = texture2D(SpriteTexture, texCoord).s;\n" +" if (lum==0.0)\n" +" discard;\n" +" vec2 v = texCoord-vec2(0.5,0.5);\n" +" float z = size * sqrt(1.0-dot(v,v));\n" +" vec2 zfrag = positionFragIn + vec2(z,0.0);\n" +" gl_FragDepth = 0.5 + 0.5 * dot(zfrag, mvpFragIn.xy) / dot(zfrag, mvpFragIn.zw);\n" +" gl_FragColor = vec4(color,0.0)*lum;\n" +"}"; + + +PointSprite::PointSprite(float radius) +{ + + std::string glxvert(*GLSLShader::DEFINES_GL); + glxvert.append(vertexShaderText); + + + std::string glxgeom = GLSLShader::defines_Geom("points","triangle_strip",4); + glxgeom.append(geometryShaderText); + + std::string glxfrag(*GLSLShader::DEFINES_GL); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_POINTS, GL_TRIANGLE_STRIP); + + bind(); + m_uniform_size = glGetUniformLocation(program_handler(),"size"); + m_uniform_color = glGetUniformLocation(program_handler(),"color"); + glUniform1f(m_uniform_size, radius); + unbind(); + + // load texture + if (m_ptrSphere == NULL) + { + computeSphere(); + glGenTextures(1, &m_idTexture); + glBindTexture(GL_TEXTURE_2D, m_idTexture); + glTexImage2D(GL_TEXTURE_2D, 0, 1, WIDTHSPRITE, WIDTHSPRITE, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (GLvoid*)m_ptrSphere); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + m_uniform_texture = glGetUniformLocation(program_handler(),"SpriteTexture"); +} + +PointSprite::~PointSprite() +{ + if (m_ptrSphere!=NULL) + { + delete[] m_ptrSphere; + glDeleteTextures(1, &m_idTexture); + } +} + + +unsigned int PointSprite::setAttributePosition(VBO* vbo) +{ + return bindVA_VBO("VertexPosition", vbo); +} + + +void PointSprite::predraw(const Geom::Vec3f& color) +{ + bind(); + glUniform1i(m_uniform_texture,0); + glUniform3fv(m_uniform_color, 1, color.data()); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_idTexture); + glEnable(GL_TEXTURE_2D); +} + + +void PointSprite::postdraw() +{ + glDisable(GL_TEXTURE_2D); + unbind(); +} + + +void PointSprite::setSize(float radius) +{ + bind(); + glUniform1f(m_uniform_size, radius); + unbind(); +} + + + +void PointSprite::computeSphere() +{ + if (m_ptrSphere==NULL) // normaly useless + { + m_ptrSphere = new unsigned char[WIDTHSPRITE*WIDTHSPRITE]; + } + unsigned char* ptr = m_ptrSphere; + + Geom::Vec3f eye(0.0,.0,-1.0); + Geom::Vec3f light(5,3,10); + light.normalize(); + float r2 = float((WIDTHSPRITE-1)*(WIDTHSPRITE-1))/4.0f; + float mid = 0.5f - float(WIDTHSPRITE/2); + + for (unsigned int i=0; i= a) + { + float z = sqrt(r2-a); + Geom::Vec3f P(x,y,z); + P.normalize(); + float col = P*light; + if (col < 0.0f) + col= 0.02; // ambiant + + *ptr++ = (unsigned char)(255.0f*col); + } + else + *ptr++ = (unsigned char)0; + } + } +} + +} +} diff --git a/src/Utils/qtSimple.cpp b/src/Utils/qtSimple.cpp index 852fcad75becf69d35cdf17826e12a1e5deef1f1..f396b91d3426208cf490c34ac8ff1bae5d689c94 100644 --- a/src/Utils/qtSimple.cpp +++ b/src/Utils/qtSimple.cpp @@ -24,7 +24,9 @@ #include "Utils/qtSimple.h" #include "Utils/qtgl.h" - +#include "Utils/GLSLShader.h" +#include "glm/gtc/matrix_transform.hpp" +#include "glm/gtc/type_precision.hpp" namespace CGoGN { @@ -37,6 +39,7 @@ namespace QT SimpleQT::SimpleQT(): m_dock(NULL) { + m_glWidget = new GLWidget(this); setCentralWidget(m_glWidget); setWindowTitle(tr("CGoGN")); @@ -104,6 +107,13 @@ void SimpleQT::setHelpMsg(const std::string& msg) +void SimpleQT::glMousePosition(int& x, int& y) +{ + QPoint xy = m_glWidget->mapFromGlobal(QCursor::pos()); + x = xy.x(); + y = m_glWidget->getHeight()- xy.y(); +} + QDockWidget* SimpleQT::addEmptyDock() { m_dock = new QDockWidget(tr("Control"), this); @@ -143,6 +153,16 @@ void SimpleQT::dockTitle(const char* dockTitle) m_dock->setWindowTitle(tr(dockTitle)); } +void SimpleQT::statusMsg(const char* msg) +{ + if (msg) + { + QString message = tr(msg); + statusBar()->showMessage(message); + } + else + statusBar()->hide(); +} void SimpleQT::setCallBack( const QObject* sender, const char* signal, const char* method) { @@ -205,6 +225,42 @@ void SimpleQT::updateGL() m_glWidget->updateGL(); } +void SimpleQT::updateGLMatrices() +{ + cb_updateMatrix(); + m_glWidget->updateGL(); +} + +void SimpleQT::cb_updateMatrix() +{ + for (std::set< std::pair >::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); + } + +} + +void SimpleQT::synchronize(SimpleQT* sqt) +{ + m_projection_matrix = sqt->m_projection_matrix; + m_modelView_matrix = sqt->m_modelView_matrix; + for (unsigned int i=0; i< 4; ++i) + { + m_curquat[i] = sqt->m_curquat[i]; + m_lastquat[i] = sqt->m_lastquat[i]; + } + m_trans_x = sqt->trans_x(); + m_trans_y = sqt->trans_y(); + m_trans_z = sqt->trans_z(); + + SimpleQT::cb_updateMatrix(); + + m_glWidget->modelModified(); + m_glWidget->updateGL(); +} + + void SimpleQT::add_menu_entry(const std::string label, const char* method ) { @@ -214,27 +270,68 @@ void SimpleQT::add_menu_entry(const std::string label, const char* method ) } - -//QMenu *fileMenu - - /** - * initialize popup menu + * initialize app menu */ void SimpleQT::init_app_menu() { m_appMenu->clear(); } -//void SimpleQT::contextMenuEvent(QContextMenuEvent *event) -//{ -// QMenu menu(this); -// -// for (std::vector::iterator act = m_popup_actions.begin(); act != m_popup_actions.end(); ++act) -// menu.addAction(*act); -// -// menu.exec(event->globalPos()); -//} +void SimpleQT::registerRunning(GLSLShader* ptr) +{ + GLSLShader::m_registredRunning.insert(std::pair(this,ptr)); +} + +void SimpleQT::unregisterRunning(GLSLShader* ptr) +{ + GLSLShader::m_registredRunning.erase(std::pair(this,ptr)); +} + + +GLfloat SimpleQT::getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB, int radius) +{ + // get Z from depth buffer +// int yy = m_glWidget->getHeight() - y; + int yy = y; + GLfloat depth; + glReadPixels(x, yy,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&depth); + + + glm::i32vec4 viewport; + glGetIntegerv(GL_VIEWPORT,&(viewport[0])); + + glm::vec3 win(x, yy, 0.0f); + + glm::vec3 P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport); + + rayA[0] = P[0]; + rayA[1] = P[1]; + rayA[2] = P[2]; + + win[2]=depth; + + P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport); + rayB[0] = P[0]; + rayB[1] = P[1]; + rayB[2] = P[2]; + + if (depth == 1.0f) // depth vary in [0-1] + depth = 0.5f; + + win[0] += radius; + + P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport); + Geom::Vec3f Q; + Q[0] = P[0]; + Q[1] = P[1]; + Q[2] = P[2]; + + // compute & return distance + Q -= rayB; + return float(Q.norm()); +} + } diff --git a/src/Utils/qtgl.cpp b/src/Utils/qtgl.cpp index fd71e31aafdf77d4f30186ef3d013eec145d4f9c..1c646c38800c5ec5e9ab0406c03688d2ae3380a2 100644 --- a/src/Utils/qtgl.cpp +++ b/src/Utils/qtgl.cpp @@ -45,14 +45,14 @@ GLWidget::GLWidget(SimpleQT* cbs, QWidget *parent) : glewInit(); newModel = 1; - trans_x=0.; - trans_y=0.; + m_cbs->trans_x()=0.; + m_cbs->trans_y()=0.; float f = FAR_PLANE; - trans_z=-f/5.0f; + m_cbs->trans_z()=-f/5.0f; foc=2.0f; // init trackball - trackball(curquat, 0.0f, 0.0f, 0.0f, 0.0f); + trackball(m_cbs->curquat(), 0.0f, 0.0f, 0.0f, 0.0f); } GLWidget::~GLWidget() @@ -98,10 +98,10 @@ void GLWidget::recalcModelView() oglPopModelViewMatrix(); oglPushModelViewMatrix(); // positionne l'objet / mvt souris - oglTranslate(trans_x,trans_y,trans_z); + oglTranslate(m_cbs->trans_x(),m_cbs->trans_y(),m_cbs->trans_z()); // tourne l'objet / mvt souris - build_rotmatrixgl3(m, curquat); + build_rotmatrixgl3(m, m_cbs->curquat()); // update matrice m_cbs->modelViewMatrix() *= m; @@ -174,25 +174,25 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event) case Qt::RightButton: { float wl; - if (trans_z > -20.0f) + if (m_cbs->trans_z() > -20.0f) wl = 20.0f/foc; else - wl = -2.0f*trans_z/foc; - trans_x += wl/W*(x - beginx); - trans_y += wl/H*(beginy - y); + wl = -2.0f*m_cbs->trans_z()/foc; + m_cbs->trans_x() += wl/W*(x - beginx); + m_cbs->trans_y() += wl/H*(beginy - y); } break; case Qt::MidButton: { float wl = -0.2f*FAR_PLANE/foc; - trans_z -= wl/W*(x - beginx); - trans_z -= wl/H*(y - beginy); + m_cbs->trans_z() -= wl/W*(x - beginx); + m_cbs->trans_z() -= wl/H*(y - beginy); } break; case Qt::LeftButton: - trackball(lastquat, (2.0f * beginx - W) / W,(H - 2.0f * beginy) / H, + trackball(m_cbs->lastquat(), (2.0f * beginx - W) / W,(H - 2.0f * beginy) / H, (2.0f * x - W) / W,(H - 2.0f * y) / H ); - add_quats(lastquat, curquat, curquat); + add_quats(m_cbs->lastquat(), m_cbs->curquat(), m_cbs->curquat()); break; } beginx = x; @@ -209,9 +209,9 @@ void GLWidget::wheelEvent ( QWheelEvent * event ) float wl = -0.02f*FAR_PLANE/foc; if (event->delta() > 0) - trans_z += wl; + m_cbs->trans_z() += wl; else - trans_z -= wl; + m_cbs->trans_z() -= wl; newModel = 1; updateGL(); @@ -230,9 +230,7 @@ void GLWidget:: keyPressEvent(QKeyEvent* event) if ( (k>=65) && (k<=91) && (event->modifiers() != Qt::ShiftModifier) ) k+=32; - std::cout << "Pressed:"<< std::endl; - - if (m_cbs) + if (m_cbs) m_cbs->cb_keyPress(k); } diff --git a/src/Utils/shaderColorPerVertex.cpp b/src/Utils/shaderColorPerVertex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b4200b38952395d6c32408bd2a2075b7b59912a --- /dev/null +++ b/src/Utils/shaderColorPerVertex.cpp @@ -0,0 +1,88 @@ +/******************************************************************************* +* 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 +#include "Utils/shaderColorPerVertex.h" + +namespace CGoGN +{ +namespace Utils +{ + +std::string ShaderColorPerVertex::vertexShaderText = + "ATTRIBUTE vec3 VertexPosition;\n" + "ATTRIBUTE vec3 VertexColor;\n" + "uniform mat4 ModelViewProjectionMatrix;\n" + "VARYING_VERT vec3 color;\n" + "INVARIANT_POS;\n" + "void main ()\n" + "{\n" + " gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n" + " color = VertexColor;\n" + "}"; + + +std::string ShaderColorPerVertex::fragmentShaderText = + "PRECISON;\n" + "VARYING_FRAG vec3 color;\n" + "FRAG_OUT_DEF;\n" + "void main()\n" + "{\n" + " gl_FragColor=vec4(color,0.0);\n" + "}"; + + +ShaderColorPerVertex::ShaderColorPerVertex() +{ + std::string glxvert(*GLSLShader::DEFINES_GL); + glxvert.append(vertexShaderText); + + std::string glxfrag(*GLSLShader::DEFINES_GL); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str()); +} + + +unsigned int ShaderColorPerVertex::setAttributePosition(VBO* vbo) +{ + m_vboPos = vbo; + return bindVA_VBO("VertexPosition", vbo); +} + +unsigned int ShaderColorPerVertex::setAttributeColor(VBO* vbo) +{ + m_vboCol = vbo; + return bindVA_VBO("VertexColor", vbo); +} + +void ShaderColorPerVertex::restoreUniformsAttribs() +{ + bindVA_VBO("VertexPosition", m_vboPos); + bindVA_VBO("VertexColor", m_vboCol); +} + +} +} + diff --git a/src/Utils/shaderFlat.cpp b/src/Utils/shaderFlat.cpp index de5826ff9d4976d3aac3abcdcc093cb6bc7bd41c..b7bcf37a17d1ef1577e0ccc604a365ea73e83e12 100644 --- a/src/Utils/shaderFlat.cpp +++ b/src/Utils/shaderFlat.cpp @@ -34,89 +34,157 @@ namespace CGoGN namespace Utils { -std::string ShaderFlat::vertexShaderText = "\ -#version 330 \n\ -in vec3 VertexPosition;\n\ -void main()\n\ -{\n\ - gl_Position = vec4(VertexPosition, 1.0f);\n\ -}"; - - -std::string ShaderFlat::geometryShaderText = "\ -#version 330\n\ -layout (triangles) in;\n\ -layout (triangle_strip, max_vertices = 3 ) out;\n\ -uniform float explode;\n\ -uniform mat4 ModelViewProjectionMatrix;\n\ -uniform mat4 NormalMatrix;\n\ -uniform mat4 ModelViewMatrix;\n\ -uniform vec3 lightPosition;\n\ -uniform vec4 materialDiffuse;\n\ -uniform vec4 materialAmbient;\n\ -flat out vec4 ColorFS;\n\ -void main(void)\n\ -{\n\ - vec3 v1 = gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz;\n\ - vec3 v2 = gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz;\n\ - vec3 N = cross(v1,v2);\n\ - N = normalize (vec3(NormalMatrix*vec4(N,0.0))); \n\ - vec3 center = gl_in[0].gl_Position.xyz + gl_in[1].gl_Position.xyz + gl_in[2].gl_Position.xyz; \n\ - center /= 3.0;\n\ - vec4 newPos = ModelViewMatrix * vec4(center,0.0);\n\ - vec3 L = normalize (lightPosition - newPos.xyz);\n\ - float lambertTerm = dot(N,L);\n\ - ColorFS = materialAmbient;\n\ - if(lambertTerm > 0.0)\n\ - ColorFS = materialDiffuse * lambertTerm;\n\ - int i;\n\ - for(i=0; i< gl_in.length(); i++)\n\ - {\n\ - vec3 displ = center - gl_in[i].gl_Position.xyz;\n\ - displ *= explode ;\n\ - gl_Position = gl_in[i].gl_Position + vec4(displ.xyz,0.0);\n\ - gl_Position = ModelViewProjectionMatrix * gl_Position;\n\ - EmitVertex();\n\ - }\n\ - EndPrimitive();\n\ -}"; - -std::string ShaderFlat::fragmentShaderText = "\ -#version 330\n\ -precision highp float;\n\ -flat in vec4 ColorFS; \n\ -out vec4 FragColor;\n\ -void main()\n\ -{\n\ - FragColor = ColorFS;\n\ -}"; +std::string ShaderFlat::vertexShaderText = +"ATTRIBUTE vec3 VertexPosition;\n" +"void main()\n" +"{\n" +" gl_Position = vec4(VertexPosition, 1.0);\n" +"}"; + + +std::string ShaderFlat::geometryShaderText = +"uniform float explode;\n" +"uniform mat4 ModelViewProjectionMatrix;\n" +"uniform mat4 NormalMatrix;\n" +"uniform mat4 ModelViewMatrix;\n" +"uniform vec3 lightPosition;\n" +"uniform vec4 diffuse;\n" +"uniform vec4 ambient;\n" +"VARYING_OUT vec4 ColorFS;\n" +"void main(void)\n" +"{\n" +" vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;\n" +" vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;\n" +" vec3 N = cross(v1,v2);\n" +" N = normalize (vec3(NormalMatrix*vec4(N,0.0))); \n" +" vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz; \n" +" center /= 3.0;\n" +" vec4 newPos = ModelViewMatrix * vec4(center,0.0);\n" +" vec3 L = normalize (lightPosition - newPos.xyz);\n" +" float lambertTerm = dot(N,L);\n" +" ColorFS = ambient;\n" +" if(lambertTerm > 0.0)\n" +" ColorFS += diffuse * lambertTerm;\n" +" int i;\n" +" for(i=0; i< gl_in.length(); i++)\n" +" {\n" +" vec4 pos = explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);\n" +" gl_Position = ModelViewProjectionMatrix * pos;\n" +" EmitVertex();\n" +" }\n" +" EndPrimitive();\n" +"}"; + +std::string ShaderFlat::fragmentShaderText = +"VARYING_FRAG vec4 ColorFS; \n" +"void main()\n" +"{\n" +" gl_FragColor = ColorFS;\n" +"}"; ShaderFlat::ShaderFlat() { - this->loadShadersFromMemory(vertexShaderText.c_str(), fragmentShaderText.c_str(),geometryShaderText.c_str(),GL_TRIANGLES, GL_TRIANGLE_STRIP); - m_unif_ambiant = glGetUniformLocation(this->program_handler(),"materialAmbient"); - m_unif_diffuse = glGetUniformLocation(this->program_handler(),"materialDiffuse"); - m_unif_lightPos = glGetUniformLocation(this->program_handler(),"lightPosition"); + std::string glxvert(*GLSLShader::DEFINES_GL); + glxvert.append(vertexShaderText); + + std::string glxgeom = GLSLShader::defines_Geom("triangles","triangle_strip",3); + glxgeom.append(geometryShaderText); + + std::string glxfrag(*GLSLShader::DEFINES_GL); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_TRIANGLES, GL_TRIANGLE_STRIP); + + getLocations(); //Default values - Geom::Vec4f amb(0.05f,0.05f,0.1f,0.0f); - Geom::Vec4f diff(0.1f,1.0f,0.1f,0.0f); - Geom::Vec3f lp(10.0f,10.0f,1000.0f); + m_explode=1.0f; + m_ambiant = Geom::Vec4f(0.05f,0.05f,0.1f,0.0f); + m_diffuse = Geom::Vec4f(0.1f,1.0f,0.1f,0.0f); + m_light_pos = Geom::Vec3f(10.0f,10.0f,1000.0f); - setParams(0.9f, amb,diff,lp); + setParams(m_explode, m_ambiant, m_diffuse, m_light_pos); +} + +void ShaderFlat::getLocations() +{ + m_unif_explode = glGetUniformLocation(program_handler(),"explode"); + m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient"); + m_unif_diffuse = glGetUniformLocation(program_handler(),"diffuse"); + m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition"); +} +void ShaderFlat::setAttributePosition(VBO* vbo) +{ + m_vboPos = vbo; + bindVA_VBO("VertexPosition", vbo); } void ShaderFlat::setParams(float expl, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos) { - this->bind(); + m_explode = expl; + m_ambiant = ambiant; + m_diffuse = diffuse; + m_light_pos = lightPos; + + bind(); glUniform1f (m_unif_explode, expl); glUniform4fv(m_unif_ambiant, 1, ambiant.data()); glUniform4fv(m_unif_diffuse, 1, diffuse.data()); - glUniform3fv(m_unif_lightPos, 1,lightPos.data()); + + unbind(); // ?? +} + +void ShaderFlat::setExplode(float explode) +{ + m_explode = explode; + bind(); + glUniform1f (m_unif_explode, explode); +} + + +void ShaderFlat::setAmbiant(const Geom::Vec4f& ambiant) +{ + m_ambiant = ambiant; + bind(); + glUniform4fv(m_unif_ambiant,1, ambiant.data()); +} + +void ShaderFlat::setDiffuse(const Geom::Vec4f& diffuse) +{ + m_diffuse = diffuse; + bind(); + glUniform4fv(m_unif_diffuse,1, diffuse.data()); + +} + + +void ShaderFlat::setLightPosition(const Geom::Vec3f& lp) +{ + m_light_pos = lp; + bind(); + glUniform3fv(m_unif_lightPos,1,lp.data()); +} + + +void ShaderFlat::restoreUniformsAttribs() +{ + m_unif_explode = glGetUniformLocation(program_handler(),"explode"); + m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient"); + m_unif_diffuse = glGetUniformLocation(program_handler(),"diffuse"); + m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition"); + + bind(); + glUniform1f (m_unif_explode, m_explode); + glUniform4fv(m_unif_ambiant, 1, m_ambiant.data()); + glUniform4fv(m_unif_diffuse, 1, m_diffuse.data()); + glUniform3fv(m_unif_lightPos, 1, m_light_pos.data()); + + bindVA_VBO("VertexPosition", m_vboPos); + unbind(); } diff --git a/src/Utils/shaderPhong.cpp b/src/Utils/shaderPhong.cpp index 9d65dadb5818b2c6e6516e2f60b42b7848f8836f..4b9f63bfccf46d7db4edfeb62be6e4be56d04404 100644 --- a/src/Utils/shaderPhong.cpp +++ b/src/Utils/shaderPhong.cpp @@ -136,6 +136,8 @@ void ShaderPhong::sendParams() glUniform3fv(m_unif_lightPos, 1, m_lightPos.data()); } + + void ShaderPhong::setAmbiant(const Geom::Vec4f& ambiant) { this->bind(); @@ -185,8 +187,9 @@ void ShaderPhong::setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffu } -void ShaderPhong::setAttributeColor(VBO& vbo) +unsigned int ShaderPhong::setAttributeColor(VBO* vbo) { + m_vboColor = vbo; if (!m_with_color) { m_with_color=true; @@ -205,12 +208,13 @@ void ShaderPhong::setAttributeColor(VBO& vbo) sendParams(); } // bind th VA with WBO - bindVA_VBO("VertexColor", vbo); + return bindVA_VBO("VertexColor", vbo); } void ShaderPhong::unsetAttributeColor() { + m_vboColor = NULL; if (m_with_color) { m_with_color=false; @@ -227,9 +231,33 @@ void ShaderPhong::unsetAttributeColor() getLocations(); sendParams(); } +} + + +void ShaderPhong::restoreUniformsAttribs() +{ + getLocations(); + sendParams(); + bindVA_VBO("VertexPosition", m_vboPos); + bindVA_VBO("VertexNormal", m_vboNormal); + if (m_vboColor) + bindVA_VBO("VertexColor", m_vboColor); } +unsigned int ShaderPhong::setAttributePosition(VBO* vbo) +{ + m_vboPos=vbo; + return bindVA_VBO("VertexPosition", vbo); +} + +unsigned int ShaderPhong::setAttributeNormal(VBO* vbo) +{ + m_vboNormal = vbo; + return bindVA_VBO("VertexNormal", vbo); +} + + } } diff --git a/src/Utils/shaderSimpleColor.cpp b/src/Utils/shaderSimpleColor.cpp index b81783504e0215b312d55ce4a17736f3c91affea..14bd877ae69b309bac6e2ef44b1c11f3d726d570 100644 --- a/src/Utils/shaderSimpleColor.cpp +++ b/src/Utils/shaderSimpleColor.cpp @@ -25,8 +25,6 @@ #include #include "Utils/shaderSimpleColor.h" - - namespace CGoGN { namespace Utils @@ -74,14 +72,24 @@ ShaderSimpleColor::ShaderSimpleColor() void ShaderSimpleColor::setColor(const Geom::Vec4f& color) { - this->bind(); + m_color = color; + bind(); glUniform4fv(m_unif_color,1, color.data()); } -void ShaderSimpleColor::setAttributePosition(VBO& vbo) +unsigned int ShaderSimpleColor::setAttributePosition(VBO* vbo) +{ + m_vboPos = vbo; + return bindVA_VBO("VertexPosition", vbo); +} + +void ShaderSimpleColor::restoreUniformsAttribs() { - this->bindVA_VBO("VertexPosition", vbo); + m_unif_color = glGetUniformLocation(this->program_handler(),"color"); + bind(); + glUniform4fv(m_unif_color,1, m_color.data()); + bindVA_VBO("VertexPosition", m_vboPos); } diff --git a/src/Utils/text3d.cpp b/src/Utils/text3d.cpp index 43360f18407dbb325b08e7f2eb168e0dd94acafd..7be11831d2528e4bfc1a67da3048598ea636f59e 100644 --- a/src/Utils/text3d.cpp +++ b/src/Utils/text3d.cpp @@ -24,56 +24,115 @@ #include "Utils/text3d.h" +#include "Utils/vbo.h" + namespace CGoGN { namespace Utils { -Strings3D::Strings3D(): +std::string Strings3D::vertexShaderText = +"ATTRIBUTE vec4 VertexPosition;\n" +"uniform mat4 ModelViewMatrix;\n" +"uniform mat4 ProjectionMatrix;\n" +"uniform vec3 strPos;\n" +"uniform float scale;\n" +"VARYING_VERT vec2 tex_coord;\n" +"INVARIANT_POS;\n" +"void main ()\n" +"{\n" +" vec4 pos = ModelViewMatrix * vec4(strPos,1.0) + vec4(VertexPosition[0]*scale,VertexPosition[1]*scale,0.0,0.0);\n" +" tex_coord = vec2(VertexPosition[2],VertexPosition[3]);\n" +" gl_Position = ProjectionMatrix * pos;\n" +"}"; + +std::string Strings3D::fragmentShaderText1 = +"VARYING_FRAG vec2 tex_coord;\n" +"uniform sampler2D FontTexture;\n" +"uniform vec3 color;\n" +"FRAG_OUT_DEF;\n" +"void main (void)\n" +"{\n" +" float lum = texture2D(FontTexture, tex_coord).s;\n"; + +std::string Strings3D::fragmentShaderText2 = +" gl_FragColor = vec4(color,0.0)*lum;\n" +"}"; + +GLuint Strings3D::m_idTexture = 0xffffffff; +ILuint Strings3D::m_imgName; + +Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc): m_nbChars(0) -{ } - -void Strings3D::init(float scale) { - glGenBuffersARB(1, &m_vbo1); - m_shader.loadShaders("text.vert", "text.frag"); - m_shader.bind(); - m_uniform_position = glGetUniformLocationARB(m_shader.program_handler(),"strPos"); - m_uniform_color = glGetUniformLocationARB(m_shader.program_handler(),"color"); - m_uniform_scale = glGetUniformLocationARB(m_shader.program_handler(),"scale"); - glUniform1f(m_uniform_scale, scale); - m_shader.unbind(); + if (m_idTexture == 0xffffffff) + { + std::string font_finename = Utils::GLSLShader::findFile("font_cgogn.png"); + ilInit(); + ilOriginFunc(IL_ORIGIN_UPPER_LEFT); + ilEnable(IL_ORIGIN_SET); + + ilGenImages(1,&m_imgName); + ilBindImage(m_imgName); + ilLoadImage(font_finename.c_str()); + + glGenTextures( 1, &m_idTexture); + glBindTexture(GL_TEXTURE_2D, m_idTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, WIDTHTEXTURE, HEIGHTTEXTURE, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (GLvoid*)(ilGetData())); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } - // load texture - std::string font_finename = Utils::GLSLShader::findFile("font_cgogn.png"); - ilInit(); - ilOriginFunc(IL_ORIGIN_UPPER_LEFT); - ilEnable(IL_ORIGIN_SET); - ilGenImages(1,&m_imgName); - ilBindImage(m_imgName); - ilLoadImage(font_finename.c_str()); - glGenTextures( 1, &m_idTexture); - glBindTexture(GL_TEXTURE_2D, m_idTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, WIDTHTEXTURE, HEIGHTTEXTURE, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (GLvoid*)(ilGetData())); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - m_uniform_texture = glGetUniformLocationARB(m_shader.program_handler(),"FontTexture"); -} + std::string glxvert(*GLSLShader::DEFINES_GL); + glxvert.append(vertexShaderText); + std::string glxfrag(*GLSLShader::DEFINES_GL); + + glxfrag.append(fragmentShaderText1); + + std::string background; + if (!withBackground) + glxfrag.append("if (lum==0.0) discard;\n"); + else if (bgc*bgc > 0.0) + { + std::stringstream ss; + ss << " if (lum==0.0) gl_FragColor=vec4("; + ss << bgc[0]<<","<setDataSize(4); + m_vbo1->ref(this); + + bindVA_VBO("VertexPosition", m_vbo1); + + bind(); + m_uniform_position = glGetUniformLocation(program_handler(),"strPos"); + m_uniform_color = glGetUniformLocation(program_handler(),"color"); + m_uniform_scale = glGetUniformLocation(program_handler(),"scale"); + m_uniform_texture = glGetUniformLocation(program_handler(),"FontTexture"); + glUniform1f(m_uniform_scale, 1.0f); + unbind(); +} void Strings3D::setScale(float scale) { - m_shader.bind(); + bind(); glUniform1f(m_uniform_scale, scale); - m_shader.unbind(); + unbind(); } Strings3D::~Strings3D() { ilDeleteImages(1,&m_imgName); - glDeleteBuffers(1, &m_vbo1); + + delete m_vbo1; } unsigned int Strings3D::addString(const std::string& str) @@ -144,9 +203,9 @@ void Strings3D::sendToVBO() // send coord / texcoord of strings // alloc buffer - glBindBufferARB(GL_ARRAY_BUFFER, m_vbo1); - glBufferDataARB(GL_ARRAY_BUFFER, m_nbChars*16*sizeof(float), 0, GL_STREAM_DRAW); - float* buffer = reinterpret_cast(glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE)); + m_vbo1->bind(); + glBufferData(GL_ARRAY_BUFFER, m_nbChars*16*sizeof(float), 0, GL_STREAM_DRAW); + float* buffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); // fill buffer unsigned int pos=0; // pos of first index in vbo for current string @@ -158,17 +217,16 @@ void Strings3D::sendToVBO() pos += nb; } - glUnmapBufferARB(GL_ARRAY_BUFFER); + glUnmapBuffer(GL_ARRAY_BUFFER); } void Strings3D::predraw(const Geom::Vec3f& color) { - m_shader.bind(); - glUniform1iARB(m_uniform_texture,0); - - glUniform3fvARB(m_uniform_color,1,color.data()); + bind(); + glUniform1i(m_uniform_texture,0); + glUniform3fv(m_uniform_color,1,color.data()); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, m_idTexture); @@ -176,17 +234,13 @@ void Strings3D::predraw(const Geom::Vec3f& color) glDisable(GL_LIGHTING); - glBindBufferARB(GL_ARRAY_BUFFER, m_vbo1); - glVertexPointer(4, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); + enableVertexAttribs(); } void Strings3D::postdraw() { - glDisableClientState(GL_VERTEX_ARRAY); - glDisable(GL_TEXTURE_2D); - glEnable(GL_LIGHTING); - m_shader.unbind(); + disableVertexAttribs(); + unbind(); } @@ -206,6 +260,7 @@ void Strings3D::drawAll(const Geom::Vec3f& color) return; } + unsigned int nb = m_strpos.size(); for (unsigned int idSt=0; idSt +#include namespace CGoGN { @@ -31,15 +33,37 @@ namespace Utils { -VBO::VBO() +VBO::VBO(): +m_nbElts(0),m_lock(false) { - glGenBuffersARB(1,&m_id); + glGenBuffers(1,&m_id); m_refs.reserve(4); } +VBO::VBO(const VBO& vbo): + m_data_size(vbo.m_data_size),m_nbElts(vbo.m_nbElts),m_lock(false) +{ + + unsigned int nbbytes = sizeof(float)*m_data_size*m_nbElts; + + glGenBuffers(1,&m_id); + + vbo.bind(); + void* src = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); + + bind(); + glBufferData(GL_ARRAY_BUFFER, nbbytes, src, GL_STREAM_DRAW); + + vbo.bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); +} + + VBO::~VBO() { - glDeleteBuffersARB(1,&m_id); + if (m_lock) + releasePtr(); + glDeleteBuffers(1,&m_id); for(std::vector::iterator it = m_refs.begin(); it != m_refs.end(); ++it) { (*it)->unbindVBO(this); @@ -57,6 +81,27 @@ void VBO::ref(GLSLShader* sh) } +void* VBO::lockPtr() +{ + if (m_lock) + { + std::cerr <<" Error already locked VBO"<< std::endl; + return NULL; + } + + m_lock=true; + glBindBuffer(GL_ARRAY_BUFFER, m_id); + return glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); +} + +void VBO::releasePtr() +{ + glBindBuffer(GL_ARRAY_BUFFER, m_id); + glUnmapBuffer(GL_ARRAY_BUFFER); + m_lock=false; +} + + } } diff --git a/src/Utils/glutwin_gl3.cpp b/src/Utils/xglutwin_gl3.cppx similarity index 100% rename from src/Utils/glutwin_gl3.cpp rename to src/Utils/xglutwin_gl3.cppx