2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
#include "cairo-dock-draw-opengl.h"
26
#include "cairo-dock-particle-system.h"
28
static GLfloat s_pCornerCoords[8] = {0.0, 0.0,
33
void cairo_dock_render_particles_full (CairoParticleSystem *pParticleSystem, int iDepth)
35
_cairo_dock_enable_texture ();
37
if (pParticleSystem->bAddLuminance)
38
_cairo_dock_set_blend_over ();
39
//glBlendFunc (GL_SRC_ALPHA, GL_ONE);
41
_cairo_dock_set_blend_alpha ();
43
glBindTexture(GL_TEXTURE_2D, pParticleSystem->iTexture);
45
GLfloat *vertices = pParticleSystem->pVertices;
46
GLfloat *coords = pParticleSystem->pCoords;
47
GLfloat *colors = pParticleSystem->pColors;
48
GLfloat *vertices2 = &pParticleSystem->pVertices[pParticleSystem->iNbParticles * 4 * 3];
49
GLfloat *coords2 = &pParticleSystem->pCoords[pParticleSystem->iNbParticles * 4 * 2];
50
GLfloat *colors2 = &pParticleSystem->pColors[pParticleSystem->iNbParticles * 4 * 4];
54
GLfloat fHeight = pParticleSystem->fHeight;
59
for (i = 0; i < pParticleSystem->iNbParticles; i ++)
61
p = &pParticleSystem->pParticles[i];
62
if (p->iLife == 0 || iDepth * p->z < 0)
66
w = p->fWidth * p->fSizeFactor;
67
h = p->fHeight * p->fSizeFactor;
68
x = p->x * pParticleSystem->fWidth / 2;
69
y = p->y * pParticleSystem->fHeight;
80
if (pParticleSystem->bDirectionUp)
89
vertices[1] = fHeight - y + h;
90
vertices[4] = fHeight - y - h;
91
vertices[7] = fHeight - y - h;
92
vertices[10] = fHeight - y + h;
96
memcpy (coords, s_pCornerCoords, sizeof (s_pCornerCoords));
99
colors[0] = p->color[0];
100
colors[1] = p->color[1];
101
colors[2] = p->color[2];
102
colors[3] = p->color[3];
103
memcpy (colors + 4, colors, 4*sizeof (GLfloat));
104
memcpy (colors + 8, colors, 8*sizeof (GLfloat));
107
if (pParticleSystem->bAddLight)
111
vertices2[0] = x - w;
113
vertices2[3] = x - w;
115
vertices2[6] = x + w;
117
vertices2[9] = x + w;
119
if (pParticleSystem->bDirectionUp)
121
vertices2[1] = y + h;
122
vertices2[4] = y - h;
123
vertices2[7] = y - h;
124
vertices2[10] = y + h;
128
vertices2[1] = fHeight - y + h;
129
vertices2[4] = fHeight - y - h;
130
vertices2[7] = fHeight - y - h;
131
vertices2[10] = fHeight - y + h;
135
memcpy (coords2, s_pCornerCoords, sizeof (s_pCornerCoords));
141
colors2[3] = colors[3];
142
memcpy (colors2 + 4, colors2, 4*sizeof (GLfloat));
143
memcpy (colors2 + 8, colors2, 8*sizeof (GLfloat));
148
glEnableClientState(GL_COLOR_ARRAY);
149
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
150
glEnableClientState (GL_VERTEX_ARRAY);
152
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), pParticleSystem->pCoords);
153
glVertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), pParticleSystem->pVertices);
154
glColorPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), pParticleSystem->pColors);
156
glDrawArrays(GL_QUADS, 0, pParticleSystem->bAddLight ? numActive*2 : numActive);
158
glDisableClientState(GL_COLOR_ARRAY);
159
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
160
glDisableClientState (GL_VERTEX_ARRAY);
162
_cairo_dock_disable_texture ();
165
CairoParticleSystem *cairo_dock_create_particle_system (int iNbParticles, GLuint iTexture, double fWidth, double fHeight)
167
g_return_val_if_fail (iNbParticles > 0, NULL);
168
CairoParticleSystem *pParticleSystem = g_new0 (CairoParticleSystem, 1);
169
pParticleSystem->iNbParticles = iNbParticles;
170
pParticleSystem->pParticles = g_new0 (CairoParticle, iNbParticles);
172
pParticleSystem->iTexture = iTexture;
174
pParticleSystem->fWidth = fWidth;
175
pParticleSystem->fHeight = fHeight;
176
pParticleSystem->bDirectionUp = TRUE;
178
pParticleSystem->pVertices = malloc(iNbParticles * 4 * 3 * sizeof(GLfloat)*2);
179
pParticleSystem->pCoords = malloc(iNbParticles * 4 * 2 * sizeof(GLfloat)*2);
180
pParticleSystem->pColors = malloc(iNbParticles * 4 * 4 * sizeof(GLfloat)*2);
181
return pParticleSystem;
185
void cairo_dock_free_particle_system (CairoParticleSystem *pParticleSystem)
187
if (pParticleSystem == NULL)
190
g_free (pParticleSystem->pParticles);
192
free (pParticleSystem->pVertices);
193
free (pParticleSystem->pCoords);
194
free (pParticleSystem->pColors);
196
g_free (pParticleSystem);
200
gboolean cairo_dock_update_default_particle_system (CairoParticleSystem *pParticleSystem, CairoDockRewindParticleFunc pRewindParticle)
202
gboolean bAllParticlesEnded = TRUE;
205
for (i = 0; i < pParticleSystem->iNbParticles; i ++)
207
p = &(pParticleSystem->pParticles[i]);
209
p->fOscillation += p->fOmega;
210
p->x += p->vx + (p->z + 2)/3. * .02 * sin (p->fOscillation); // 3%
212
p->color[3] = 1.*p->iLife / p->iInitialLife;
213
p->fSizeFactor += p->fResizeSpeed;
217
if (pRewindParticle && p->iLife == 0)
219
pRewindParticle (p, pParticleSystem->dt);
221
if (bAllParticlesEnded && p->iLife != 0)
222
bAllParticlesEnded = FALSE;
224
else if (pRewindParticle)
225
pRewindParticle (p, pParticleSystem->dt);
227
return ! bAllParticlesEnded;