Commit 7893575b authored by Pierre Kraemer's avatar Pierre Kraemer

allow PointSprite to draw transparent spheres

parent e6fb3a99
...@@ -128,7 +128,7 @@ void Viewer::cb_redraw() ...@@ -128,7 +128,7 @@ void Viewer::cb_redraw()
{ {
float size = vertexScaleFactor ; float size = vertexScaleFactor ;
m_pointSprite->setSize(size) ; m_pointSprite->setSize(size) ;
m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ; 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() ; m_pointSprite->postdraw() ;
} }
......
...@@ -200,7 +200,7 @@ void MyQT::cb_redraw() ...@@ -200,7 +200,7 @@ void MyQT::cb_redraw()
if (render_balls) if (render_balls)
{ {
m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f)); 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(); m_sprite->postdraw();
} }
......
...@@ -99,7 +99,7 @@ void RenderPlugin::redraw(View* view) ...@@ -99,7 +99,7 @@ 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::Vec3f(0.0f, 0.0f, 1.0f)); m_pointSprite->predraw(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(); m_pointSprite->postdraw();
} }
......
...@@ -8,13 +8,14 @@ ...@@ -8,13 +8,14 @@
#include "mapHandler.h" #include "mapHandler.h"
#include "Utils/pointSprite.h"
#include "Container/fakeAttribute.h" #include "Container/fakeAttribute.h"
#include "NL/nl.h" #include "NL/nl.h"
#include "Algo/LinearSolving/basic.h" #include "Algo/LinearSolving/basic.h"
#include "Eigen/Dense" #include "Eigen/Dense"
namespace CGoGN namespace CGoGN
{ {
...@@ -111,8 +112,11 @@ protected: ...@@ -111,8 +112,11 @@ protected:
SurfaceDeformationDockTab* m_dockTab; SurfaceDeformationDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams; QHash<View*, ParameterSet*> h_viewParams;
Utils::PointSprite* m_pointSprite;
Utils::Drawer* m_drawer; Utils::Drawer* m_drawer;
Utils::VBO* selectionSphereVBO;
bool selecting; bool selecting;
PFP2::VEC3 selectionCenter; PFP2::VEC3 selectionCenter;
PFP2::REAL selectionRadius; PFP2::REAL selectionRadius;
......
...@@ -110,6 +110,11 @@ bool SurfaceDeformationPlugin::enable() ...@@ -110,6 +110,11 @@ bool SurfaceDeformationPlugin::enable()
m_dockTab = new SurfaceDeformationDockTab(m_window, this); m_dockTab = new SurfaceDeformationDockTab(m_window, this);
addTabInDock(m_dockTab, "Surface Deformation"); addTabInDock(m_dockTab, "Surface Deformation");
selectionSphereVBO = new Utils::VBO();
m_pointSprite = new CGoGN::Utils::PointSprite();
registerShader(m_pointSprite);
m_drawer = new Utils::Drawer(); m_drawer = new Utils::Drawer();
registerShader(m_drawer->getShader()); registerShader(m_drawer->getShader());
...@@ -122,6 +127,7 @@ bool SurfaceDeformationPlugin::enable() ...@@ -122,6 +127,7 @@ bool SurfaceDeformationPlugin::enable()
void SurfaceDeformationPlugin::disable() void SurfaceDeformationPlugin::disable()
{ {
delete m_pointSprite;
delete m_drawer; delete m_drawer;
} }
...@@ -129,25 +135,22 @@ void SurfaceDeformationPlugin::redraw(View* view) ...@@ -129,25 +135,22 @@ void SurfaceDeformationPlugin::redraw(View* view)
{ {
if(selecting) if(selecting)
{ {
glDisable(GL_LIGHTING) ; std::vector<PFP2::VEC3> selectionPoint;
m_drawer->newList(GL_COMPILE_AND_EXECUTE) ; selectionPoint.push_back(selectionCenter);
m_drawer->lineWidth(2.0f) ; selectionSphereVBO->updateData(selectionPoint);
m_drawer->begin(GL_LINES) ;
m_drawer->color3f(0.0f, 0.0f, 1.0f) ; m_pointSprite->setSize(selectionRadius);
m_drawer->vertex(selectionCenter) ; m_pointSprite->setAttributePosition(selectionSphereVBO);
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(1,0,0)) ; m_pointSprite->predraw(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f));
m_drawer->vertex(selectionCenter) ;
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(-1,0,0)) ; m_pointSprite->enableVertexAttribs();
m_drawer->vertex(selectionCenter) ; glEnable(GL_BLEND);
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,1,0)) ; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_drawer->vertex(selectionCenter) ; glDrawArrays(GL_POINTS, 0, 1);
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,-1,0)) ; glDisable(GL_BLEND);
m_drawer->vertex(selectionCenter) ; m_pointSprite->disableVertexAttribs();
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,0,1)) ;
m_drawer->vertex(selectionCenter) ; m_pointSprite->postdraw();
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,0,-1)) ;
m_drawer->end() ;
m_drawer->endList() ;
} }
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
......
...@@ -12,7 +12,7 @@ uniform float size; ...@@ -12,7 +12,7 @@ uniform float size;
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
VARYING_FRAG vec3 colorsprite; VARYING_FRAG vec3 colorsprite;
#else #else
uniform vec3 colorsprite; uniform vec4 colorsprite;
#endif #endif
VARYING_FRAG vec2 spriteCoord; VARYING_FRAG vec2 spriteCoord;
...@@ -51,6 +51,8 @@ void main(void) ...@@ -51,6 +51,8 @@ void main(void)
vec3 L = normalize (lightPos - frag_position_eye); vec3 L = normalize (lightPos - frag_position_eye);
float lambertTerm = dot(N,L); float lambertTerm = dot(N,L);
gl_FragColor = vec4(colorsprite*lambertTerm + ambiant ,1.0); vec4 result = colorsprite*lambertTerm;
result.xyz += ambiant;
gl_FragColor = result;
} }
...@@ -88,7 +88,7 @@ public: ...@@ -88,7 +88,7 @@ public:
* call once before sending points to gpu * call once before sending points to gpu
* @param color set global color of sprites * @param color set global color of sprites
*/ */
void predraw(const Geom::Vec3f& color); void predraw(const Geom::Vec4f& color);
/** /**
* call once before sending points to gpu * call once before sending points to gpu
......
...@@ -124,11 +124,11 @@ unsigned int PointSprite::setAttributeColor(VBO* vbo) ...@@ -124,11 +124,11 @@ unsigned int PointSprite::setAttributeColor(VBO* vbo)
return bindVA_VBO("VertexColor", vbo); return bindVA_VBO("VertexColor", vbo);
} }
void PointSprite::predraw(const Geom::Vec3f& color) void PointSprite::predraw(const Geom::Vec4f& color)
{ {
bind(); bind();
glUniform1i(*m_uniform_texture, 0); glUniform1i(*m_uniform_texture, 0);
glUniform3fv(*m_uniform_color, 1, color.data()); glUniform4fv(*m_uniform_color, 1, color.data());
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *m_idTexture); glBindTexture(GL_TEXTURE_2D, *m_idTexture);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
......
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