GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_pointsprite.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  Copyright (C) 2009 Laurent Bauer
6  http://glc-lib.sourceforge.net
7 
8  GLC-lib is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  GLC-lib is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with GLC-lib; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22  *****************************************************************************/
24 
25 #include "glc_pointsprite.h"
26 #include "../glc_openglexception.h"
27 #include "../glc_state.h"
28 #include "../glc_ext.h"
29 #include "../shading/glc_selectionmaterial.h"
30 #include "../glc_context.h"
31 
32 // The maximum point size
33 float GLC_PointSprite::m_MaxSize= -1.0f;
34 
35 // Default constructor
38 , m_Size(size)
39 , m_DistanceAttenuation(3)
40 , m_FadeThresoldSize(60.0f)
41 {
42  Q_ASSERT(pMaterial != NULL);
43  Q_ASSERT(pMaterial->hasTexture());
44  addMaterial(pMaterial);
45 
46  // Set Distance attenuation defaults values
47  m_DistanceAttenuation[0]= 1.0f;
48  m_DistanceAttenuation[1]= 0.0f;
49  m_DistanceAttenuation[2]= 0.0f;
50 
51  QList<GLC_Point3d> points;
52  points.append(GLC_Point3d(0.0, 0.0, 0.0));
54 }
55 
57 : GLC_PointCloud(point)
58 , m_Size(point.m_Size)
59 , m_DistanceAttenuation(point.m_DistanceAttenuation)
60 , m_FadeThresoldSize(point.m_FadeThresoldSize)
61 {
62 
63 }
64 
66 {
67 
68 }
69 
70 // Return a copy of the current geometry
72 {
73  return new GLC_PointSprite(*this);
74 }
75 
76 // Return the point size
77 void GLC_PointSprite::setSize(float size)
78 {
79  m_GeometryIsValid= false;
80  m_Size= size;
81  // Clamp m_Size to m_MaxSize
82  if(qFuzzyCompare(-1.0f, m_MaxSize) && (m_MaxSize < m_Size))
83  {
85  }
86 }
87 
88 // Set the point distance attenuation values
89 void GLC_PointSprite::setPointDistanceAttenuation(QVector<float> parameters)
90 {
91  Q_ASSERT(3 == parameters.size());
92  m_DistanceAttenuation= parameters;
93 }
94 
96 // OpenGL Functions
98 // Specific glExecute method
99 void GLC_PointSprite::render(const GLC_RenderProperties& renderProperties)
100 {
101  // Check if extension GL_ARB_point_parameters is present
102  if (!GLC_State::pointSpriteSupported()) return;
103 
104  glPushAttrib(GL_ALL_ATTRIB_BITS);
105 
107  {
108  glEnable( GL_BLEND );
109  glDepthMask(GL_FALSE);
110  glEnable(GL_TEXTURE_2D);
111  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
112  glDisable(GL_LIGHTING);
113  //GLC_Context::current()->glcEnableLighting(false);
114 
115  if(m_MaterialHash.size() == 1)
116  {
117 
118  if (renderProperties.isSelected())
119  {
121  }
122  else
123  {
124  GLC_Material* pCurrentMaterial= m_MaterialHash.begin().value();
125  const GLfloat red= pCurrentMaterial->diffuseColor().redF();
126  const GLfloat green= pCurrentMaterial->diffuseColor().greenF();
127  const GLfloat blue= pCurrentMaterial->diffuseColor().blueF();
128  const GLfloat alpha= pCurrentMaterial->diffuseColor().alphaF();
129 
130  glColor4f(red, green, blue, alpha);
131  pCurrentMaterial->glExecute();
132 
133  }
134  }
135  }
136  else
137  {
138  glDisable(GL_BLEND);
139  glDisable(GL_TEXTURE_2D);
140  glDisable(GL_LIGHTING);
141  //GLC_Context::current()->glcEnableLighting(false);
142  }
143 
144 
145  // Executed only the first time
146  if (qFuzzyCompare(-1.0f, m_MaxSize))
147  {
148  // Query for the max point size supported by the hardware
149  glGetFloatv(GL_POINT_SIZE_MAX, &m_MaxSize);
150 
151  // Clamp m_Size to m_MaxSize
152  if(m_MaxSize < m_Size)
153  m_Size= m_MaxSize;
154  }
155 
156  // This is how will our point sprite's size will be modified by
157  // distance from the viewer
158  glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, m_DistanceAttenuation.data());
159  glPointSize(m_Size);
160 
161  // The alpha of a point is calculated to allow the fading of points
162  // instead of shrinking them past a defined threshold size. The threshold
163  // is defined by GL_POINT_FADE_THRESHOLD_SIZE_ARB and is not clamped to
164  // the minimum and maximum point sizes.
165  glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, m_FadeThresoldSize);
166 
167  glPointParameterf(GL_POINT_SIZE_MIN, 1.0f);
168  glPointParameterf(GL_POINT_SIZE_MAX, m_Size);
169 
170  // Specify point sprite texture coordinate replacement mode for each
171  // texture unit
172  glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
173 
174  glEnable(GL_POINT_SPRITE);
175  glDraw(renderProperties);
176 
177  glPopAttrib();
178 
179 }
180 // Point sprite set up
181 void GLC_PointSprite::glDraw(const GLC_RenderProperties& renderProperties)
182 {
183  GLC_PointCloud::glDraw(renderProperties);
184 }
185 

©2005-2013 Laurent Ribon