annotate android/project/jni/lesson05.c @ 4898:164bee619400

XDamageDestroy is called before use_damage is tested. This crashes on my setup. The patch calls XDamageDestroy only when use_damage is true. Kind regards, André
author Sam Lantinga <slouken@libsdl.org>
date Mon, 27 Sep 2010 00:49:56 -0700
parents 9076cdb027af
children
rev   line source
4726
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
1 /*
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
2 * This code was created by Jeff Molofee '99
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
3 * (ported to Linux/SDL by Ti Leggett '01)
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
4 *
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
5 * If you've found this code useful, please let me know.
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
6 *
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
7 * Visit Jeff at http://nehe.gamedev.net/
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
8 *
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
9 * or for port-specific comments, questions, bugreports etc.
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
10 * email to leggett@eecs.tulane.edu
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
11 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
12
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
13 #include <stdio.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
14 #include <stdlib.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
15 #include <math.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
16
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
17 #include <signal.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
18
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
19 #include <android/log.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
20
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
21
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
22 #ifdef ANDROID
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
23 #include <GLES/gl.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
24 #else
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
25 #include <GL/gl.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
26 #include <GL/glu.h>
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
27 #endif
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
28 #include "SDL.h"
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
29
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
30 /* screen width, height, and bit depth */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
31 #define SCREEN_WIDTH 320
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
32 #define SCREEN_HEIGHT 430
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
33 #define SCREEN_BPP 16
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
34
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
35 /* Define our booleans */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
36 #define TRUE 1
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
37 #define FALSE 0
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
38
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
39 /* This is our SDL surface */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
40 SDL_Surface *surface;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
41
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
42 int rotation = 0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
43
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
44
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
45 /**************************************
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
46 gluperspective implementation
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
47 **************************************/
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
48 void gluPerspective(double fovy, double aspect, double zNear, double zFar){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
49 glMatrixMode(GL_PROJECTION);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
50 glLoadIdentity();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
51 double xmin, xmax, ymin, ymax;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
52 ymax = zNear * tan(fovy * M_PI / 360.0);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
53 ymin = -ymax;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
54 xmin = ymin * aspect;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
55 xmax = ymax * aspect;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
56 glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
57 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
58
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
59
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
60 /**************************************
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
61 glulookat implementation
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
62 **************************************/
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
63 void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
64 GLfloat centerx, GLfloat centery, GLfloat centerz,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
65 GLfloat upx, GLfloat upy, GLfloat upz)
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
66 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
67 GLfloat m[16];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
68 GLfloat x[3], y[3], z[3];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
69 GLfloat mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
70
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
71 /* Make rotation matrix */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
72
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
73 /* Z vector */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
74 z[0] = eyex - centerx;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
75 z[1] = eyey - centery;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
76 z[2] = eyez - centerz;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
77 mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
78 if (mag) { /* mpichler, 19950515 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
79 z[0] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
80 z[1] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
81 z[2] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
82 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
83
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
84 /* Y vector */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
85 y[0] = upx;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
86 y[1] = upy;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
87 y[2] = upz;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
88
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
89 /* X vector = Y cross Z */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
90 x[0] = y[1] * z[2] - y[2] * z[1];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
91 x[1] = -y[0] * z[2] + y[2] * z[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
92 x[2] = y[0] * z[1] - y[1] * z[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
93
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
94 /* Recompute Y = Z cross X */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
95 y[0] = z[1] * x[2] - z[2] * x[1];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
96 y[1] = -z[0] * x[2] + z[2] * x[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
97 y[2] = z[0] * x[1] - z[1] * x[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
98
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
99 /* mpichler, 19950515 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
100 /* cross product gives area of parallelogram, which is < 1.0 for
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
101 * non-perpendicular unit-length vectors; so normalize x, y here
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
102 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
103
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
104 mag = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
105 if (mag) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
106 x[0] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
107 x[1] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
108 x[2] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
109 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
110
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
111 mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
112 if (mag) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
113 y[0] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
114 y[1] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
115 y[2] /= mag;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
116 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
117
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
118 #define M(row,col) m[col*4+row]
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
119 M(0, 0) = x[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
120 M(0, 1) = x[1];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
121 M(0, 2) = x[2];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
122 M(0, 3) = 0.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
123 M(1, 0) = y[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
124 M(1, 1) = y[1];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
125 M(1, 2) = y[2];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
126 M(1, 3) = 0.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
127 M(2, 0) = z[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
128 M(2, 1) = z[1];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
129 M(2, 2) = z[2];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
130 M(2, 3) = 0.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
131 M(3, 0) = 0.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
132 M(3, 1) = 0.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
133 M(3, 2) = 0.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
134 M(3, 3) = 1.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
135 #undef M
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
136 glMultMatrixf(m);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
137
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
138 /* Translate Eye to Origin */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
139 glTranslatef(-eyex, -eyey, -eyez);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
140
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
141 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
142
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
143
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
144
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
145
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
146
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
147 /* function to release/destroy our resources and restoring the old desktop */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
148 void Quit( int returnCode )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
149 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
150 /* clean up the window */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
151 SDL_Quit( );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
152
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
153 /* and exit appropriately */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
154 exit( returnCode );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
155 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
156
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
157 /* function to reset our viewport after a window resize */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
158 int resizeWindow( int width, int height )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
159 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
160 /* Height / width ration */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
161 GLfloat ratio;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
162
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
163 /* Protect against a divide by zero */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
164 if ( height == 0 )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
165 height = 1;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
166
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
167 ratio = ( GLfloat )width / ( GLfloat )height;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
168
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
169 /* Setup our viewport. */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
170 glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
171
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
172 /* change to the projection matrix and set our viewing volume. */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
173 glMatrixMode( GL_PROJECTION );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
174 glLoadIdentity( );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
175
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
176 /* Set our perspective */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
177 gluPerspective( 45.0f, ratio, 0.1f, 100.0f );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
178
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
179 /* Make sure we're chaning the model view and not the projection */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
180 glMatrixMode( GL_MODELVIEW );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
181
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
182 /* Reset The View */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
183 glLoadIdentity( );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
184
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
185 return( TRUE );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
186 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
187
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
188 /* function to handle key press events */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
189 void handleKeyPress( SDL_keysym *keysym )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
190 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
191 switch ( keysym->sym )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
192 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
193 case SDLK_ESCAPE:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
194 /* ESC key was pressed */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
195 Quit( 0 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
196 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
197 case SDLK_F1:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
198 /* F1 key was pressed
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
199 * this toggles fullscreen mode
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
200 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
201 SDL_WM_ToggleFullScreen( surface );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
202 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
203 case SDLK_LEFT:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
204 rotation -= 30;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
205 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
206
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
207 case SDLK_RIGHT:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
208 rotation += 30;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
209 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
210
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
211 default:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
212 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
213 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
214
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
215 __android_log_print(ANDROID_LOG_INFO, "SDL","Keycode: %d, %d, %d\n", keysym->sym, SDLK_LEFT, SDLK_RIGHT);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
216
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
217 return;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
218 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
219
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
220 /* general OpenGL initialization function */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
221 int initGL( GLvoid )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
222 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
223
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
224 /* Enable smooth shading */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
225 glShadeModel( GL_SMOOTH );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
226
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
227 /* Set the background black */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
228 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
229
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
230 /* Depth buffer setup */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
231 //glClearDepth( 1.0f );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
232
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
233 /* Enables Depth Testing */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
234 glEnable( GL_DEPTH_TEST );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
235
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
236 /* The Type Of Depth Test To Do */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
237 glDepthFunc( GL_LEQUAL );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
238
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
239 /* Really Nice Perspective Calculations */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
240 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
241
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
242 return( TRUE );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
243 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
244
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
245 /* Here goes our drawing code */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
246 int drawGLScene( GLvoid )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
247 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
248
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
249 static int Frames = 0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
250 static int T0 = 0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
251
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
252 glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
253
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
254 glClearColorx(0,0,0,255);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
255 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
256
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
257 glMatrixMode(GL_PROJECTION);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
258 glLoadIdentity();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
259 gluPerspective(45, (float)SCREEN_WIDTH / SCREEN_HEIGHT, 0.5f, 150);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
260
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
261 glMatrixMode(GL_MODELVIEW);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
262
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
263 glLoadIdentity();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
264
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
265 //Camera
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
266 gluLookAt(0,0,5, 0,0,0, 0,1,0);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
267
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
268 //Draw a triangle
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
269 //glRotatef(iRot, 0, 1, 0);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
270
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
271 glRotatef( rotation, 0.0f, 1.0f, 0.0f );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
272
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
273
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
274 glEnableClientState (GL_VERTEX_ARRAY);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
275 glEnableClientState (GL_COLOR_ARRAY);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
276
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
277 /* Rotate The Triangle On The Y axis ( NEW ) */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
278 //glRotatef( Frames % 360, 0.0f, 1.0f, 0.0f );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
279
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
280 /* GLES variant of drawing a triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
281 const GLfloat triVertices[][9] = {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
282 { /* Front Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
283 0.0f, 1.0f, 0.0f, /* Top Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
284 -1.0f, -1.0f, 1.0f, /* Left Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
285 1.0f, -1.0f, 1.0f /* Right Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
286 }, { /* Right Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
287 0.0f, 1.0f, 0.0f, /* Top Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
288 1.0f, -1.0f, 1.0f, /* Left Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
289 1.0f, -1.0f, -1.0f /* Right Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
290 }, { /* Back Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
291 0.0f, 1.0f, 0.0f, /* Top Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
292 1.0f, -1.0f, -1.0f, /* Left Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
293 -1.0f, -1.0f, -1.0f /* Right Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
294 }, { /* Left Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
295 0.0f, 1.0f, 0.0f, /* Top Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
296 -1.0f, -1.0f, -1.0f, /* Left Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
297 -1.0f, -1.0f, 1.0f /* Right Of Triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
298 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
299 };
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
300
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
301 /* unlike GL, GLES does not support RGB. We have to use RGBA instead */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
302 const GLfloat triColors[][12] = {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
303 { /* Front triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
304 1.0f, 0.0f, 0.0f, 1.0f, /* Red */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
305 0.0f, 1.0f, 0.0f, 1.0f, /* Green */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
306 0.0f, 0.0f, 1.0f, 1.0f /* Blue */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
307 }, { /* Right triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
308 1.0f, 0.0f, 0.0f, 1.0f, /* Red */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
309 0.0f, 0.0f, 1.0f, 1.0f, /* Blue */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
310 0.0f, 1.0f, 0.0f, 1.0f /* Green */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
311 }, { /* Back triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
312 1.0f, 0.0f, 0.0f, 1.0f, /* Red */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
313 0.0f, 1.0f, 0.0f, 1.0f, /* Green */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
314 0.0f, 0.0f, 1.0f, 1.0f /* Blue */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
315 }, { /* Left triangle */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
316 1.0f, 0.0f, 0.0f, 1.0f, /* Red */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
317 0.0f, 0.0f, 1.0f, 1.0f, /* Blue */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
318 0.0f, 1.0f, 0.0f, 1.0f /* Green */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
319 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
320 };
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
321
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
322 glEnableClientState(GL_COLOR_ARRAY);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
323
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
324 int tri=0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
325
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
326 /* Loop through all Triangles */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
327 for(tri=0;tri<sizeof(triVertices)/(9*sizeof(GLfloat));tri++)
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
328 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
329 glVertexPointer(3, GL_FLOAT, 0, triVertices[tri]);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
330 glColorPointer(4, GL_FLOAT, 0, triColors[tri]);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
331
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
332 glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
333 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
334
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
335 //__android_log_print(ANDROID_LOG_INFO, "SDL", "render %d", Frames++);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
336
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
337 /* Draw it to the screen */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
338 SDL_GL_SwapBuffers( );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
339
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
340 /* Gather our frames per second */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
341 Frames++;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
342 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
343 GLint t = SDL_GetTicks();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
344 if (t - T0 >= 5000) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
345 GLfloat seconds = (t - T0) / 1000.0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
346 GLfloat fps = Frames / seconds;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
347 __android_log_print(ANDROID_LOG_INFO, "SDL","%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
348 T0 = t;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
349 Frames = 0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
350 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
351 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
352
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
353 rotation++;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
354
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
355 return( TRUE );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
356 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
357
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
358
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
359 struct
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
360 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
361 SDL_AudioSpec spec;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
362 Uint8 *sound; /* Pointer to wave data */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
363 Uint32 soundlen; /* Length of wave data */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
364 int soundpos; /* Current play position */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
365 } wave;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
366
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
367 void SDLCALL
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
368 fillerup(void *unused, Uint8 * stream, int len)
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
369 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
370 __android_log_print(ANDROID_LOG_INFO, "SDL","FILLERUP\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
371
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
372 Uint8 *waveptr;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
373 int waveleft;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
374
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
375 /* Set up the pointers */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
376 waveptr = wave.sound + wave.soundpos;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
377 waveleft = wave.soundlen - wave.soundpos;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
378
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
379 /* Go! */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
380 while (waveleft <= len) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
381 SDL_memcpy(stream, waveptr, waveleft);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
382 stream += waveleft;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
383 len -= waveleft;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
384 waveptr = wave.sound;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
385 waveleft = wave.soundlen;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
386 wave.soundpos = 0;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
387 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
388 SDL_memcpy(stream, waveptr, len);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
389 wave.soundpos += len;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
390 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
391
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
392 void testAudio(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
393
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
394 const char *file = "/sdcard/sample.wav";
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
395
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
396 /* Load the SDL library */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
397 if (SDL_Init(SDL_INIT_AUDIO) < 0) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
398 __android_log_print(ANDROID_LOG_INFO, "SDL","Couldn't initialize SDL Audio: %s\n", SDL_GetError());
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
399 return;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
400 }else{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
401 __android_log_print(ANDROID_LOG_INFO, "SDL","Init audio ok\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
402 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
403
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
404 /* Load the wave file into memory */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
405 if (SDL_LoadWAV(file, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
406 __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't load %s: %s\n", file, SDL_GetError());
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
407 return;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
408 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
409
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
410 wave.spec.callback = fillerup;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
411
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
412 __android_log_print(ANDROID_LOG_INFO, "SDL","Loaded: %d\n", wave.soundlen);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
413
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
414
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
415 /* Initialize fillerup() variables */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
416 if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
417 __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't open audio: %s\n", SDL_GetError());
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
418 SDL_FreeWAV(wave.sound);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
419 return;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
420 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
421
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
422 __android_log_print(ANDROID_LOG_INFO, "SDL","Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
423
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
424 /* Let the audio run */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
425 SDL_PauseAudio(0);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
426
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
427 __android_log_print(ANDROID_LOG_INFO, "SDL","Playing\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
428
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
429 while (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
430 //__android_log_print(ANDROID_LOG_INFO, "SDL","Still playing\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
431 SDL_Delay(100);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
432 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
433
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
434 __android_log_print(ANDROID_LOG_INFO, "SDL","Closing down\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
435
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
436 /* Clean up on signal */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
437 SDL_CloseAudio();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
438 SDL_FreeWAV(wave.sound);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
439 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
440
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
441 int SDL_main( int argc, char **argv )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
442 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
443
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
444 __android_log_print(ANDROID_LOG_INFO, "SDL","entry\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
445
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
446 /* Flags to pass to SDL_SetVideoMode */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
447 int videoFlags;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
448 /* main loop variable */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
449 int done = FALSE;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
450 /* used to collect events */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
451 SDL_Event event;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
452 /* this holds some info about our display */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
453 const SDL_VideoInfo *videoInfo;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
454 /* whether or not the window is active */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
455 int isActive = TRUE;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
456
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
457 /* initialize SDL */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
458 if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
459 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
460 __android_log_print(ANDROID_LOG_INFO, "SDL", "Video initialization failed: %s\n",
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
461 SDL_GetError( ) );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
462 Quit( 1 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
463 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
464
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
465 /* Fetch the video info */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
466 videoInfo = SDL_GetVideoInfo( );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
467
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
468 if ( !videoInfo )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
469 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
470 __android_log_print(ANDROID_LOG_INFO, "SDL", "Video query failed: %s\n",
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
471 SDL_GetError( ) );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
472 Quit( 1 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
473 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
474
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
475 /* the flags to pass to SDL_SetVideoMode */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
476 videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
477 videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
478 videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
479 videoFlags |= SDL_RESIZABLE; /* Enable window resizing */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
480
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
481 /* This checks to see if surfaces can be stored in memory */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
482 if ( videoInfo->hw_available )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
483 videoFlags |= SDL_HWSURFACE;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
484 else
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
485 videoFlags |= SDL_SWSURFACE;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
486
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
487 /* This checks if hardware blits can be done */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
488 if ( videoInfo->blit_hw )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
489 videoFlags |= SDL_HWACCEL;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
490
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
491 /* Sets up OpenGL double buffering */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
492 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
493
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
494 /* get a SDL surface */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
495 surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
496 videoFlags );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
497
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
498 /* Verify there is a surface */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
499 if ( !surface )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
500 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
501 __android_log_print(ANDROID_LOG_INFO, "SDL", "Video mode set failed: %s\n", SDL_GetError( ) );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
502 Quit( 1 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
503 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
504
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
505 __android_log_print(ANDROID_LOG_INFO, "SDL","Made a video mode!\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
506
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
507 /* initialize OpenGL */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
508 initGL( );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
509
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
510 /* resize the initial window */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
511 resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
512
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
513
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
514 //testAudio();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
515
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
516
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
517 /* wait for events */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
518 while ( !done )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
519 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
520 /* handle the events in the queue */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
521
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
522 while ( SDL_PollEvent( &event ) )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
523 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
524 switch( event.type )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
525 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
526 case SDL_ACTIVEEVENT:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
527 /* Something's happend with our focus
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
528 * If we lost focus or we are iconified, we
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
529 * shouldn't draw the screen
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
530 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
531 if ( event.active.gain == 0 )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
532 isActive = FALSE;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
533 else
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
534 isActive = TRUE;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
535 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
536 case SDL_VIDEORESIZE:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
537 /* handle resize event */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
538 surface = SDL_SetVideoMode( event.resize.w,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
539 event.resize.h,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
540 16, videoFlags );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
541 if ( !surface )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
542 {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
543 __android_log_print(ANDROID_LOG_INFO, "SDL","Could not get a surface after resize: %s\n", SDL_GetError( ) );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
544 Quit( 1 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
545 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
546 resizeWindow( event.resize.w, event.resize.h );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
547 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
548 case SDL_KEYDOWN:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
549 /* handle key presses */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
550 handleKeyPress( &event.key.keysym );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
551 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
552 case SDL_QUIT:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
553 /* handle quit requests */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
554 done = TRUE;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
555 __android_log_print(ANDROID_LOG_INFO, "SDL","App is shutting down\n");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
556 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
557 default:
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
558 break;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
559 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
560 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
561
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
562 /* draw the scene */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
563 if ( isActive )
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
564 drawGLScene( );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
565 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
566
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
567 /* clean ourselves up and exit */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
568 Quit( 0 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
569
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
570 /* Should never get here */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
571 return( 0 );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
572 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
573
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
574