annotate XCodeiPhoneOS/Demos/src/fireworks.c @ 2429:2c55b72ba46e gsoc2008_iphone

testdyngles is exactly what it sounds like -- a version of testdyngl that uses OpenGL ES calls instead of OpenGL. Was necessary to create because glOrtho is called glOrthof in OpenGL ES, and OpenGL ES doesn't have glBegin() type semantics for specifying geometry.
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Fri, 15 Aug 2008 00:52:52 +0000
parents ac26bd83db1f
children
rev   line source
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
1 /*
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
2 * fireworks.c
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
3 * written by Holmes Futrell
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
4 * use however you want
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
5 */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
6
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
7 #include "SDL.h"
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
8 #include "SDL_opengles.h"
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
9 #include "common.h"
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
10 #include <math.h>
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
11 #include <time.h>
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
12
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
13 #define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
14 #define ACCEL 0.0001f /* acceleration due to gravity, units in pixels per millesecond squared */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
15 #define WIND_RESISTANCE 0.00005f /* acceleration per unit velocity due to wind resistance */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
16 #define MAX_PARTICLES 2000 /* maximum number of particles displayed at once */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
17
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
18 static GLuint particleTextureID; /* OpenGL particle texture id */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
19 static SDL_bool pointSizeExtensionSupported; /* is GL_OES_point_size_array supported ? */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
20 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
21 used to describe what type of particle a given struct particle is.
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
22 emitter - this particle flies up, shooting off trail particles, then finally explodes into dust particles.
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
23 trail - shoots off, following emitter particle
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
24 dust - radiates outwards from emitter explosion
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
25 */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
26 enum particleType {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
27 emitter = 0,
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
28 trail,
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
29 dust
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
30 };
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
31 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
32 struct particle is used to describe each particle displayed on screen
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
33 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
34 struct particle {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
35 GLfloat x; /* x position of particle */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
36 GLfloat y; /* y position of particle */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
37 GLubyte color[4]; /* rgba color of particle */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
38 GLfloat size; /* size of particle in pixels */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
39 GLfloat xvel; /* x velocity of particle in pixels per milesecond */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
40 GLfloat yvel; /* y velocity of particle in pixels per millescond */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
41 int isActive; /* if not active, then particle is overwritten */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
42 enum particleType type; /* see enum particleType */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
43 } particles[MAX_PARTICLES]; /* this array holds all our particles */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
44
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
45 static int num_active_particles; /* how many members of the particle array are actually being drawn / animated? */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
46
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
47 /* function declarations */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
48 void spawnTrailFromEmitter(struct particle *emitter);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
49 void spawnEmitterParticle(GLfloat x, GLfloat y);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
50 void explodeEmitter(struct particle *emitter);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
51 void initializeParticles(void);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
52 void initializeTexture();
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
53 int nextPowerOfTwo(int x);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
54 void drawParticles();
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
55 void stepParticles(void);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
56
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
57 /* helper function (used in texture loading)
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
58 returns next power of two greater than or equal to x
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
59 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
60 int nextPowerOfTwo(int x) {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
61 int val=1;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
62 while (val < x) {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
63 val *= 2;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
64 }
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
65 return val;
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
66 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
67 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
68 steps each active particle by timestep MILLESECONDS_PER_FRAME
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
69 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
70 void stepParticles(void) {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
71 int i;
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
72 struct particle *slot = particles;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
73 struct particle *curr = particles;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
74 for (i=0; i<num_active_particles; i++) {
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
75 /* is the particle actually active, or is it marked for deletion? */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
76 if (curr->isActive) {
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
77 /* is the particle off the screen? */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
78 if (curr->y > SCREEN_HEIGHT) curr->isActive = 0;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
79 else if (curr->y < 0) curr->isActive = 0;
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
80 if (curr->x > SCREEN_WIDTH) curr->isActive = 0;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
81 else if (curr->x < 0) curr->isActive = 0;
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
82
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
83 /* step velocity, then step position */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
84 curr->yvel += ACCEL * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
85 curr->xvel += 0.0f;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
86 curr->y += curr->yvel * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
87 curr->x += curr->xvel * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
88
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
89 /* particle behavior */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
90 if (curr->type == emitter) {
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
91 /* if we're an emitter, spawn a trail */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
92 spawnTrailFromEmitter(curr);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
93 /* if we've reached our peak, explode */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
94 if (curr->yvel > 0.0) {
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
95 explodeEmitter(curr);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
96 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
97 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
98 else {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
99 float speed = sqrt(curr->xvel*curr->xvel + curr->yvel*curr->yvel);
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
100 /* if wind resistance is not powerful enough to stop us completely,
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
101 then apply winde resistance, otherwise just stop us completely */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
102 if (WIND_RESISTANCE * MILLESECONDS_PER_FRAME < speed) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
103 float normx = curr->xvel / speed;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
104 float normy = curr->yvel / speed;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
105 curr->xvel -= normx * WIND_RESISTANCE * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
106 curr->yvel -= normy * WIND_RESISTANCE * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
107 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
108 else {
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
109 curr->xvel = curr->yvel = 0; /* stop particle */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
110 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
111
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
112 if (curr->color[3] <= MILLESECONDS_PER_FRAME * 0.1275f) {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
113 /* if this next step will cause us to fade out completely
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
114 then just mark for deletion */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
115 curr->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
116 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
117 else {
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
118 /* otherwise, let's fade a bit more */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
119 curr->color[3] -= MILLESECONDS_PER_FRAME * 0.1275f;
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
120 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
121
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
122 /* if we're a dust particle, shrink our size */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
123 if (curr->type == dust)
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
124 curr->size -= MILLESECONDS_PER_FRAME * 0.010f;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
125
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
126 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
127
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
128 /* if we're still active, pack ourselves in the array next
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
129 to the last active guy (pack the array tightly) */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
130 if (curr->isActive)
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
131 *(slot++) = *curr;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
132 } /* endif (curr->isActive) */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
133 curr++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
134 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
135 /* the number of active particles is computed as the difference between
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
136 old number of active particles, where slot points, and the
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
137 new size of the array, where particles points */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
138 num_active_particles = slot - particles;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
139 }
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
140 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
141 This draws all the particles shown on screen
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
142 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
143 void drawParticles() {
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
144
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
145 /* draw the background */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
146 glClear(GL_COLOR_BUFFER_BIT);
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
147
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
148 /* set up the position and color pointers */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
149 glVertexPointer(2, GL_FLOAT, sizeof(struct particle), particles);
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
150 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(struct particle), particles[0].color);
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
151
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
152 if (pointSizeExtensionSupported) {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
153 /* pass in our array of point sizes */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
154 glPointSizePointerOES(GL_FLOAT, sizeof(struct particle), &(particles[0].size));
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
155 }
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
156
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
157 /* draw our particles! */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
158 glDrawArrays(GL_POINTS, 0, num_active_particles);
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
159
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
160 /* update screen */
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
161 SDL_RenderPresent();
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
162
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
163 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
164 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
165 This causes an emitter to explode in a circular bloom of dust particles
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
166 */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
167 void explodeEmitter(struct particle *emitter) {
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
168 /* first off, we're done with this particle, so turn active off */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
169 emitter->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
170 int i;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
171 for (i=0; i<200; i++) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
172
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
173 if (num_active_particles >= MAX_PARTICLES)
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
174 return;
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
175
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
176 /* come up with a random angle and speed for new particle */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
177 float theta = randomFloat(0, 2.0f * 3.141592);
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
178 float exponent = 3.0f;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
179 float speed = randomFloat(0.00, powf(0.17, exponent));
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
180 speed = powf(speed, 1.0f / exponent);
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
181
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
182 /*select the particle at the end of our array */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
183 struct particle *p = &particles[num_active_particles];
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
184
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
185 /* set the particles properties */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
186 p->xvel = speed * cos(theta);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
187 p->yvel = speed * sin(theta);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
188 p->x = emitter->x + emitter->xvel;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
189 p->y = emitter->y + emitter->yvel;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
190 p->isActive = 1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
191 p->type = dust;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
192 p->size = 15;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
193 /* inherit emitter's color */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
194 p->color[0] = emitter->color[0];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
195 p->color[1] = emitter->color[1];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
196 p->color[2] = emitter->color[2];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
197 p->color[3] = 255;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
198 /* our array has expanded at the end */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
199 num_active_particles++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
200 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
201
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
202 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
203 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
204 This spawns a trail particle from an emitter
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
205 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
206 void spawnTrailFromEmitter(struct particle *emitter) {
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
207
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
208 if (num_active_particles >= MAX_PARTICLES)
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
209 return;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
210
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
211 /* select the particle at the slot at the end of our array */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
212 struct particle *p = &particles[num_active_particles];
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
213
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
214 /* set position and velocity to roughly that of the emitter */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
215 p->x = emitter->x + randomFloat(-3.0, 3.0);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
216 p->y = emitter->y + emitter->size / 2.0f;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
217 p->xvel = emitter->xvel + randomFloat(-0.005, 0.005);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
218 p->yvel = emitter->yvel + 0.1;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
219
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
220 /* set the color to a random-ish orangy type color */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
221 p->color[0] = (0.8f + randomFloat(-0.1, 0.0)) * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
222 p->color[1] = (0.4f + randomFloat(-0.1, 0.1)) * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
223 p->color[2] = (0.0f + randomFloat(0.0, 0.2)) * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
224 p->color[3] = (0.7f) * 255;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
225
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
226 /* set other attributes */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
227 p->size = 10;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
228 p->type = trail;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
229 p->isActive = 1;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
230
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
231 /* our array has expanded at the end */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
232 num_active_particles++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
233
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
234 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
235 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
236 spawns a new emitter particle at the bottom of the screen
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
237 destined for the point (x,y).
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
238 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
239 void spawnEmitterParticle(GLfloat x, GLfloat y) {
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
240
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
241 if (num_active_particles >= MAX_PARTICLES)
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
242 return;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
243
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
244 /* find particle at endpoint of array */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
245 struct particle *p = &particles[num_active_particles];
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
246
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
247 /* set the color randomly */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
248 switch(rand() % 4) {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
249 case 0:
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
250 p->color[0] = 255;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
251 p->color[1] = 100;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
252 p->color[2] = 100;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
253 break;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
254 case 1:
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
255 p->color[0] = 100;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
256 p->color[1] = 255;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
257 p->color[2] = 100;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
258 break;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
259 case 2:
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
260 p->color[0] = 100;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
261 p->color[1] = 100;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
262 p->color[2] = 255;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
263 break;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
264 case 3:
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
265 p->color[0] = 255;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
266 p->color[1] = 150;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
267 p->color[2] = 50;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
268 break;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
269 }
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
270 p->color[3] = 255;
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
271 /* set position to (x, SCREEN_HEIGHT) */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
272 p->x = x;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
273 p->y = SCREEN_HEIGHT;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
274 /* set velocity so that terminal point is (x,y) */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
275 p->xvel = 0;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
276 p->yvel = -sqrt(2*ACCEL*(SCREEN_HEIGHT-y));
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
277 /* set other attributes */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
278 p->size = 10;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
279 p->type = emitter;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
280 p->isActive = 1;
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
281 /* our array has expanded at the end */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
282 num_active_particles++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
283 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
284
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
285 /* just sets the endpoint of the particle array to element zero */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
286 void initializeParticles(void) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
287 num_active_particles = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
288 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
289
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
290 /*
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
291 loads the particle texture
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
292 */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
293 void initializeTexture() {
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
294
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
295 int bpp; /* texture bits per pixel */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
296 Uint32 Rmask, Gmask, Bmask, Amask; /* masks for pixel format passed into OpenGL */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
297 SDL_Surface *bmp_surface; /* the bmp is loaded here */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
298 SDL_Surface *bmp_surface_rgba8888; /* this serves as a destination to convert the BMP
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
299 to format passed into OpenGL */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
300
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
301 bmp_surface = SDL_LoadBMP("stroke.bmp");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
302 if (bmp_surface == NULL) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
303 fatalError("could not load stroke.bmp");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
304 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
305
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
306 /* Grab info about format that will be passed into OpenGL */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
307 SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
308 /* Create surface that will hold pixels passed into OpenGL */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
309 bmp_surface_rgba8888 = SDL_CreateRGBSurface(0, bmp_surface->w, bmp_surface->h, bpp, Rmask, Gmask, Bmask, Amask);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
310 /* Blit to this surface, effectively converting the format */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
311 SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba8888, NULL);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
312
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
313 glGenTextures(1, &particleTextureID);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
314 glBindTexture(GL_TEXTURE_2D, particleTextureID);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
315 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,\
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
316 nextPowerOfTwo(bmp_surface->w),\
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
317 nextPowerOfTwo(bmp_surface->h),\
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
318 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
321 /* this is where we actually pass in the pixel data */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
322 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmp_surface->w, bmp_surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bmp_surface_rgba8888->pixels);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
323
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
324 /* free bmp surface and converted bmp surface */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
325 SDL_FreeSurface(bmp_surface);
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
326 SDL_FreeSurface(bmp_surface_rgba8888);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
327
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
328 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
329
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
330 int main(int argc, char *argv[]) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
331
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
332 SDL_WindowID windowID; /* ID of main window */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
333 Uint32 startFrame; /* time frame began to process */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
334 Uint32 endFrame; /* time frame ended processing */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
335 Uint32 delay; /* time to pause waiting to draw next frame */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
336 int done; /* should we clean up and exit? */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
337
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
338 /* initialize SDL */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
339 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
340 fatalError("Could not initialize SDL");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
341 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
342 /* seed the random number generator */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
343 srand(time(NULL));
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
344 /*
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
345 request some OpenGL parameters
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
346 that may speed drawing
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
347 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
348 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
349 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
350 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
351 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
352 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
353 SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
354 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
355
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
356 /* create main window and renderer */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
357 windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,\
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
358 SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
359 SDL_CreateRenderer(windowID, 0, 0);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
360
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
361 /* load the particle texture */
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
362 initializeTexture();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
363
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
364 /* check if GL_POINT_SIZE_ARRAY_OES is supported
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
365 this is used to give each particle its own size
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
366 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
367 pointSizeExtensionSupported = SDL_GL_ExtensionSupported("GL_OES_point_size_array");
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
368
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
369 /* set up some OpenGL state */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
370 glEnable(GL_TEXTURE_2D);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
371 glEnable(GL_BLEND);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
372 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
373 glEnableClientState(GL_VERTEX_ARRAY);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
374 glEnableClientState(GL_COLOR_ARRAY);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
375
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
376 glEnable(GL_POINT_SPRITE_OES);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
377 glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, 1);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
378
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
379 if (pointSizeExtensionSupported) {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
380 /* we use this to set the sizes of all the particles */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
381 glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
382 }
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
383 else {
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
384 /* if extension not available then all particles have size 10 */
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
385 glPointSize(10);
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
386 }
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
387
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
388 done = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
389 /* enter main loop */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
390 while(!done) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
391 startFrame = SDL_GetTicks();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
392 SDL_Event event;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
393 while (SDL_PollEvent(&event)) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
394 if (event.type == SDL_QUIT) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
395 done = 1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
396 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
397 if (event.type == SDL_MOUSEBUTTONDOWN) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
398 int which = event.button.which;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
399 int x, y;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
400 SDL_SelectMouse(which);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
401 SDL_GetMouseState(&x, &y);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
402 spawnEmitterParticle(x, y);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
403 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
404 }
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
405 stepParticles();
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
406 drawParticles();
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
407 endFrame = SDL_GetTicks();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
408
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
409 /* figure out how much time we have left, and then sleep */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
410 delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
411 if (delay > MILLESECONDS_PER_FRAME) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
412 delay = MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
413 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
414 if (delay > 0) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
415 SDL_Delay(delay);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
416 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
417 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
418
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
419 /* delete textures */
2417
ac26bd83db1f Cleaned up code, added comments, added randomized colors, added check for extension GL_POINT_SIZE_ARRAY_OES, which not all OpenGL ES systems have.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2382
diff changeset
420 glDeleteTextures(1, &particleTextureID);
2382
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
421 /* shutdown SDL */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
422 SDL_Quit();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
423
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
424 return 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
425 }