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