Mercurial > sdl-ios-xcode
annotate android/testproject/jni/lesson05.c @ 4716:f2c2a33a1a38
Added resize hander stub and initial screen size setter
author | Paul Hunkin <paul@bieh.net> |
---|---|
date | Tue, 27 Jul 2010 10:49:11 +0200 |
parents | 9bb98766eed0 |
children | d59792d2c3ae |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
17 #include <android/log.h> |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
18 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
19 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
20 #ifdef ANDROID |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
21 #include <GLES/gl.h> |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
22 #else |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
23 #include <GL/gl.h> |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
24 #include <GL/glu.h> |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
25 #endif |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
26 #include "SDL.h" |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
27 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
28 /* screen width, height, and bit depth */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
29 #define SCREEN_WIDTH 320 |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
30 #define SCREEN_HEIGHT 430 |
4708
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
31 #define SCREEN_BPP 16 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
32 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
33 /* Define our booleans */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
34 #define TRUE 1 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
35 #define FALSE 0 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
36 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
37 /* This is our SDL surface */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
38 SDL_Surface *surface; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
39 |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
40 int rotation = 0; |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
41 |
4708
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
42 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
43 /************************************** |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
44 gluperspective implementation |
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 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
|
47 glMatrixMode(GL_PROJECTION); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
48 glLoadIdentity(); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
49 double xmin, xmax, ymin, ymax; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
50 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
|
51 ymin = -ymax; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
52 xmin = ymin * aspect; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
53 xmax = ymax * aspect; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
54 glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
55 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
56 |
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 glulookat implementation |
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 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
|
62 GLfloat centerx, GLfloat centery, GLfloat centerz, |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
63 GLfloat upx, GLfloat upy, GLfloat upz) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
64 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
65 GLfloat m[16]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
66 GLfloat x[3], y[3], z[3]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
67 GLfloat mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
68 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
69 /* Make rotation matrix */ |
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 /* Z vector */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
72 z[0] = eyex - centerx; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
73 z[1] = eyey - centery; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
74 z[2] = eyez - centerz; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
75 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
|
76 if (mag) { /* mpichler, 19950515 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
77 z[0] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
78 z[1] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
79 z[2] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
80 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
81 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
82 /* Y vector */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
83 y[0] = upx; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
84 y[1] = upy; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
85 y[2] = upz; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
86 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
87 /* X vector = Y cross Z */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
92 /* Recompute Y = Z cross X */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
97 /* mpichler, 19950515 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
98 /* 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
|
99 * 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
|
100 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
101 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
102 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
|
103 if (mag) { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
104 x[0] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
105 x[1] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
106 x[2] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
107 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
108 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
109 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
|
110 if (mag) { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
111 y[0] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
112 y[1] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
113 y[2] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
114 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
115 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
116 #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
|
117 M(0, 0) = x[0]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
118 M(0, 1) = x[1]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
119 M(0, 2) = x[2]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
120 M(0, 3) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
121 M(1, 0) = y[0]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
122 M(1, 1) = y[1]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
123 M(1, 2) = y[2]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
124 M(1, 3) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
125 M(2, 0) = z[0]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
126 M(2, 1) = z[1]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
127 M(2, 2) = z[2]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
128 M(2, 3) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
129 M(3, 0) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
130 M(3, 1) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
131 M(3, 2) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
132 M(3, 3) = 1.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
133 #undef M |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
134 glMultMatrixf(m); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
135 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
136 /* Translate Eye to Origin */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
137 glTranslatef(-eyex, -eyey, -eyez); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
138 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
139 } |
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 /* 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
|
146 void Quit( int returnCode ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
147 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
148 /* clean up the window */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
149 SDL_Quit( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
150 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
151 /* and exit appropriately */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
152 exit( returnCode ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
153 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
154 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
155 /* 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
|
156 int resizeWindow( int width, int height ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
157 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
158 /* Height / width ration */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
159 GLfloat ratio; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
160 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
161 /* Protect against a divide by zero */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
162 if ( height == 0 ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
163 height = 1; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
164 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
165 ratio = ( GLfloat )width / ( GLfloat )height; |
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 /* Setup our viewport. */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
168 glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
169 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
170 /* 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
|
171 glMatrixMode( GL_PROJECTION ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
172 glLoadIdentity( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
173 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
174 /* Set our perspective */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
175 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
|
176 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
177 /* 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
|
178 glMatrixMode( GL_MODELVIEW ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
179 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
180 /* Reset The View */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
181 glLoadIdentity( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
182 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
183 return( TRUE ); |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
186 /* function to handle key press events */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
187 void handleKeyPress( SDL_keysym *keysym ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
188 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
189 switch ( keysym->sym ) |
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 case SDLK_ESCAPE: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
192 /* ESC key was pressed */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
193 Quit( 0 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
194 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
195 case SDLK_F1: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
196 /* F1 key was pressed |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
197 * this toggles fullscreen mode |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
198 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
199 SDL_WM_ToggleFullScreen( surface ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
200 break; |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
201 case SDLK_LEFT: |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
202 rotation -= 30; |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
203 break; |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
204 |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
205 case SDLK_RIGHT: |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
206 rotation += 30; |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
207 break; |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
208 |
4708
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
209 default: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
210 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
211 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
212 |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
213 __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
|
214 |
4708
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
215 return; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
216 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
217 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
218 /* general OpenGL initialization function */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
219 int initGL( GLvoid ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
220 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
221 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
222 /* Enable smooth shading */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
223 glShadeModel( GL_SMOOTH ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
224 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
225 /* Set the background black */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
226 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
|
227 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
228 /* Depth buffer setup */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
229 //glClearDepth( 1.0f ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
230 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
231 /* Enables Depth Testing */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
232 glEnable( GL_DEPTH_TEST ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
233 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
234 /* The Type Of Depth Test To Do */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
235 glDepthFunc( GL_LEQUAL ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
236 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
237 /* Really Nice Perspective Calculations */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
238 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
239 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
240 return( TRUE ); |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
243 /* Here goes our drawing code */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
244 int drawGLScene( GLvoid ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
245 { |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
246 |
4708
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
247 static int Frames = 0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
248 static int T0 = 0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
249 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
250 glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
251 |
4710
aeac51289991
Last test version with GLSurface
Paul Hunkin <paul@bieh.net>
parents:
4708
diff
changeset
|
252 glClearColorx(0,0,0,255); |
4708
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
253 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
|
254 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
255 glMatrixMode(GL_PROJECTION); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
256 glLoadIdentity(); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
257 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
|
258 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
259 glMatrixMode(GL_MODELVIEW); |
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 glLoadIdentity(); |
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 //Camera |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
264 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
|
265 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
266 //Draw a triangle |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
267 //glRotatef(iRot, 0, 1, 0); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
268 |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
269 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
|
270 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
271 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
272 glEnableClientState (GL_VERTEX_ARRAY); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
273 glEnableClientState (GL_COLOR_ARRAY); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
274 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
275 /* Rotate The Triangle On The Y axis ( NEW ) */ |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4710
diff
changeset
|
276 //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
|
277 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
278 /* GLES variant of drawing a triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
279 const GLfloat triVertices[][9] = { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
280 { /* Front Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
281 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
|
282 -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
|
283 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
|
284 }, { /* Right Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 }, { /* Back Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
289 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
|
290 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
|
291 -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
|
292 }, { /* Left Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
293 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
|
294 -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
|
295 -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
|
296 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
297 }; |
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 /* 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
|
300 const GLfloat triColors[][12] = { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
301 { /* Front triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 }, { /* Right triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 }, { /* Back triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
310 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
|
311 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
|
312 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
|
313 }, { /* Left triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
314 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
|
315 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
|
316 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
|
317 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
318 }; |
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 glEnableClientState(GL_COLOR_ARRAY); |
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 int tri=0; |
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 /* Loop through all Triangles */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
325 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
|
326 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
327 glVertexPointer(3, GL_FLOAT, 0, triVertices[tri]); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
328 glColorPointer(4, GL_FLOAT, 0, triColors[tri]); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
329 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
330 glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
333 //__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
|
334 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
335 /* Draw it to the screen */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
336 SDL_GL_SwapBuffers( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
337 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
338 /* Gather our frames per second */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
339 Frames++; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
340 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
341 GLint t = SDL_GetTicks(); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
342 if (t - T0 >= 5000) { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
343 GLfloat seconds = (t - T0) / 1000.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
344 GLfloat fps = Frames / seconds; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
345 __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
|
346 T0 = t; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
347 Frames = 0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
348 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
349 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
350 |
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
|
351 rotation++; |
4710
aeac51289991
Last test version with GLSurface
Paul Hunkin <paul@bieh.net>
parents:
4708
diff
changeset
|
352 |
4708
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
353 return( TRUE ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
354 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
355 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
356 int SDL_main( int argc, char **argv ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
357 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
358 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
359 __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
|
360 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
361 /* Flags to pass to SDL_SetVideoMode */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
362 int videoFlags; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
363 /* main loop variable */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
364 int done = FALSE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
365 /* used to collect events */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
366 SDL_Event event; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
367 /* this holds some info about our display */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
368 const SDL_VideoInfo *videoInfo; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
369 /* whether or not the window is active */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
370 int isActive = TRUE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
371 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
372 /* initialize SDL */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
373 if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
374 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
375 __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
|
376 SDL_GetError( ) ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
377 Quit( 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
378 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
379 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
380 /* Fetch the video info */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
381 videoInfo = SDL_GetVideoInfo( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
382 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
383 if ( !videoInfo ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
384 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
385 __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
|
386 SDL_GetError( ) ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
387 Quit( 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
388 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
389 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
390 /* the flags to pass to SDL_SetVideoMode */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
391 videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
392 videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
393 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
|
394 videoFlags |= SDL_RESIZABLE; /* Enable window resizing */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
395 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
396 /* 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
|
397 if ( videoInfo->hw_available ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
398 videoFlags |= SDL_HWSURFACE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
399 else |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
400 videoFlags |= SDL_SWSURFACE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
401 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
402 /* 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
|
403 if ( videoInfo->blit_hw ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
404 videoFlags |= SDL_HWACCEL; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
405 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
406 /* Sets up OpenGL double buffering */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
407 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
408 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
409 /* get a SDL surface */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
410 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
|
411 videoFlags ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
412 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
413 /* Verify there is a surface */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
414 if ( !surface ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
415 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
416 __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
|
417 Quit( 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
418 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
419 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
420 __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
|
421 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
422 /* initialize OpenGL */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
423 initGL( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
424 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
425 /* resize the initial window */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
426 resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
427 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
428 /* wait for events */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
429 while ( !done ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
430 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
431 /* handle the events in the queue */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
432 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
433 while ( SDL_PollEvent( &event ) ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
434 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
435 switch( event.type ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
436 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
437 case SDL_ACTIVEEVENT: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
438 /* Something's happend with our focus |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
439 * 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
|
440 * shouldn't draw the screen |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
441 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
442 if ( event.active.gain == 0 ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
443 isActive = FALSE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
444 else |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
445 isActive = TRUE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
446 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
447 case SDL_VIDEORESIZE: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
448 /* handle resize event */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
449 surface = SDL_SetVideoMode( event.resize.w, |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
450 event.resize.h, |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
451 16, videoFlags ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
452 if ( !surface ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
453 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
454 __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
|
455 Quit( 1 ); |
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 resizeWindow( event.resize.w, event.resize.h ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
458 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
459 case SDL_KEYDOWN: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
460 /* handle key presses */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
461 handleKeyPress( &event.key.keysym ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
462 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
463 case SDL_QUIT: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
464 /* handle quit requests */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
465 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
|
466 __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
|
467 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
468 default: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
469 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
470 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
471 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
472 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
473 /* draw the scene */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
474 if ( isActive ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
475 drawGLScene( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
476 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
477 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
478 /* clean ourselves up and exit */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
479 Quit( 0 ); |
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 /* Should never get here */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
482 return( 0 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
483 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
484 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
485 |