Commit dc426c9a authored by untereiner's avatar untereiner

Merge branch 'master' of cgogn:~thery/CGoGN

parents 877cc473 735a68f9
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "Algo/Render/topo3_vboRender.h" #include "Algo/Render/topo3_vboRender.h"
#include "Topology/generic/cellmarker.h" #include "Topology/generic/cellmarker.h"
#include "Utils/text3d.h"
//#include "testMaps.h" //#include "testMaps.h"
...@@ -66,6 +67,10 @@ Dart dglobal; ...@@ -66,6 +67,10 @@ Dart dglobal;
unsigned int idNorm; unsigned int idNorm;
unsigned int idCol; unsigned int idCol;
class myGlutWin: public Utils::SimpleGlutWin class myGlutWin: public Utils::SimpleGlutWin
{ {
public: public:
...@@ -83,8 +88,12 @@ public: ...@@ -83,8 +88,12 @@ public:
Algo::Render::VBO::MapRender_VBO* m_render; Algo::Render::VBO::MapRender_VBO* m_render;
Algo::Render::VBO::topo3_VBORenderMapD* m_render_topo; Algo::Render::VBO::topo3_VBORenderMapD* m_render_topo;
Utils::Strings3D m_strings;
void updateVBO(); void updateVBO();
void storeVerticesInfo();
myGlutWin( int* argc, char **argv, int winX, int winY):SimpleGlutWin(argc,argv,winX,winY) myGlutWin( int* argc, char **argv, int winX, int winY):SimpleGlutWin(argc,argv,winX,winY)
{ {
aff_help = false; aff_help = false;
...@@ -97,6 +106,22 @@ public: ...@@ -97,6 +106,22 @@ public:
void myKeyboard(unsigned char keycode, int x, int y); void myKeyboard(unsigned char keycode, int x, int y);
}; };
void myGlutWin::storeVerticesInfo()
{
CellMarker mv(myMap,VERTEX_CELL);
for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
{
if (!mv.isMarked(d))
{
mv.mark(d);
std::stringstream ss;
ss << d << " : "<< position[d];
m_strings.addString(ss.str(),position[d]);
}
}
}
void myGlutWin::myRedraw(void) void myGlutWin::myRedraw(void)
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
...@@ -161,6 +186,15 @@ void myGlutWin::myRedraw(void) ...@@ -161,6 +186,15 @@ void myGlutWin::myRedraw(void)
} }
// 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();
m_strings.drawAll(Geom::Vec3f(0.0,1.0,1.0));
//affichage de l'aide //affichage de l'aide
if (aff_help) { if (aff_help) {
glColor3f(1.0f,1.0f,1.0f); glColor3f(1.0f,1.0f,1.0f);
...@@ -503,10 +537,11 @@ int main(int argc, char **argv) ...@@ -503,10 +537,11 @@ int main(int argc, char **argv)
mgw.m_render = new Algo::Render::VBO::MapRender_VBO(); mgw.m_render = new Algo::Render::VBO::MapRender_VBO();
mgw.m_render_topo = new Algo::Render::VBO::topo3_VBORenderMapD(); mgw.m_render_topo = new Algo::Render::VBO::topo3_VBORenderMapD();
mgw.updateVBO(); mgw.updateVBO();
mgw.m_strings.init();
mgw.storeVerticesInfo();
mgw.m_strings.sendToVBO();
mgw.mainLoop(); mgw.mainLoop();
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <map> #include <map>
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <vector>
namespace CGoGN namespace CGoGN
{ {
...@@ -128,10 +129,7 @@ protected: ...@@ -128,10 +129,7 @@ protected:
*/ */
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES); bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES);
/*
* search file in different path
*/
std::string findFile(const std::string filename);
/** /**
* get log after compiling * get log after compiling
...@@ -141,6 +139,8 @@ protected: ...@@ -141,6 +139,8 @@ protected:
char* getInfoLog( GLhandleARB obj ); char* getInfoLog( GLhandleARB obj );
static std::vector<std::string> m_pathes;
public: public:
/** /**
* constructor * constructor
...@@ -153,6 +153,11 @@ public: ...@@ -153,6 +153,11 @@ public:
*/ */
virtual ~GLSLShader(); virtual ~GLSLShader();
/*
* search file in different path
*/
static std::string findFile(const std::string filename);
/** /**
* test support of shader * test support of shader
...@@ -210,6 +215,9 @@ public: ...@@ -210,6 +215,9 @@ public:
virtual void unbind(); virtual void unbind();
/**
*
*/
GLuint getAttribIndex( char* attribName ); GLuint getAttribIndex( char* attribName );
...@@ -225,20 +233,49 @@ public: ...@@ -225,20 +233,49 @@ public:
void bindAttrib(unsigned int att, const char* name) const; void bindAttrib(unsigned int att, const char* name) const;
/**
* check shader validity width official GLSL syntax
*/
bool validateProgram(); bool validateProgram();
/**
* check program link status
*/
bool checkProgram(); bool checkProgram();
/**
* check shader compile status
*/
bool checkShader(int shaderType); bool checkShader(int shaderType);
public: public:
/**
* set uniform shader float variable
* @warning practical but less efficient that storing id (get with glGetUniformLocation) and use glUniform*fvARB
* @param NB template size of variable to set
* @param name name in shader
* @param pointer on data to copy
*/
template<unsigned int NB> template<unsigned int NB>
void setuniformf( const char* name , float* val); void setuniformf( const char* name , float* val);
/**
* set uniform shader int variable
* @warning practical but less efficient that storing id (get with glGetUniformLocation) and use glUniform*ivARB
* @param NB template size of variable to set
* @param name name in shader
* @param pointer on data to copy
*/
template<unsigned int NB> template<unsigned int NB>
void setuniformi( const char* name , int* val); void setuniformi( const char* name , int* val);
/**
* add search path for file
* @param path to add
*/
void addPathFileSeach(const std::string& path);
}; };
...@@ -289,13 +326,13 @@ void GLSLShader::setuniformi( const char* name , int* val) ...@@ -289,13 +326,13 @@ void GLSLShader::setuniformi( const char* name , int* val)
glUniform1ivARB( uni, 1, val) ; glUniform1ivARB( uni, 1, val) ;
break; break;
case 2: case 2:
glUniform2ivARB( uni, 2, val) ; glUniform2ivARB( uni, 1, val) ;
break; break;
case 3: case 3:
glUniform3ivARB( uni, 3, val) ; glUniform3ivARB( uni, 1, val) ;
break; break;
case 4: case 4:
glUniform4ivARB( uni, 4, val) ; glUniform4ivARB( uni, 1, val) ;
break; break;
} }
} }
...@@ -305,6 +342,7 @@ void GLSLShader::setuniformi( const char* name , int* val) ...@@ -305,6 +342,7 @@ void GLSLShader::setuniformi( const char* name , int* val)
} //namespace Utils } //namespace Utils
} //namespace CGoGN } //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 *
* *
*******************************************************************************/
#ifndef __TEXT_3D__
#define __TEXT_3D__
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include <IL/ilu.h>
#include <IL/ilut.h>
namespace CGoGN
{
namespace Utils
{
class Strings3D
{
protected:
static const unsigned int WIDTHFONT = 32;
static const unsigned int REALWIDTHFONT = 18;
static const unsigned int WIDTHTEXTURE = 512;
static const unsigned int HEIGHTTEXTURE = 256;
static const unsigned int CHARSPERLINE = WIDTHTEXTURE/WIDTHFONT;
static const unsigned int CHARSPERCOL = HEIGHTTEXTURE/WIDTHFONT;
ILuint m_imgName;
std::vector<std::string> m_strings;
unsigned int m_nbChars;
std::vector< std::pair<unsigned int, unsigned int> > m_strpos;
std::vector< Geom::Vec3f > m_strTranslate;
/**
* VBO (4f: x,y,u,v)
*/
GLuint m_vbo1;
unsigned int sendOneStringToVBO(const std::string& str, float **buffer);
GLuint m_idTexture;
GLuint m_uniform_texture;
GLuint m_uniform_scale;
GLuint m_uniform_position;
GLuint m_uniform_color;
Utils::GLSLShader m_shader;
public:
Strings3D();
~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
* @return the id of string for rendering
*/
unsigned int addString(const std::string& str);
/**
* add astring with its position
* @param string to add to pool of string
* @param pos the position of text
* @return the id of string (future use:updating data)
*/
unsigned int addString(const std::string& str, const Geom::Vec3f& pos);
/**
* once all string are stored, we must send it to the gracphic card
*/
void sendToVBO();
/**
* draw on string
* @param idSt the id of string
* @param pos the position of text
*/
void draw(unsigned int idSt, const Geom::Vec3f& pos);
/**
* Draw all text stored with their position
* @param color the color of text
*/
void drawAll(const Geom::Vec3f& color);
/**
* call once before several draw(id,pos)
* @param color the color of text
*/
void predraw(const Geom::Vec3f& color);
/**
* call once after several draw(id,pos)
*/
void postdraw();
/**
* set the scale for font rendering
* @param scale
*/
void setScale(float scale);
};
}
}
#endif
varying vec2 tex_coord;
uniform sampler2D FontTexture;
uniform vec3 color;
void main (void)
{
float lum = texture2D(FontTexture, tex_coord).s;
gl_FragColor = vec4(color,0.0)*lum;
}
uniform vec3 strPos;
uniform float scale;
varying vec2 tex_coord;
void main()
{
vec4 pos = gl_ModelViewMatrix * vec4(strPos,1.0) + vec4(gl_Vertex[0]*scale,gl_Vertex[1]*scale,0.0,0.0);
tex_coord = vec2(gl_Vertex[2],gl_Vertex[3]);
gl_Position = gl_ProjectionMatrix * pos;
}
...@@ -35,6 +35,9 @@ namespace CGoGN ...@@ -35,6 +35,9 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
std::vector<std::string> GLSLShader::m_pathes;
GLSLShader::GLSLShader() GLSLShader::GLSLShader()
{ {
m_vertex_shader_object = 0; m_vertex_shader_object = 0;
...@@ -527,6 +530,20 @@ std::string GLSLShader::findFile(const std::string filename) ...@@ -527,6 +530,20 @@ std::string GLSLShader::findFile(const std::string filename)
} }
file.close(); file.close();
for (std::vector<std::string>::const_iterator ipath = m_pathes.begin(); ipath != m_pathes.end(); ++ipath)
{
std::string st(*ipath);
st.append(filename);
std::ifstream file2;
file2.open(st.c_str(),std::ios::in);
if (!file2.fail())
{
file2.close();
return st;
}
}
// LA MACRO SHADERPATH contient le chemin du repertoire qui contient les fichiers textes // LA MACRO SHADERPATH contient le chemin du repertoire qui contient les fichiers textes
std::string st(SHADERPATH); std::string st(SHADERPATH);
st.append(filename); st.append(filename);
...@@ -684,6 +701,11 @@ void GLSLShader::bindAttrib(unsigned int att, const char* name) const ...@@ -684,6 +701,11 @@ void GLSLShader::bindAttrib(unsigned int att, const char* name) const
} }
void GLSLShader::addPathFileSeach(const std::string& path)
{
m_pathes.push_back(path);
}
} // namespace Utils } // namespace Utils
......
...@@ -69,7 +69,7 @@ SimpleGlutWin::SimpleGlutWin(int* argc, char **argv, int winX, int winY) ...@@ -69,7 +69,7 @@ SimpleGlutWin::SimpleGlutWin(int* argc, char **argv, int winX, int winY)
scalefactor = 1.0f; scalefactor = 1.0f;
trans_x=0.; trans_x=0.;
trans_y=0.; trans_y=0.;
trans_z=-50.0f; trans_z=-200.0f;
std::cout << "Initialisation Glut" << std::endl; std::cout << "Initialisation Glut" << std::endl;
...@@ -160,14 +160,11 @@ void SimpleGlutWin::recalcModelView(void) ...@@ -160,14 +160,11 @@ void SimpleGlutWin::recalcModelView(void)
glPopMatrix(); glPopMatrix();
glPushMatrix(); glPushMatrix();
glTranslatef(trans_x,trans_y,trans_z+foc); glTranslatef(trans_x,trans_y,trans_z);
build_rotmatrix(m, curquat); build_rotmatrix(m, curquat);
glMultMatrixf(&m[0][0]); glMultMatrixf(&m[0][0]);
float sc = getScale();
glScalef(sc,sc,sc);
newModel = 0; newModel = 0;
} }
...@@ -215,12 +212,13 @@ void SimpleGlutWin::motion(int x, int y) ...@@ -215,12 +212,13 @@ void SimpleGlutWin::motion(int x, int y)
{ {
if (scaling) if (scaling)
{ {
scalefactor = scalefactor * (1.0f + (((float) (beginy - y)) / H)); trans_z -= 0.1f*(x - beginx);
trans_z -= 0.1f*(y - beginy);
} }
else if (translating) else if (translating)
{ {
trans_x += 0.01f*(x - beginx); trans_x += 0.05f*(x - beginx);
trans_y += 0.01f*(beginy - y); trans_y += 0.05f*(beginy - y);
} }
beginx = x; beginx = x;
beginy = y; beginy = y;
......
...@@ -65,7 +65,7 @@ GlutWin_ATB::GlutWin_ATB(int* argc, char **argv, int winX, int winY) ...@@ -65,7 +65,7 @@ GlutWin_ATB::GlutWin_ATB(int* argc, char **argv, int winX, int winY)
scalefactor = 1.0f ; scalefactor = 1.0f ;
trans_x = 0.0f ; trans_x = 0.0f ;
trans_y = 0.0f ; trans_y = 0.0f ;
trans_z = -50.0f ; trans_z = -200.0f ;
std::cout << "Initialisation Glut" << std::endl ; std::cout << "Initialisation Glut" << std::endl ;
glutInit(argc, argv) ; glutInit(argc, argv) ;
...@@ -155,14 +155,11 @@ void GlutWin_ATB::recalcModelView() ...@@ -155,14 +155,11 @@ void GlutWin_ATB::recalcModelView()
glPopMatrix() ; glPopMatrix() ;
glPushMatrix() ; glPushMatrix() ;
glTranslatef(trans_x, trans_y, trans_z+focal) ; glTranslatef(trans_x, trans_y, trans_z) ;
build_rotmatrix(m, curquat) ; build_rotmatrix(m, curquat) ;
glMultMatrixf(&m[0][0]) ; glMultMatrixf(&m[0][0]) ;
float sc = getScale() ;
glScalef(sc, sc, sc) ;
newModel = 0 ; newModel = 0 ;
} }
...@@ -185,14 +182,15 @@ void GlutWin_ATB::motion(int x, int y) ...@@ -185,14 +182,15 @@ void GlutWin_ATB::motion(int x, int y)
} }
else if(scaling) else if(scaling)
{ {
scalefactor = scalefactor * (1.0f + (((float) (beginy - y)) / H)) ; trans_z -= 0.1f*(x - beginx);
trans_z -= 0.1f*(y - beginy);
newModel = 1 ; newModel = 1 ;
glutPostRedisplay() ; glutPostRedisplay() ;
} }
else if(translating) else if(translating)
{ {
trans_x += 0.01f * (x - beginx) ; trans_x += 0.05f * (x - beginx) ;
trans_y += 0.01f * (beginy - y) ; trans_y += 0.05f * (beginy - y) ;
newModel = 1 ; newModel = 1 ;
glutPostRedisplay() ; glutPostRedisplay() ;
} }
......
/*******************************************************************************
* 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 *