Mercurial > sdl-ios-xcode
annotate android/testproject/jni/lesson05.c @ 4708:f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
author | Paul Hunkin <paul@bieh.net> |
---|---|
date | Fri, 18 Jun 2010 01:28:39 +1200 |
parents | |
children | aeac51289991 |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
30 #define SCREEN_HEIGHT 480 |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
40 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
41 /************************************** |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
42 gluperspective implementation |
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 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
|
45 glMatrixMode(GL_PROJECTION); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
46 glLoadIdentity(); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
47 double xmin, xmax, ymin, ymax; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
48 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
|
49 ymin = -ymax; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
50 xmin = ymin * aspect; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
51 xmax = ymax * aspect; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
52 glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
53 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
54 |
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 glulookat implementation |
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 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
|
60 GLfloat centerx, GLfloat centery, GLfloat centerz, |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
61 GLfloat upx, GLfloat upy, GLfloat upz) |
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 GLfloat m[16]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
64 GLfloat x[3], y[3], z[3]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
65 GLfloat mag; |
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 /* Make rotation matrix */ |
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 /* Z vector */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
70 z[0] = eyex - centerx; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
71 z[1] = eyey - centery; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
72 z[2] = eyez - centerz; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
73 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
|
74 if (mag) { /* mpichler, 19950515 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
75 z[0] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
76 z[1] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
77 z[2] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
78 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
79 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
80 /* Y vector */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
81 y[0] = upx; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
82 y[1] = upy; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
83 y[2] = upz; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
84 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
85 /* X vector = Y cross Z */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
90 /* Recompute Y = Z cross X */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
95 /* mpichler, 19950515 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
96 /* 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
|
97 * 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
|
98 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
99 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
100 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
|
101 if (mag) { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
102 x[0] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
103 x[1] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
104 x[2] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
105 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
106 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
107 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
|
108 if (mag) { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
109 y[0] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
110 y[1] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
111 y[2] /= mag; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
112 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
113 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
114 #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
|
115 M(0, 0) = x[0]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
116 M(0, 1) = x[1]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
117 M(0, 2) = x[2]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
118 M(0, 3) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
119 M(1, 0) = y[0]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
120 M(1, 1) = y[1]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
121 M(1, 2) = y[2]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
122 M(1, 3) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
123 M(2, 0) = z[0]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
124 M(2, 1) = z[1]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
125 M(2, 2) = z[2]; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
126 M(2, 3) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
127 M(3, 0) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
128 M(3, 1) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
129 M(3, 2) = 0.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
130 M(3, 3) = 1.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
131 #undef M |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
132 glMultMatrixf(m); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
133 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
134 /* Translate Eye to Origin */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
135 glTranslatef(-eyex, -eyey, -eyez); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
136 |
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 |
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 /* 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
|
144 void Quit( int returnCode ) |
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 /* clean up the window */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
147 SDL_Quit( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
148 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
149 /* and exit appropriately */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
150 exit( returnCode ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
151 } |
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 /* 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
|
154 int resizeWindow( int width, int height ) |
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 /* Height / width ration */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
157 GLfloat ratio; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
158 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
159 /* Protect against a divide by zero */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
160 if ( height == 0 ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
161 height = 1; |
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 ratio = ( GLfloat )width / ( GLfloat )height; |
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 /* Setup our viewport. */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
166 glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
167 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
168 /* 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
|
169 glMatrixMode( GL_PROJECTION ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
170 glLoadIdentity( ); |
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 /* Set our perspective */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
173 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
|
174 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
175 /* 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
|
176 glMatrixMode( GL_MODELVIEW ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
177 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
178 /* Reset The View */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
179 glLoadIdentity( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
180 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
181 return( TRUE ); |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
184 /* function to handle key press events */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
185 void handleKeyPress( SDL_keysym *keysym ) |
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 switch ( keysym->sym ) |
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 case SDLK_ESCAPE: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
190 /* ESC key was pressed */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
191 Quit( 0 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
192 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
193 case SDLK_F1: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
194 /* F1 key was pressed |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
195 * this toggles fullscreen mode |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
196 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
197 SDL_WM_ToggleFullScreen( surface ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
198 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
199 default: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
200 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
201 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
202 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
203 return; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
204 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
205 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
206 /* general OpenGL initialization function */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
207 int initGL( GLvoid ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
208 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
209 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
210 /* Enable smooth shading */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
211 glShadeModel( GL_SMOOTH ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
212 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
213 /* Set the background black */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
214 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
|
215 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
216 /* Depth buffer setup */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
217 //glClearDepth( 1.0f ); |
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 /* Enables Depth Testing */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
220 glEnable( GL_DEPTH_TEST ); |
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 /* The Type Of Depth Test To Do */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
223 glDepthFunc( GL_LEQUAL ); |
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 /* Really Nice Perspective Calculations */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
226 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); |
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 return( TRUE ); |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
231 /* Here goes our drawing code */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
232 int drawGLScene( GLvoid ) |
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 static int Frames = 0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
235 static int T0 = 0; |
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 glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); |
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 glClearColorx(0,0,Frames,255); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
240 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
|
241 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
242 glMatrixMode(GL_PROJECTION); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
243 glLoadIdentity(); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
244 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
|
245 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
246 glMatrixMode(GL_MODELVIEW); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
247 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
248 glLoadIdentity(); |
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 //Camera |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
251 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
|
252 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
253 //Draw a triangle |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
254 //glRotatef(iRot, 0, 1, 0); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
255 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
256 glRotatef( Frames % 360, 0.0f, 1.0f, 0.0f ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
257 |
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 glEnableClientState (GL_VERTEX_ARRAY); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
260 glEnableClientState (GL_COLOR_ARRAY); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
261 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
262 /* Rotate The Triangle On The Y axis ( NEW ) */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
263 glRotatef( Frames % 360, 0.0f, 1.0f, 0.0f ); |
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 /* GLES variant of drawing a triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
266 const GLfloat triVertices[][9] = { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
267 { /* Front Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
268 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
|
269 -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
|
270 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
|
271 }, { /* Right Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 }, { /* Back Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
276 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
|
277 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
|
278 -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
|
279 }, { /* Left Triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
280 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
|
281 -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
|
282 -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
|
283 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
284 }; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
285 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
286 /* 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
|
287 const GLfloat triColors[][12] = { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
288 { /* Front triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 }, { /* Right triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 }, { /* Back triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 }, { /* Left triangle */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
301 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
|
302 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
|
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 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
305 }; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
306 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
307 glEnableClientState(GL_COLOR_ARRAY); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
308 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
309 int tri=0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
310 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
311 /* Loop through all Triangles */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
312 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
|
313 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
314 glVertexPointer(3, GL_FLOAT, 0, triVertices[tri]); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
315 glColorPointer(4, GL_FLOAT, 0, triColors[tri]); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
316 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
317 glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); |
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 //__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
|
321 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
322 /* Draw it to the screen */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
323 SDL_GL_SwapBuffers( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
324 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
325 /* Gather our frames per second */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
326 Frames++; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
327 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
328 GLint t = SDL_GetTicks(); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
329 if (t - T0 >= 5000) { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
330 GLfloat seconds = (t - T0) / 1000.0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
331 GLfloat fps = Frames / seconds; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
332 __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
|
333 T0 = t; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
334 Frames = 0; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
335 } |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
338 return( TRUE ); |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
341 int SDL_main( int argc, char **argv ) |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
344 __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
|
345 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
346 /* Flags to pass to SDL_SetVideoMode */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
347 int videoFlags; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
348 /* main loop variable */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
349 int done = FALSE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
350 /* used to collect events */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
351 SDL_Event event; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
352 /* this holds some info about our display */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
353 const SDL_VideoInfo *videoInfo; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
354 /* whether or not the window is active */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
355 int isActive = 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 /* initialize SDL */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
358 if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
359 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
360 __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
|
361 SDL_GetError( ) ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
362 Quit( 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
363 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
364 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
365 /* Fetch the video info */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
366 videoInfo = SDL_GetVideoInfo( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
367 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
368 if ( !videoInfo ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
369 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
370 __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
|
371 SDL_GetError( ) ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
372 Quit( 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
373 } |
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 /* the flags to pass to SDL_SetVideoMode */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
376 videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
377 videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
378 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
|
379 videoFlags |= SDL_RESIZABLE; /* Enable window resizing */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
380 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
381 /* 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
|
382 if ( videoInfo->hw_available ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
383 videoFlags |= SDL_HWSURFACE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
384 else |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
385 videoFlags |= SDL_SWSURFACE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
386 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
387 /* 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
|
388 if ( videoInfo->blit_hw ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
389 videoFlags |= SDL_HWACCEL; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
390 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
391 /* Sets up OpenGL double buffering */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
392 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
393 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
394 /* get a SDL surface */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
395 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
|
396 videoFlags ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
397 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
398 /* Verify there is a surface */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
399 if ( !surface ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
400 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
401 __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
|
402 Quit( 1 ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
403 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
404 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
405 __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
|
406 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
407 /* initialize OpenGL */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
408 initGL( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
409 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
410 /* resize the initial window */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
411 resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); |
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 /* wait for events */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
414 while ( !done ) |
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 /* handle the events in the queue */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
417 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
418 while ( SDL_PollEvent( &event ) ) |
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 switch( event.type ) |
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 case SDL_ACTIVEEVENT: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
423 /* Something's happend with our focus |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
424 * 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
|
425 * shouldn't draw the screen |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
426 */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
427 if ( event.active.gain == 0 ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
428 isActive = FALSE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
429 else |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
430 isActive = TRUE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
431 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
432 case SDL_VIDEORESIZE: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
433 /* handle resize event */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
434 surface = SDL_SetVideoMode( event.resize.w, |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
435 event.resize.h, |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
436 16, videoFlags ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
437 if ( !surface ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
438 { |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
439 __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
|
440 Quit( 1 ); |
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 resizeWindow( event.resize.w, event.resize.h ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
443 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
444 case SDL_KEYDOWN: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
445 /* handle key presses */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
446 handleKeyPress( &event.key.keysym ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
447 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
448 case SDL_QUIT: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
449 /* handle quit requests */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
450 done = TRUE; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
451 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
452 default: |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
453 break; |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
454 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
455 } |
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 /* draw the scene */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
458 if ( isActive ) |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
459 drawGLScene( ); |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
460 } |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
461 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
462 /* clean ourselves up and exit */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
463 Quit( 0 ); |
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 /* Should never get here */ |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
466 return( 0 ); |
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 |
f3f65cb6a382
Added egl headers so we can use eglMakeCurrent()
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
469 |