Commit 604a068c authored by Sylvain Thery's avatar Sylvain Thery

oubli fichiers Render/*.cpp

parent 6980a3f7
......@@ -40,7 +40,6 @@ target_link_libraries( tuto1
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} )
......@@ -69,9 +68,10 @@ add_executable( tuto_mt tuto_mt.cpp)
target_link_libraries( tuto_mt
container topology utils algo ${COMMON_LIBS} boost_thread-mt)
add_executable( tuto_ogl3 tuto_ogl3.cpp)
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} )
container topology utils algo ${COMMON_LIBS} ${QT_LIBRARIES} )
add_executable( tuto_ogl2 tuto_ogl2.cpp)
target_link_libraries( tuto_ogl2
......
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
* 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 <iostream>
#include "Utils/glutwingl3.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/gl3mapRender.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Geometry/vector_gen.h"
#include "Algo/Geometry/normal.h"
#include "tuto_ogl3.h"
#include <QWidget>
#include <QtGui>
#include "Utils/shaderPhong.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
void MyQT::sliderFocale_cb(int x)
{
// definition of the type of the map
typedef EmbeddedMap2<Map2> MAP;
};
/**
* A class for a little interface and rendering
*/
class MyGlutWin: public Utils::SimpleGlutWinGL3
{
public:
void myRedraw();
void myKeyboard(unsigned char keycode, int x, int y);
void renderColor();
void renderPhong();
void initPhongMaterial();
PFP::REAL gWidthObj;
PFP::VEC3 gPosObj;
Algo::Render::GL3::MapRender* m_render;
m_glWidget->setFocal(0.01f*x);
updateGL();
}
Utils::GLSLShader* current_shader;
Utils::GLSLShader shaders[4];
int rt;
MyGlutWin(int* argc, char **argv, int winX, int winY) : SimpleGlutWinGL3(argc, argv, winX, winY),rt(0)
void MyQT::color_cb()
{
QColor color = QColorDialog::getColor ();
if (color.isValid())
{
shaders[0].loadShaders("color_gl3.vert","color_gl3.frag");
shaders[1].loadShaders("phong_gl3.vert","phong_gl3.frag");
current_shader = &shaders[0];
setCurrentShader(current_shader);
std::cout <<"Color " << color.red()<<","<< color.green()<<","<<color.blue()<< std::endl;
shader1->setDiffuse(Geom::Vec4f(float(color.red())/255.0f,float(color.green())/255.0f,float(color.blue())/255.0f,0.0f));
updateGL();
}
~MyGlutWin()
else
{
delete m_render ;
std::cout << "Cancel"<< std::endl;
}
};
void MyGlutWin::initPhongMaterial()
{
float diffuse[] = {0.0f,1.0f,0.0f,0.0f};
float specular[] = {0.3f,0.3f,1.0f,0.0f};
float ambient[] = {0.1f,0.03f,0.03f,0.0f};
float shininess = 100.0f;
float lightPos[] = {100.0,300.0,1000.0f};
shaders[1].bind();
shaders[1].setuniformf<4>("materialDiffuse",diffuse);
shaders[1].setuniformf<4>("materialSpecular",specular);
shaders[1].setuniformf<4>("materialAmbient",ambient);
shaders[1].setuniformf<1>("shininess",&shininess);
shaders[1].setuniformf<3>("LightPosition",lightPos);
}
void MyGlutWin::renderColor()
MyQT::MyQT(): m_render(NULL)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_LIGHTING);
current_shader->bind();
// draw the lines
glLineWidth(2.0f);
float colorLine[] = {1.0f,1.0f,0.0f,0.0f};
current_shader->setuniformf<4>("Color",colorLine);
m_render->draw(Algo::Render::GL3::LINES);
// currentShader = NULL;
}
// draw the faces
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
float colorFace[] = {0.1f,0.1f,0.3f,0.0f};
current_shader->setuniformf<4>("Color",colorFace);
m_render->draw(Algo::Render::GL3::TRIANGLES);
MyQT::~MyQT()
{ }
glDisable(GL_POLYGON_OFFSET_FILL);
}
void MyGlutWin::renderPhong()
void MyQT::cb_initGL()
{
Utils::GLSLShader::setCurrentOGLVersion(3);
// instanciation of the renderer (here using VBOs)
m_render = new Algo::Render::GL2::MapRender();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
positionVBO = new Utils::VBO();
normalVBO = new Utils::VBO();
current_shader->bind();
shader1 = new Utils::ShaderPhong();
m_render->draw(Algo::Render::GL3::TRIANGLES);
}
shader1->setAttributePosition(*positionVBO);
shader1->setAttributeNormal(*normalVBO);
currentShader = shader1;
}
void MyGlutWin::myRedraw()
void MyQT::cb_updateMatrix()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// oglPushModelViewMatrix();
switch(rt)
if (currentShader)
{
case 0:
renderColor();
break;
case 1:
renderPhong();
break;
currentShader->bind();
currentShader->updateMatrices(m_projection_matrix, m_modelView_matrix);
}
// oglPopModelViewMatrix();
}
void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
void MyQT::cb_redraw()
{
switch(keycode)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
if (currentShader)
{
case 'c':
rt=0;
current_shader = &shaders[0];
setCurrentShader(current_shader);
std::cout << "Color"<< std::endl;
break;
case 'p':
rt=1;
current_shader = &shaders[1];
setCurrentShader(current_shader);
std::cout << "Phong"<< std::endl;
break;
m_render->draw(currentShader, Algo::Render::GL2::TRIANGLES);
}
glutPostRedisplay();
}
int main(int argc, char **argv)
{
//void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
//{
// switch(keycode)
// {
// case 'f':
// focale-=0.1f;
// setFoc(focale);
// break;
// case 'F':
// focale+=0.1f;
// setFoc(focale);
// break;
// }
////
//// switch(keycode)
//// {
//// case 'c':
//// rt=0;
//// current_shader = &shaders[0];
//// setCurrentShader(current_shader);
//// std::cout << "Color"<< std::endl;
//// break;
//// case 'p':
//// rt=1;
//// current_shader = &shaders[1];
//// setCurrentShader(current_shader);
//// std::cout << "Phong"<< std::endl;
//// break;
//// }
//// glutPostRedisplay();
//
//
// switch(keycode)
// {
// case 'r':
// shader1.setDiffuse(Geom::Vec4f(1.,0.,0.,0.));
// break;
// case 'v':
// shader1.setDiffuse(Geom::Vec4f(0.,1.,0.,0.));
// break;
// case 'j':
// shader1.setDiffuse(Geom::Vec4f(1.,1.,0.,0.));
// break;
//
// case 'w':
// shader1.setAttributeColor(normalVBO);
// break;
// case 'x':
// shader1.unsetAttributeColor();
// break;
//
// }
// glutPostRedisplay();
//}
// instanciation of the interface
MyGlutWin mgw(&argc, argv, 800, 800);
int main(int argc, char **argv)
{
// declaration of the map
PFP::MAP myMap;
......@@ -206,44 +170,69 @@ int main(int argc, char **argv)
AttributeHandler<PFP::VEC3> normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal");
Algo::Modelisation::Polyhedron<PFP> prim3(myMap, position);
prim3.tore_topo(16, 32);
prim3.embedTore(30.0f,10.0f);
prim3.tore_topo(32, 64);
prim3.embedTore(1.0f,0.3f);
Algo::Geometry::computeNormalVertices<PFP>(myMap,position,normal);
mgw.init();
glClearColor(0.1,0.1,0.3,0.0);
QApplication app(argc, argv);
MyQT sqt;
// computation of the bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
mgw.gWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
mgw.gPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
// Qt "a la main"
mgw.setParamObject(mgw.gWidthObj,mgw.gPosObj.data());
QDockWidget* dock = sqt.addEmptyDock();
// instanciation of the renderer (here using VBOs)
mgw.m_render = new Algo::Render::GL3::MapRender();
// group principal
QGroupBox *interface_gb = new QGroupBox();
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(new QLabel("Focale"));
QSlider *slider_foc = new QSlider(Qt::Horizontal);
slider_foc->setRange(50, 300);
slider_foc->setSliderPosition(200);
layout->addWidget(slider_foc);
QPushButton* buttonColor = new QPushButton("Color");
layout->addWidget(buttonColor);
// on tasse vers le haut
layout->addItem(new QSpacerItem(0,0, QSizePolicy::Expanding, QSizePolicy::Expanding));
// et met tout ça dans le dock
interface_gb->setLayout(layout);
dock->setWidget(interface_gb);
// declare names attributes of shaders
mgw.m_render->useVertexAttributeName("VertexPosition",mgw.shaders[0]);
mgw.m_render->useVertexAttributeName("VertexPosition",mgw.shaders[1]);
unsigned int attNormalId = mgw.m_render->useVertexAttributeName("VertexNormal",mgw.shaders[1]);
sqt.windowTitle("OGL3 QT");
sqt.dockTitle("interface");
// send data to gc
mgw.m_render->updateData("VertexPosition", position); // with name
mgw.m_render->updateData(attNormalId, normal); //with Id
// connection widget callback
sqt.setCallBack( slider_foc, SIGNAL(valueChanged(int)), SLOT(sliderFocale_cb(int)) );
sqt.setCallBack( buttonColor, SIGNAL(clicked()), SLOT(color_cb()) );
// computation of the bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
sqt.setParamObject(lWidthObj,lPosObj.data());
// first show to init GL Context before initializing VBO
sqt.show();
sqt.positionVBO->updateData(position);
sqt.normalVBO->updateData(normal);
// update the renderer (primitives and geometry)
SelectorTrue allDarts;
mgw.m_render->initPrimitives<PFP>(myMap, allDarts,Algo::Render::GL3::TRIANGLES);
mgw.m_render->initPrimitives<PFP>(myMap, allDarts,Algo::Render::GL3::LINES);
mgw.m_render->initPrimitives<PFP>(myMap, allDarts,Algo::Render::GL3::POINTS);
mgw.initPhongMaterial();
sqt.m_render->initPrimitives<PFP>(myMap, allDarts,Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts,Algo::Render::GL2::LINES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts,Algo::Render::GL2::POINTS);
mgw.mainLoop();
// second show to have a good initial redraw
sqt.show();
return 0;
return app.exec();
// return 0;
}
......@@ -25,7 +25,7 @@
#ifndef __CGOGN_SHADER_PHONG_
#define __CGOGN_SHADER_PHONG_
#include "Utils/GLSLShader3.h"
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include <string>
......
/*******************************************************************************
* 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 "Algo/Render/GL2/mapRender.h"
#include "Utils/GLSLShader.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL2
{
MapRender::MapRender():
m_nbIndicesTri(0),
m_nbIndicesLines(0),
m_nbIndicesPoints(0),
m_nbFlatElts(0)
{
glGenBuffersARB(4, m_VBOBuffers) ;
}
MapRender::~MapRender()
{
glDeleteBuffersARB(4, m_VBOBuffers);
delete[] m_VBOBuffers ;
}
void MapRender::initPrimitives(int prim, std::vector<GLuint>& tableIndices)
{
// indice du VBO a utiliser
int vbo_ind = 0;
switch(prim)
{
case TRIANGLES:
m_nbIndicesTri = tableIndices.size();
vbo_ind = m_VBOBuffers[TRIANGLE_INDICES];
break;
case LINES:
m_nbIndicesLines = tableIndices.size();
vbo_ind = m_VBOBuffers[LINE_INDICES];
break;
case POINTS:
m_nbIndicesPoints = tableIndices.size();
vbo_ind = m_VBOBuffers[POINT_INDICES];
break;
default:
std::cerr << "problem initializing VBO indices" << std::endl;
break;
}
int size = tableIndices.size();
// setup du buffer d'indices
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, vbo_ind);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, size*sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
}
void MapRender::draw(Utils::GLSLShader* sh, int prim)
{
const std::vector<Utils::GLSLShader::VAStr>& vastr = sh->getVA_VBO_Bindings();
for (std::vector<Utils::GLSLShader::VAStr>::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)
{
case TRIANGLES:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[TRIANGLE_INDICES]);
glDrawElements(GL_TRIANGLES, m_nbIndicesTri, GL_UNSIGNED_INT, 0);
break;
case LINES:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[LINE_INDICES]);
glDrawElements(GL_LINES, m_nbIndicesLines, GL_UNSIGNED_INT, 0);
break;
case POINTS:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[POINT_INDICES]);
glDrawElements(GL_POINTS, m_nbIndicesPoints, GL_UNSIGNED_INT, 0) ;
break;
default:
break;
}
for (std::vector<Utils::GLSLShader::VAStr>::const_iterator it= vastr.begin(); it != vastr.end(); ++it)
{
glDisableVertexAttribArray(it->va_id);
}
}
} // namespace GL2
} // namespace Render
} // namespace Algo
} // namespace CGoGN
/*******************************************************************************
* 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 "Algo/Render/GL2/topo3Render.h"
#include "Topology/generic/dart.h"
#include <string.h>
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL2
{
topo3Render::topo3Render():
m_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL)
{
glGenBuffersARB(5, m_VBOBuffers);
}
topo3Render::~topo3Render()
{
glDeleteBuffersARB(5, m_VBOBuffers);
if (m_attIndex.map() != NULL)
static_cast<AttribMap*>(m_attIndex.map())->removeAttribute(m_attIndex);
if (m_color_save!=NULL)
{
delete[] m_color_save;