Commit de44d2ff authored by Pierre Kraemer's avatar Pierre Kraemer

update PointSprite shader + change selected points rendering in surface deformation plugin

parent 7893575b
...@@ -114,6 +114,7 @@ void Viewer::cb_initGL() ...@@ -114,6 +114,7 @@ void Viewer::cb_initGL()
m_pointSprite = new Utils::PointSprite() ; m_pointSprite = new Utils::PointSprite() ;
m_pointSprite->setAttributePosition(m_positionVBO) ; m_pointSprite->setAttributePosition(m_positionVBO) ;
m_pointSprite->setColor(Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f)) ;
registerShader(m_phongShader) ; registerShader(m_phongShader) ;
registerShader(m_flatShader) ; registerShader(m_flatShader) ;
...@@ -126,11 +127,8 @@ void Viewer::cb_redraw() ...@@ -126,11 +127,8 @@ void Viewer::cb_redraw()
{ {
if(m_drawVertices) if(m_drawVertices)
{ {
float size = vertexScaleFactor ; m_pointSprite->setSize(vertexScaleFactor) ;
m_pointSprite->setSize(size) ;
m_pointSprite->predraw(Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f)) ;
m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ; m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
m_pointSprite->postdraw() ;
} }
if(m_drawEdges) if(m_drawEdges)
......
...@@ -129,6 +129,7 @@ void MyQT::cb_initGL() ...@@ -129,6 +129,7 @@ void MyQT::cb_initGL()
m_sprite = new Utils::PointSprite(); m_sprite = new Utils::PointSprite();
m_sprite->setAttributePosition(m_positionVBO); m_sprite->setAttributePosition(m_positionVBO);
m_sprite->setColor(Geom::Vec4f(1.0f, 0.0f , 0.0f, 1.0f));
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f)); m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
storeVerticesInfo(); storeVerticesInfo();
...@@ -200,9 +201,7 @@ void MyQT::cb_redraw() ...@@ -200,9 +201,7 @@ void MyQT::cb_redraw()
if (render_balls) if (render_balls)
{ {
m_sprite->predraw(Geom::Vec4f(1.0f, 0.0f , 0.0f, 1.0f));
m_render->draw(m_sprite, Algo::Render::GL2::POINTS); m_render->draw(m_sprite, Algo::Render::GL2::POINTS);
m_sprite->postdraw();
} }
if (render_vectors) if (render_vectors)
......
...@@ -99,9 +99,8 @@ void RenderPlugin::redraw(View* view) ...@@ -99,9 +99,8 @@ void RenderPlugin::redraw(View* view)
{ {
m_pointSprite->setSize(m->getBBdiagSize() / 200.0f * p->verticesScaleFactor); m_pointSprite->setSize(m->getBBdiagSize() / 200.0f * p->verticesScaleFactor);
m_pointSprite->setAttributePosition(p->positionVBO); m_pointSprite->setAttributePosition(p->positionVBO);
m_pointSprite->predraw(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f)); m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f));
m->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS); m->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS);
m_pointSprite->postdraw();
} }
if(p->renderEdges) if(p->renderEdges)
{ {
......
#ifndef _SURFACEDEFORMATION_PLUGIN_H_ #ifndef _SURFACEDEFORMATION_PLUGIN_H_
#define _SURFACEDEFORMATION_PLUGIN_H_ #define _SURFACEDEFORMATION_PLUGIN_H_
#include "Utils/drawer.h"
#include "plugin.h" #include "plugin.h"
#include "surfaceDeformationDockTab.h" #include "surfaceDeformationDockTab.h"
...@@ -45,8 +43,11 @@ struct PerMapParameterSet ...@@ -45,8 +43,11 @@ struct PerMapParameterSet
CellMarker<VERTEX>* lockingMarker; CellMarker<VERTEX>* lockingMarker;
CellMarker<VERTEX>* handleMarker; CellMarker<VERTEX>* handleMarker;
SelectionMode verticesSelectionMode; SelectionMode verticesSelectionMode;
std::vector<unsigned int> locked_vertices; std::vector<PFP2::VEC3> lockedVertices;
std::vector<unsigned int> handle_vertices; std::vector<PFP2::VEC3> handleVertices;
std::vector<unsigned int> handleVerticesId;
Utils::VBO* lockedVerticesVBO;
Utils::VBO* handleVerticesVBO;
VertexAttribute<PFP2::VEC3> positionInit; VertexAttribute<PFP2::VEC3> positionInit;
VertexAttribute<PFP2::VEC3> vertexNormal; VertexAttribute<PFP2::VEC3> vertexNormal;
...@@ -113,7 +114,6 @@ protected: ...@@ -113,7 +114,6 @@ protected:
QHash<View*, ParameterSet*> h_viewParams; QHash<View*, ParameterSet*> h_viewParams;
Utils::PointSprite* m_pointSprite; Utils::PointSprite* m_pointSprite;
Utils::Drawer* m_drawer;
Utils::VBO* selectionSphereVBO; Utils::VBO* selectionSphereVBO;
......
...@@ -39,6 +39,9 @@ PerMapParameterSet::PerMapParameterSet(MapHandlerGen* m) : ...@@ -39,6 +39,9 @@ PerMapParameterSet::PerMapParameterSet(MapHandlerGen* m) :
lockingMarker = new CellMarker<VERTEX>(*map); lockingMarker = new CellMarker<VERTEX>(*map);
handleMarker = new CellMarker<VERTEX>(*map); handleMarker = new CellMarker<VERTEX>(*map);
lockedVerticesVBO = new Utils::VBO();
handleVerticesVBO = new Utils::VBO();
positionInit = mh->getAttribute<PFP2::VEC3, VERTEX>("positionInit", false) ; positionInit = mh->getAttribute<PFP2::VEC3, VERTEX>("positionInit", false) ;
if(!positionInit.isValid()) if(!positionInit.isValid())
positionInit = mh->addAttribute<PFP2::VEC3, VERTEX>("positionInit", false) ; positionInit = mh->addAttribute<PFP2::VEC3, VERTEX>("positionInit", false) ;
...@@ -74,6 +77,8 @@ PerMapParameterSet::~PerMapParameterSet() ...@@ -74,6 +77,8 @@ PerMapParameterSet::~PerMapParameterSet()
{ {
delete lockingMarker; delete lockingMarker;
delete handleMarker; delete handleMarker;
delete lockedVerticesVBO;
delete handleVerticesVBO;
nlDeleteContext(nlContext); nlDeleteContext(nlContext);
} }
...@@ -115,9 +120,6 @@ bool SurfaceDeformationPlugin::enable() ...@@ -115,9 +120,6 @@ bool SurfaceDeformationPlugin::enable()
m_pointSprite = new CGoGN::Utils::PointSprite(); m_pointSprite = new CGoGN::Utils::PointSprite();
registerShader(m_pointSprite); registerShader(m_pointSprite);
m_drawer = new Utils::Drawer();
registerShader(m_drawer->getShader());
connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*))); connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*)));
connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*))); connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*))); connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));
...@@ -128,20 +130,54 @@ bool SurfaceDeformationPlugin::enable() ...@@ -128,20 +130,54 @@ bool SurfaceDeformationPlugin::enable()
void SurfaceDeformationPlugin::disable() void SurfaceDeformationPlugin::disable()
{ {
delete m_pointSprite; delete m_pointSprite;
delete m_drawer;
} }
void SurfaceDeformationPlugin::redraw(View* view) void SurfaceDeformationPlugin::redraw(View* view)
{ {
ParameterSet* params = h_viewParams[view];
MapHandlerGen* mh = params->selectedMap;
if(mh)
{
PerMapParameterSet* perMap = params->perMap[mh->getName()];
if(!perMap->lockedVertices.empty() || !perMap->handleVertices.empty())
{
m_pointSprite->setAttributePosition(perMap->lockedVerticesVBO);
m_pointSprite->setSize(mh->getBBdiagSize() / 250.0f);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(1.0f, 0.0f, 0.0f, 0.75f));
m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m_pointSprite->enableVertexAttribs();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_POINTS, 0, perMap->lockedVertices.size());
glDisable(GL_BLEND);
m_pointSprite->disableVertexAttribs();
m_pointSprite->setAttributePosition(perMap->handleVerticesVBO);
m_pointSprite->setSize(mh->getBBdiagSize() / 250.0f);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 1.0f, 0.0f, 0.75f));
m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m_pointSprite->enableVertexAttribs();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_POINTS, 0, perMap->handleVertices.size());
glDisable(GL_BLEND);
m_pointSprite->disableVertexAttribs();
}
}
if(selecting) if(selecting)
{ {
std::vector<PFP2::VEC3> selectionPoint; std::vector<PFP2::VEC3> selectionPoint;
selectionPoint.push_back(selectionCenter); selectionPoint.push_back(selectionCenter);
selectionSphereVBO->updateData(selectionPoint); selectionSphereVBO->updateData(selectionPoint);
m_pointSprite->setSize(selectionRadius);
m_pointSprite->setAttributePosition(selectionSphereVBO); m_pointSprite->setAttributePosition(selectionSphereVBO);
m_pointSprite->predraw(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f)); m_pointSprite->setSize(selectionRadius);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f));
m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m_pointSprite->enableVertexAttribs(); m_pointSprite->enableVertexAttribs();
glEnable(GL_BLEND); glEnable(GL_BLEND);
...@@ -149,34 +185,6 @@ void SurfaceDeformationPlugin::redraw(View* view) ...@@ -149,34 +185,6 @@ void SurfaceDeformationPlugin::redraw(View* view)
glDrawArrays(GL_POINTS, 0, 1); glDrawArrays(GL_POINTS, 0, 1);
glDisable(GL_BLEND); glDisable(GL_BLEND);
m_pointSprite->disableVertexAttribs(); m_pointSprite->disableVertexAttribs();
m_pointSprite->postdraw();
}
ParameterSet* params = h_viewParams[view];
MapHandlerGen* mh = params->selectedMap;
if(mh)
{
PerMapParameterSet* perMap = params->perMap[mh->getName()];
if(!perMap->locked_vertices.empty() || !perMap->handle_vertices.empty())
{
glDisable(GL_LIGHTING) ;
m_drawer->newList(GL_COMPILE_AND_EXECUTE) ;
m_drawer->pointSize(4.0f) ;
m_drawer->begin(GL_POINTS) ;
m_drawer->color3f(1.0f, 0.0f, 0.0f) ;
for(unsigned int i = 0; i < perMap->locked_vertices.size(); ++i)
{
if (!perMap->handleMarker->isMarked(perMap->locked_vertices[i]))
m_drawer->vertex(perMap->positionAttribute[perMap->locked_vertices[i]]) ;
}
m_drawer->color3f(0.0f, 0.0f, 1.0f) ;
for(unsigned int i = 0; i < perMap->handle_vertices.size(); ++i)
m_drawer->vertex(perMap->positionAttribute[perMap->handle_vertices[i]]) ;
m_drawer->end() ;
m_drawer->endList() ;
}
} }
} }
...@@ -229,29 +237,31 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event) ...@@ -229,29 +237,31 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event)
PFP2::VEC3 rayA(orig.x, orig.y, orig.z); PFP2::VEC3 rayA(orig.x, orig.y, orig.z);
PFP2::VEC3 AB(dir.x, dir.y, dir.z); PFP2::VEC3 AB(dir.x, dir.y, dir.z);
Dart d ; Dart d;
PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap(); PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap();
Algo::Selection::vertexRaySelection<PFP2>(*map, perMap->positionAttribute, rayA, AB, d) ; Algo::Selection::vertexRaySelection<PFP2>(*map, perMap->positionAttribute, rayA, AB, d);
if(d != NIL) if(d != NIL)
{ {
Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, perMap->positionAttribute, selectionRadius) ; Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, perMap->positionAttribute, selectionRadius);
neigh.collectAll(d) ; neigh.collectAll(d);
const std::vector<Dart>& insideV = neigh.getInsideVertices() ; const std::vector<Dart>& insideV = neigh.getInsideVertices();
for(unsigned int i = 0; i < insideV.size(); ++i) for(unsigned int i = 0; i < insideV.size(); ++i)
{ {
unsigned int v = map->getEmbedding<VERTEX>(insideV[i]) ; unsigned int v = map->getEmbedding<VERTEX>(insideV[i]);
if (!perMap->lockingMarker->isMarked(v)) if (!perMap->lockingMarker->isMarked(v))
{ {
perMap->locked_vertices.push_back(v) ; if(perMap->verticesSelectionMode == LOCKED)
perMap->lockedVertices.push_back(perMap->positionAttribute[v]);
perMap->lockingMarker->mark(v); perMap->lockingMarker->mark(v);
} }
if(perMap->verticesSelectionMode == HANDLE) if(perMap->verticesSelectionMode == HANDLE)
{ {
if(!perMap->handleMarker->isMarked(v)) if(!perMap->handleMarker->isMarked(v))
{ {
perMap->handle_vertices.push_back(v) ; perMap->handleVertices.push_back(perMap->positionAttribute[v]);
perMap->handleVerticesId.push_back(v);
perMap->handleMarker->mark(v); perMap->handleMarker->mark(v);
} }
} }
...@@ -260,6 +270,10 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event) ...@@ -260,6 +270,10 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event)
nlMakeCurrent(perMap->nlContext) ; nlMakeCurrent(perMap->nlContext) ;
nlReset(NL_FALSE) ; nlReset(NL_FALSE) ;
perMap->lockedVerticesVBO->updateData(perMap->lockedVertices);
if(perMap->verticesSelectionMode == HANDLE)
perMap->handleVerticesVBO->updateData(perMap->handleVertices);
view->updateGL() ; view->updateGL() ;
} }
} }
...@@ -277,13 +291,13 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event) ...@@ -277,13 +291,13 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event)
dragging = true ; dragging = true ;
dragZ = 0; dragZ = 0;
for(unsigned int i = 0; i < perMap->handle_vertices.size(); ++i) for(unsigned int i = 0; i < perMap->handleVertices.size(); ++i)
{ {
const PFP2::VEC3& p = perMap->positionAttribute[perMap->handle_vertices[i]] ; const PFP2::VEC3& p = perMap->handleVertices[i] ;
qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(p[0],p[1],p[2])); qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(p[0],p[1],p[2]));
dragZ += q.z ; dragZ += q.z ;
} }
dragZ /= perMap->handle_vertices.size() ; dragZ /= perMap->handleVertices.size() ;
qglviewer::Vec p(event->x(), event->y(), dragZ); qglviewer::Vec p(event->x(), event->y(), dragZ);
dragPrevious = view->camera()->unprojectedCoordinatesOf(p); dragPrevious = view->camera()->unprojectedCoordinatesOf(p);
...@@ -294,9 +308,7 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event) ...@@ -294,9 +308,7 @@ void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event)
void SurfaceDeformationPlugin::mouseRelease(View* view, QMouseEvent* event) void SurfaceDeformationPlugin::mouseRelease(View* view, QMouseEvent* event)
{ {
if(event->button() == Qt::RightButton) if(event->button() == Qt::RightButton)
{ dragging = false;
dragging = false ;
}
} }
void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event) void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event)
...@@ -313,10 +325,14 @@ void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event) ...@@ -313,10 +325,14 @@ void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event)
qglviewer::Vec vec = q - dragPrevious; qglviewer::Vec vec = q - dragPrevious;
PFP2::VEC3 t(vec.x, vec.y, vec.z); PFP2::VEC3 t(vec.x, vec.y, vec.z);
for(unsigned int i = 0; i < perMap->handle_vertices.size(); ++i) for(unsigned int i = 0; i < perMap->handleVertices.size(); ++i)
perMap->positionAttribute[perMap->handle_vertices[i]] += t ; {
perMap->handleVertices[i] += t;
perMap->positionAttribute[perMap->handleVerticesId[i]] += t;
}
perMap->handleVerticesVBO->updateData(perMap->handleVertices);
dragPrevious = q ; dragPrevious = q;
// matchDiffCoord(view, map); // matchDiffCoord(view, map);
asRigidAsPossible(view, params->selectedMap); asRigidAsPossible(view, params->selectedMap);
...@@ -335,13 +351,13 @@ void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event) ...@@ -335,13 +351,13 @@ void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event)
PFP2::VEC3 rayA(orig.x, orig.y, orig.z); PFP2::VEC3 rayA(orig.x, orig.y, orig.z);
PFP2::VEC3 AB(dir.x, dir.y, dir.z); PFP2::VEC3 AB(dir.x, dir.y, dir.z);
Dart d ; Dart d;
PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap(); PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap();
Algo::Selection::vertexRaySelection<PFP2>(*map, perMap->positionAttribute, rayA, AB, d) ; Algo::Selection::vertexRaySelection<PFP2>(*map, perMap->positionAttribute, rayA, AB, d);
if(d != NIL) if(d != NIL)
{ {
selectionCenter = perMap->positionAttribute[d] ; selectionCenter = perMap->positionAttribute[d];
view->updateGL() ; view->updateGL();
} }
} }
} }
......
...@@ -46,13 +46,13 @@ protected: ...@@ -46,13 +46,13 @@ protected:
CGoGNGLuint m_uniform_maxValue; CGoGNGLuint m_uniform_maxValue;
CGoGNGLuint m_uniform_expansion; CGoGNGLuint m_uniform_expansion;
VBO* m_vboPos;
VBO* m_vboScal;
float m_minValue; float m_minValue;
float m_maxValue; float m_maxValue;
int m_expansion; int m_expansion;
VBO* m_vboPos;
VBO* m_vboScal;
void getLocations(); void getLocations();
void sendParams(); void sendParams();
......
...@@ -4,15 +4,16 @@ uniform mat4 ProjectionMatrix; ...@@ -4,15 +4,16 @@ uniform mat4 ProjectionMatrix;
uniform vec3 lightPos; uniform vec3 lightPos;
uniform vec3 ambiant; uniform vec3 ambiant;
uniform float size; uniform float size;
#ifdef WITH_PLANE #ifdef WITH_PLANE
uniform vec3 eyePos; uniform vec3 eyePos;
VARYING_FRAG vec3 shiftedEye; VARYING_FRAG vec3 shiftedEye;
#endif #endif
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
VARYING_FRAG vec3 colorsprite; VARYING_FRAG vec4 colorsprite;
#else #else
uniform vec4 colorsprite; uniform vec4 colorsprite;
#endif #endif
VARYING_FRAG vec2 spriteCoord; VARYING_FRAG vec2 spriteCoord;
...@@ -43,7 +44,6 @@ void main(void) ...@@ -43,7 +44,6 @@ void main(void)
vec3 frag_position_eye = ray_direction * t ; vec3 frag_position_eye = ray_direction * t ;
#endif #endif
vec4 pos = ProjectionMatrix * vec4(frag_position_eye, 1.0); vec4 pos = ProjectionMatrix * vec4(frag_position_eye, 1.0);
gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0; gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0;
......
...@@ -3,40 +3,40 @@ ...@@ -3,40 +3,40 @@
uniform float size; uniform float size;
uniform mat4 ModelViewMatrix; uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
#ifdef WITH_PLANE #ifdef WITH_PLANE
uniform vec3 eyePos; uniform vec3 eyePos;
VARYING_OUT vec3 shiftedEye; VARYING_OUT vec3 shiftedEye;
#endif #endif
VARYING_OUT vec2 spriteCoord; VARYING_OUT vec2 spriteCoord;
VARYING_OUT vec3 sphereCenter; VARYING_OUT vec3 sphereCenter;
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
VARYING_IN vec3 color[1]; VARYING_IN vec4 color[1];
VARYING_OUT vec3 colorsprite; VARYING_OUT vec4 colorsprite;
#endif #endif
#ifdef WITH_PLANE #ifdef WITH_PLANE
void corner( vec4 center, vec3 planeX, vec3 planeY, float x, float y) void corner( vec4 center, vec3 planeX, vec3 planeY, float x, float y)
{ {
spriteCoord = vec2(x,y); spriteCoord = vec2(x,y);
vec4 pos = center + size*( x*vec4(planeX,0.0) + y*vec4(planeY,0.0)+ vec4(0.0,0.0,0.5,0.0)); vec4 pos = center + size*( x*vec4(planeX,0.0) + y*vec4(planeY,0.0)+ vec4(0.0,0.0,0.5,0.0));
gl_Position = ProjectionMatrix * pos; gl_Position = ProjectionMatrix * pos;
EmitVertex(); EmitVertex();
} }
#else #else
void corner( vec4 center, float x, float y) void corner( vec4 center, float x, float y)
{ {
spriteCoord = vec2(x,y); spriteCoord = vec2(x,y);
vec4 pos = center + vec4(size*x, size*y, 0.0, 0.0); vec4 pos = center + vec4(size*x, size*y, 0.0, 0.0);
gl_Position = ProjectionMatrix * pos; gl_Position = ProjectionMatrix * pos;
EmitVertex(); EmitVertex();
} }
#endif #endif
void main() void main()
{ {
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0]; colorsprite = color[0];
#endif #endif
...@@ -63,6 +63,7 @@ void main() ...@@ -63,6 +63,7 @@ void main()
corner(posCenter, 1.4, 1.4); corner(posCenter, 1.4, 1.4);
corner(posCenter, 1.4,-1.4); corner(posCenter, 1.4,-1.4);
#endif #endif
EndPrimitive(); EndPrimitive();
} }
...@@ -36,100 +36,66 @@ namespace CGoGN ...@@ -36,100 +36,66 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
class PointSprite: public Utils::GLSLShader class PointSprite : public Utils::GLSLShader
{ {
protected: protected:
static const unsigned int WIDTHSPRITE = 64;
static std::string vertexShaderText; static std::string vertexShaderText;
static std::string geometryShaderText; static std::string geometryShaderText;
static std::string fragmentShaderText; static std::string fragmentShaderText;
static unsigned char* m_ptrSphere; bool colorPerVertex;
bool plane;
static PointSprite* m_instance0;
// compute the sphere instead of storing it in image file.
static void computeSphere();
CGoGNGLuint m_uniform_size; CGoGNGLuint m_uniform_size;
CGoGNGLuint m_uniform_color; CGoGNGLuint m_uniform_color;
CGoGNGLuint m_idTexture;
CGoGNGLuint m_uniform_texture;
CGoGNGLuint m_uniform_EyePos;
// CGoGNGLuint m_uniform_EyeY;
CGoGNGLuint m_uniform_ambiant; CGoGNGLuint m_uniform_ambiant;
CGoGNGLuint m_uniform_lightPos; CGoGNGLuint m_uniform_lightPos;
CGoGNGLuint m_uniform_eyePos;
public: VBO* m_vboPos;
/** VBO* m_vboColor;
* init shaders, texture and variables
* @param withColorPerVertex if true use setAttributeColor for per vertex color, else use predraw(color) for global color
* @param radius of sphere
*/
PointSprite(bool withColorPerVertex=false, float radius=1.0f, bool with_plane=false);
<