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
......
This diff is collapsed.
......@@ -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;
}
}
void topo3Render::setDartWidth(float dw)
{
m_topo_dart_width = dw;
}
void topo3Render::setRelationWidth(float pw)
{
m_topo_relation_width = pw;
}
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]);
glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB);
}
void topo3Render::setAllDartsColor(float r, float g, float b)
{
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]);
GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
float* colorDartBuf = reinterpret_cast<float*>(ColorDartsBuffer);
for (unsigned int i=0; i < 2*m_nbDarts; ++i)
{
*colorDartBuf++ = r;
*colorDartBuf++ = g;
*colorDartBuf++ = b;
}
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[4]);
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER);
}
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);
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()
{
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()
{
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()
{
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()
{
drawDarts();
drawRelation1();
drawRelation2();
drawRelation3();
}
void topo3Render::pushColors()
{
m_color_save = new float[6*m_nbDarts];
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]);
void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float));
glUnmapBuffer(GL_ARRAY_BUFFER);
}
void topo3Render::popColors()
{
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]);
void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float));
glUnmapBuffer(GL_ARRAY_BUFFER);
delete[] m_color_save;
m_color_save=0;
}
Dart topo3Render::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 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
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 topo3Render::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
}//end namespace Render
}//end namespace Algo
}//end 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/topoRender.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL2
{
topoRender::topoRender():
m_topo_dart_width(2.0f), m_topo_relation_width(3.0f)
{
glGenBuffersARB(4, m_VBOBuffers);
}
topoRender::~topoRender()
{
glDeleteBuffersARB(4, m_VBOBuffers);
if (m_attIndex.map() != NULL)
static_cast<AttribMap*>(m_attIndex.map())->removeAttribute(m_attIndex);
}
void topoRender::setDartWidth(float dw)
{
m_topo_dart_width = dw;
}
void topoRender::setRelationWidth(float pw)
{
m_topo_relation_width = pw;
}
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]);
glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB);
}
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);
float* colorDartBuf = reinterpret_cast<float*>(ColorDartsBuffer);
for (unsigned int i=0; i < 2*m_nbDarts; ++i)
{
*colorDartBuf++ = r;
*colorDartBuf++ = g;
*colorDartBuf++ = b;
}
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[3]);
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER);
}
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);
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);
glDrawArrays(GL_POINTS, 0, m_nbDarts);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
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);
glDrawArrays(GL_LINES, 0, m_nbDarts*2);
glDisableClientState(GL_VERTEX_ARRAY);
}
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);
}
void topoRender::drawTopo()
{
drawDarts();
drawRelation1();
drawRelation2();
}
void topoRender::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);
}
}//end namespace GL2
}//end namespace Render
}//end namespace Algo
}//end namespace CGoGN
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment