annotate Xcode-iPhoneOS/Demos/src/fireworks.c @ 5271:e107518710f6

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