annotate XCodeiPhoneOS/Demos/src/fireworks.c @ 2385:0705e8ebe951 gsoc2008_iphone

Rectangles demo (SDL_RenderFill)
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Fri, 18 Jul 2008 20:52:18 +0000
parents 36bcf13ccb48
children ac26bd83db1f
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"
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
8 #include "math.h"
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 #include <OpenGLES/ES1/gl.h>
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
13
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
14 #define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
15 #define ACCEL 0.0001f
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
16 #define WIND_RESISTANCE 0.00005f
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
17 #define MAX_PARTICLES 2000
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
18 #define VEL_BEFORE_EXPLODE 0.0f
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
19
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
20 SDL_TextureID flashTextureID;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
21
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
22
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
23 enum particleType {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
24 emitter = 0,
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
25 trail,
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
26 dust
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
27 };
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
28
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
29 struct glformat {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
30 int SDL_GL_RED_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
31 int SDL_GL_GREEN_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
32 int SDL_GL_BLUE_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
33 int SDL_GL_ALPHA_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
34 int SDL_GL_BUFFER_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
35 int SDL_GL_DOUBLEBUFFER;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
36 int SDL_GL_DEPTH_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
37 int SDL_GL_STENCIL_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
38 int SDL_GL_ACCUM_RED_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
39 int SDL_GL_ACCUM_GREEN_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
40 int SDL_GL_ACCUM_BLUE_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
41 int SDL_GL_ACCUM_ALPHA_SIZE;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
42 int SDL_GL_STEREO;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
43 int SDL_GL_MULTISAMPLEBUFFERS;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
44 int SDL_GL_MULTISAMPLESAMPLES;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
45 int SDL_GL_ACCELERATED_VISUAL;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
46 int SDL_GL_RETAINED_BACKING;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
47 };
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
48
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
49 struct particle {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
50
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
51 GLfloat x;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
52 GLfloat y;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
53 GLubyte color[4];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
54 GLfloat size;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
55 GLfloat xvel;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
56 GLfloat yvel;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
57 int isActive;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
58 enum particleType type;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
59 int framesSinceEmission;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
60 } particles[MAX_PARTICLES];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
61
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
62 void spawnParticleFromEmitter(struct particle *emitter);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
63 void explodeEmitter(struct particle *emitter);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
64
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
65 static int num_active_particles;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
66
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
67 static void getError(const char *prefix)
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
68 {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
69 const char *error;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
70
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
71 GLenum result = glGetError();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
72 if (result == GL_NO_ERROR)
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
73 return;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
74
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
75 switch (result) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
76 case GL_NO_ERROR:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
77 error = "GL_NO_ERROR";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
78 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
79 case GL_INVALID_ENUM:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
80 error = "GL_INVALID_ENUM";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
81 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
82 case GL_INVALID_VALUE:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
83 error = "GL_INVALID_VALUE";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
84 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
85 case GL_INVALID_OPERATION:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
86 error = "GL_INVALID_OPERATION";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
87 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
88 case GL_STACK_OVERFLOW:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
89 error = "GL_STACK_OVERFLOW";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
90 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
91 case GL_STACK_UNDERFLOW:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
92 error = "GL_STACK_UNDERFLOW";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
93 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
94 case GL_OUT_OF_MEMORY:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
95 error = "GL_OUT_OF_MEMORY";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
96 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
97 default:
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
98 error = "UNKNOWN";
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
99 break;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
100 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
101 printf("%s: %s\n", prefix, error);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
102 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
103
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
104 void render(void) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
105
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
106 /* draw the background */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
107 glClear(GL_COLOR_BUFFER_BIT);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
108
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
109 struct particle *slot = particles;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
110 struct particle *curr = particles;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
111 int i;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
112 for (i=0; i<num_active_particles; i++) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
113 if (curr->isActive) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
114
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
115 if (curr->y > SCREEN_HEIGHT) curr->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
116 if (curr->y < 0) curr->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
117 if (curr->x > SCREEN_WIDTH) curr->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
118 if (curr->x < 0) curr->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
119
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
120 curr->yvel += ACCEL * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
121 curr->xvel += 0.0f;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
122 curr->y += curr->yvel * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
123 curr->x += curr->xvel * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
124
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
125 if (curr->type == emitter) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
126 spawnParticleFromEmitter(curr);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
127 curr->framesSinceEmission = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
128 if (curr->yvel > -VEL_BEFORE_EXPLODE) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
129 explodeEmitter(curr);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
130 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
131 curr->framesSinceEmission++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
132 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
133 else {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
134
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
135 float speed = sqrt(curr->xvel*curr->xvel + curr->yvel*curr->yvel);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
136
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
137 if (WIND_RESISTANCE * MILLESECONDS_PER_FRAME < speed) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
138 float normx = curr->xvel / speed;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
139 float normy = curr->yvel / speed;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
140 curr->xvel -= normx * WIND_RESISTANCE * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
141 curr->yvel -= normy * WIND_RESISTANCE * MILLESECONDS_PER_FRAME;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
142 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
143 else {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
144 curr->xvel = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
145 curr->yvel = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
146 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
147
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
148 if (curr->color[3] <= MILLESECONDS_PER_FRAME * 0.0005f * 255) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
149 curr->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
150
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
151 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
152 else {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
153 curr->color[3] -= MILLESECONDS_PER_FRAME * 0.0005f * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
154 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
155
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
156 if (curr->type == dust)
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
157 curr->size -= MILLESECONDS_PER_FRAME * 0.010f;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
158
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
159 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
160
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
161 *(slot++) = *curr;
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 curr++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
164 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
165 num_active_particles = slot - particles;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
166
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
168 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
169 glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, 1);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
170
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
171 glEnableClientState(GL_VERTEX_ARRAY);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
172 glVertexPointer(2, GL_FLOAT, sizeof(struct particle), particles + 0);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
173 getError("vertices");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
174
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
175 glEnableClientState(GL_COLOR_ARRAY);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
176 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(struct particle), particles[0].color);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
177 getError("colors");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
178
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
179 glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
180 getError("enable client state");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
181 glPointSizePointerOES(GL_FLOAT, sizeof(struct particle), &(particles[0].size));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
182 getError("point size");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
183
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
184 glEnable(GL_POINT_SPRITE_OES);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
185 glDrawArrays(GL_POINTS, 0, num_active_particles);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
186 getError("glDrawArrays");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
187
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
188
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
189 /* update screen */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
190 SDL_RenderPresent();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
191
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
192 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
193
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
194 void printOpenGLAttributes(struct glformat *format) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
195 printf("\tSDL_GL_RED_SIZE = %d\n", format->SDL_GL_RED_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
196 printf("\tSDL_GL_GREEN_SIZE = %d\n", format->SDL_GL_GREEN_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
197 printf("\tSDL_GL_BLUE_SIZE = %d\n", format->SDL_GL_BLUE_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
198 printf("\tSDL_GL_ALPHA_SIZE = %d\n", format->SDL_GL_ALPHA_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
199 printf("\tSDL_GL_BUFFER_SIZE = %d\n", format->SDL_GL_BUFFER_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
200 printf("\tSDL_GL_DOUBLEBUFFER = %d\n", format->SDL_GL_DOUBLEBUFFER);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
201 printf("\tSDL_GL_DEPTH_SIZE = %d\n", format->SDL_GL_DEPTH_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
202 printf("\tSDL_GL_STENCIL_SIZE = %d\n", format->SDL_GL_STENCIL_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
203 printf("\tSDL_GL_ACCUM_RED_SIZE = %d\n", format->SDL_GL_ACCUM_RED_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
204 printf("\tSDL_GL_ACCUM_GREEN_SIZE = %d\n", format->SDL_GL_ACCUM_GREEN_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
205 printf("\tSDL_GL_ACCUM_BLUE_SIZE = %d\n", format->SDL_GL_ACCUM_BLUE_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
206 printf("\tSDL_GL_ACCUM_ALPHA_SIZE = %d\n", format->SDL_GL_ACCUM_ALPHA_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
207 printf("\tSDL_GL_STEREO = %d\n", format->SDL_GL_STEREO);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
208 printf("\tSDL_GL_MULTISAMPLEBUFFERS = %d\n", format->SDL_GL_MULTISAMPLEBUFFERS);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
209 printf("\tSDL_GL_MULTISAMPLESAMPLES = %d\n", format->SDL_GL_MULTISAMPLESAMPLES);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
210 printf("\tSDL_GL_ACCELERATED_VISUAL = %d\n", format->SDL_GL_ACCELERATED_VISUAL);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
211 printf("\tSDL_GL_RETAINED_BACKING = %d\n", format->SDL_GL_RETAINED_BACKING);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
212 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
213
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
214 void setOpenGLAttributes(struct glformat *format) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
215 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, format->SDL_GL_RED_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
216 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, format->SDL_GL_GREEN_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
217 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, format->SDL_GL_BLUE_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
218 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, format->SDL_GL_ALPHA_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
219 SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, format->SDL_GL_BUFFER_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
220 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, format->SDL_GL_DOUBLEBUFFER);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
221 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, format->SDL_GL_DEPTH_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
222 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, format->SDL_GL_STENCIL_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
223 SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, format->SDL_GL_ACCUM_RED_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
224 SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, format->SDL_GL_ACCUM_GREEN_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
225 SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, format->SDL_GL_ACCUM_BLUE_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
226 SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, format->SDL_GL_ACCUM_ALPHA_SIZE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
227 SDL_GL_SetAttribute(SDL_GL_STEREO, format->SDL_GL_STEREO);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
228 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, format->SDL_GL_MULTISAMPLEBUFFERS);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
229 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, format->SDL_GL_MULTISAMPLESAMPLES);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
230 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, format->SDL_GL_ACCELERATED_VISUAL);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
231 SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, format->SDL_GL_RETAINED_BACKING);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
232 }
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 void getOpenGLAttributes(struct glformat *format) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
235
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
236 SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &(format->SDL_GL_RED_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
237 SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &(format->SDL_GL_GREEN_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
238 SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &(format->SDL_GL_BLUE_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
239 SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &(format->SDL_GL_ALPHA_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
240 SDL_GL_GetAttribute(SDL_GL_BUFFER_SIZE, &(format->SDL_GL_BUFFER_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
241 SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &(format->SDL_GL_DOUBLEBUFFER));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
242 SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &(format->SDL_GL_DEPTH_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
243 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &(format->SDL_GL_STENCIL_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
244 SDL_GL_GetAttribute(SDL_GL_ACCUM_RED_SIZE, &(format->SDL_GL_ACCUM_RED_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
245 SDL_GL_GetAttribute(SDL_GL_ACCUM_GREEN_SIZE, &(format->SDL_GL_ACCUM_GREEN_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
246 SDL_GL_GetAttribute(SDL_GL_ACCUM_BLUE_SIZE, &(format->SDL_GL_ACCUM_BLUE_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
247 SDL_GL_GetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, &(format->SDL_GL_ACCUM_ALPHA_SIZE));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
248 SDL_GL_GetAttribute(SDL_GL_STEREO, &(format->SDL_GL_STEREO));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
249 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &(format->SDL_GL_MULTISAMPLEBUFFERS));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
250 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &(format->SDL_GL_MULTISAMPLESAMPLES));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
251 SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &(format->SDL_GL_ACCELERATED_VISUAL));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
252 SDL_GL_GetAttribute(SDL_GL_RETAINED_BACKING, &(format->SDL_GL_RETAINED_BACKING));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
253 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
254
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
255 void explodeEmitter(struct particle *emitter) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
256
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
257 emitter->isActive = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
258
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
259 int i;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
260 for (i=0; i<200; i++) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
261
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
262 if (num_active_particles >= MAX_PARTICLES) return;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
263
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
264 float theta = randomFloat(0, 2.0f * 3.141592);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
265 float max = 3.0f;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
266 float speed = randomFloat(0.00, powf(0.17, max));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
267 speed = powf(speed, 1.0f / max);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
268
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
269 struct particle *p = &particles[num_active_particles];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
270 p->xvel = speed * cos(theta);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
271 p->yvel = speed * sin(theta);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
272 p->x = emitter->x + emitter->xvel;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
273 p->y = emitter->y + emitter->yvel;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
274 p->isActive = 1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
275 p->type = dust;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
276 p->color[0] = emitter->color[0];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
277 p->color[1] = emitter->color[1];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
278 p->color[2] = emitter->color[2];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
279 p->color[3] = 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
280
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
281 p->size = 15;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
282
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
283 num_active_particles++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
284
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
285 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
286
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
287 }
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 void spawnParticleFromEmitter(struct particle *emitter) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
290
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
291 if (num_active_particles >= MAX_PARTICLES) return;
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 struct particle *p = &particles[num_active_particles];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
294 p->x = emitter->x + randomFloat(-3.0, 3.0);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
295 p->y = emitter->y + emitter->size / 2.0f;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
296 p->xvel = emitter->xvel + randomFloat(-0.005, 0.005);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
297 p->yvel = emitter->yvel + 0.1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
298 p->color[0] = (0.8f + randomFloat(-0.1, 0.0)) * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
299 p->color[1] = (0.4f + randomFloat(-0.1, 0.1)) * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
300 p->color[2] = (0.0f + randomFloat(0.0, 0.2)) * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
301 p->color[3] = (0.7f) * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
302 p->size = 10;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
303 p->type = trail;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
304 p->isActive = 1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
305 num_active_particles++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
306
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
307 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
308
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
309 void spawnEmitterParticle(int x, int y) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
310
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
311 if (num_active_particles >= MAX_PARTICLES) return;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
312
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
313 struct particle *p = &particles[num_active_particles];
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
314 p->x = x;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
315 p->y = SCREEN_HEIGHT;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
316 p->xvel = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
317 p->yvel = -sqrt(2*ACCEL*(SCREEN_HEIGHT-y) + VEL_BEFORE_EXPLODE * VEL_BEFORE_EXPLODE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
318 p->color[0] = 1.0 * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
319 p->color[1] = 0.4 * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
320 p->color[2] = 0.4 * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
321 p->color[3] = 1.0f * 255;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
322 p->size = 10;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
323 p->type = emitter;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
324 p->framesSinceEmission = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
325 p->isActive = 1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
326 num_active_particles++;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
327 }
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 void initializeParticles(void) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
330
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
331 num_active_particles = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
332
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
333 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
334
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
335 /*
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
336 loads the brush texture
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 void initializeTexture() {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
339 SDL_Surface *bmp_surface;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
340 bmp_surface = SDL_LoadBMP("stroke.bmp");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
341 if (bmp_surface == NULL) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
342 fatalError("could not load stroke.bmp");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
343 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
344 flashTextureID = SDL_CreateTextureFromSurface(SDL_PIXELFORMAT_ABGR8888, bmp_surface);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
345 SDL_FreeSurface(bmp_surface);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
346 if (flashTextureID == 0) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
347 fatalError("could not create brush texture");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
348 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
349 glEnable(GL_TEXTURE_2D);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
350 glEnable(GL_BLEND);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
351 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
352 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
353
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
354 int main(int argc, char *argv[]) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
355
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
356 SDL_WindowID windowID; /* ID of main window */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
357 Uint32 startFrame; /* time frame began to process */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
358 Uint32 endFrame; /* time frame ended processing */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
359 Uint32 delay; /* time to pause waiting to draw next frame */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
360 int done; /* should we clean up and exit? */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
361
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
362 struct glformat requested, obtained;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
363
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
364 /* initialize SDL */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
365 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
366 fatalError("Could not initialize SDL");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
367 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
368
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
369 srand(time(NULL));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
370
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
371 SDL_GL_LoadLibrary(NULL);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
372
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
373 SDL_memset(&requested, 0, sizeof(requested));
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
374 requested.SDL_GL_RED_SIZE = 5;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
375 requested.SDL_GL_GREEN_SIZE = 6;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
376 requested.SDL_GL_BLUE_SIZE = 5;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
377 requested.SDL_GL_ALPHA_SIZE = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
378 requested.SDL_GL_DEPTH_SIZE = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
379 requested.SDL_GL_RETAINED_BACKING = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
380 requested.SDL_GL_ACCELERATED_VISUAL = 1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
381
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
382 setOpenGLAttributes(&requested);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
383
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
384 /* create main window and renderer */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
385 windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,\
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
386 SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
387 SDL_CreateRenderer(windowID, 0, 0);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
388
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
389 printf("Requested:\n");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
390 printOpenGLAttributes(&requested);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
391
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
392 printf("obtained:\n");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
393 getOpenGLAttributes(&obtained);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
394 printOpenGLAttributes(&obtained);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
395
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
396 initializeTexture();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
397
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
398 done = 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
399 /* enter main loop */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
400 while(!done) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
401 startFrame = SDL_GetTicks();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
402 SDL_Event event;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
403 while (SDL_PollEvent(&event)) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
404 if (event.type == SDL_QUIT) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
405 done = 1;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
406 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
407 if (event.type == SDL_MOUSEBUTTONDOWN) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
408 printf("mouse down\n");
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
409 int which = event.button.which;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
410 int x, y;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
411 SDL_SelectMouse(which);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
412 SDL_GetMouseState(&x, &y);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
413 spawnEmitterParticle(x, y);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
414 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
415 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
416 render();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
417 endFrame = SDL_GetTicks();
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 /* figure out how much time we have left, and then sleep */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
420 delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
421 if (delay > MILLESECONDS_PER_FRAME) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
422 delay = MILLESECONDS_PER_FRAME;
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 if (delay > 0) {
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
425 SDL_Delay(delay);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
426 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
427
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
428 //SDL_Delay(delay);
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
429 }
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
430
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
431 /* delete textures */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
432
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
433 /* shutdown SDL */
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
434 SDL_Quit();
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
435
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
436 return 0;
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
437
36bcf13ccb48 fireworks demo
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
438 }