Mercurial > mplayer.hg
annotate libvo/matrixview.c @ 36242:406e87858d1f
Remove unused depth test code.
author | reimar |
---|---|
date | Wed, 12 Jun 2013 18:54:15 +0000 |
parents | 0cfa55e44ea5 |
children | 33b774ea1ae6 |
rev | line source |
---|---|
30140 | 1 /* |
2 * Copyright (C) 2003 Alex Zolotov <nightradio@knoppix.ru> | |
3 * Mucked with by Tugrul Galatali <tugrul@galatali.com> | |
4 * | |
5 * MatrixView is free software; you can redistribute it and/or modify | |
30182
ab027cdbba31
Change license terms for matrixview to GPLv2 "or later", all known
reimar
parents:
30160
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
ab027cdbba31
Change license terms for matrixview to GPLv2 "or later", all known
reimar
parents:
30160
diff
changeset
|
7 * the Free Software Foundation; either version 2 of the License, or |
ab027cdbba31
Change license terms for matrixview to GPLv2 "or later", all known
reimar
parents:
30160
diff
changeset
|
8 * (at your option) any later version. |
30140 | 9 * |
10 * MatrixView is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License along | |
30160
f91c628dc701
Refer to MatrixView instead of MPlayer in code taken from MatrixView.
diego
parents:
30153
diff
changeset
|
16 * with MatrixView; if not, write to the Free Software Foundation, Inc., |
30140 | 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 */ | |
19 | |
20 /** | |
21 * Ported to an MPlayer video out plugin by Pigeon <pigeon at pigeond.net> | |
22 * August 2006 | |
23 */ | |
24 | |
25 #include <math.h> | |
26 #include <stdio.h> | |
27 #include <stdint.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 #include "gl_common.h" | |
31 #include "matrixview.h" | |
32 #include "matrixview_font.h" | |
33 | |
30153 | 34 static float matrix_contrast = 1.5; |
30140 | 35 static float matrix_brightness = 1.0; |
36 | |
37 static const uint8_t flare[4][4] = { | |
38 { 0, 0, 0, 0}, | |
39 { 0, 180, 0, 0}, | |
40 { 0, 0, 0, 0}, | |
41 { 0, 0, 0, 0} | |
42 }; | |
43 | |
44 #define MAX_TEXT_X 0x4000 | |
45 #define MAX_TEXT_Y 0x4000 | |
46 static int text_x = 0; | |
47 static int text_y = 0; | |
34060
fab4513840cb
Add () around macro definitions where necessary to avoid bad surprises.
reimar
parents:
34054
diff
changeset
|
48 #define _text_x (text_x/2) |
fab4513840cb
Add () around macro definitions where necessary to avoid bad surprises.
reimar
parents:
34054
diff
changeset
|
49 #define _text_y (text_y/2) |
30140 | 50 |
51 // Scene position | |
52 #define Z_Off -128.0f | |
53 #define Z_Depth 8 | |
54 | |
55 static uint8_t *speed; | |
56 static uint8_t *text; | |
57 static uint8_t *text_light; | |
58 static float *text_depth; | |
59 | |
60 static float *bump_pic; | |
61 | |
62 static void draw_char(int num, float light, float x, float y, float z) | |
63 { | |
64 float tx, ty; | |
65 int num2, num3; | |
66 | |
67 num &= 63; | |
68 //light = light / 255; //light=7-light;num+=(light*60); | |
36127 | 69 light *= matrix_brightness; |
30140 | 70 num2 = num / 10; |
71 num3 = num - (num2 * 10); | |
72 ty = (float)num2 / 7; | |
73 tx = (float)num3 / 10; | |
36138 | 74 mpglColor4ub(0, 255, 0, light); // Basic polygon color |
30140 | 75 |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
76 mpglTexCoord2f(tx, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
77 mpglVertex3f(x, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
78 mpglTexCoord2f(tx + 0.1, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
79 mpglVertex3f(x + 1, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
80 mpglTexCoord2f(tx + 0.1, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
81 mpglVertex3f(x + 1, y - 1, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
82 mpglTexCoord2f(tx, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
83 mpglVertex3f(x, y - 1, z); |
30140 | 84 } |
85 | |
86 static void draw_illuminatedchar(int num, float x, float y, float z) | |
87 { | |
88 float tx, ty; | |
89 int num2, num3; | |
90 | |
91 num2 = num / 10; | |
92 num3 = num - (num2 * 10); | |
93 ty = (float)num2 / 7; | |
94 tx = (float)num3 / 10; | |
36127 | 95 mpglColor4ub(255, 255, 255, 128); // Basic polygon color |
30140 | 96 |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
97 mpglTexCoord2f(tx, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
98 mpglVertex3f(x, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
99 mpglTexCoord2f(tx + 0.1, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
100 mpglVertex3f(x + 1, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
101 mpglTexCoord2f(tx + 0.1, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
102 mpglVertex3f(x + 1, y - 1, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
103 mpglTexCoord2f(tx, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
104 mpglVertex3f(x, y - 1, z); |
30140 | 105 } |
106 | |
107 static void draw_flare(float x, float y, float z) //flare | |
108 { | |
36127 | 109 mpglColor4ub(255, 255, 255, 204); // Basic polygon color |
30140 | 110 |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
111 mpglTexCoord2f(0, 0); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
112 mpglVertex3f(x - 1, y + 1, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
113 mpglTexCoord2f(0.75, 0); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
114 mpglVertex3f(x + 2, y + 1, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
115 mpglTexCoord2f(0.75, 0.75); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
116 mpglVertex3f(x + 2, y - 2, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
117 mpglTexCoord2f(0, 0.75); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
118 mpglVertex3f(x - 1, y - 2, z); |
30140 | 119 } |
120 | |
36227 | 121 static void draw_text(const uint8_t *pic) |
30140 | 122 { |
123 int x, y; | |
124 int p = 0; | |
125 int c, c_pic; | |
126 int pic_fade = 255; | |
127 | |
128 for (y = _text_y; y > -_text_y; y--) { | |
129 for (x = -_text_x; x < _text_x; x++) { | |
30153 | 130 c = text_light[p] - (text[p] >> 1); |
30140 | 131 c += pic_fade; |
132 if (c > 255) | |
133 c = 255; | |
134 | |
135 if (pic) { | |
136 // Original code | |
137 //c_pic = pic[p] * matrix_contrast - (255 - pic_fade); | |
138 | |
139 c_pic = (255 - pic[p]) * matrix_contrast - (255 - pic_fade); | |
140 | |
141 if (c_pic < 0) | |
142 c_pic = 0; | |
143 | |
144 c -= c_pic; | |
145 | |
146 if (c < 0) | |
147 c = 0; | |
148 | |
149 bump_pic[p] = (255.0f - c_pic) / (256 / Z_Depth); | |
150 } else { | |
151 bump_pic[p] = Z_Depth; | |
152 } | |
153 | |
154 if (text[p] && c > 10) | |
155 draw_char(text[p] + 1, c, x, y, text_depth[p] + bump_pic[p]); | |
156 | |
157 if (text_depth[p] < 0.1) | |
158 text_depth[p] = 0; | |
159 else | |
160 text_depth[p] /= 1.1; | |
161 | |
162 if (text_light[p] > 128 && text_light[p + text_x] < 10) | |
30153 | 163 draw_illuminatedchar(text[p] + 1, x, y, |
164 text_depth[p] + bump_pic[p]); | |
30140 | 165 |
166 p++; | |
167 } | |
168 } | |
169 } | |
170 | |
171 static void draw_flares(void) | |
172 { | |
173 float x, y; | |
174 int p = 0; | |
175 | |
176 for (y = _text_y; y > -_text_y; y--) { | |
177 for (x = -_text_x; x < _text_x; x++) { | |
178 if (text_light[p] > 128 && text_light[p + text_x] < 10) | |
30153 | 179 draw_flare(x, y, text_depth[p] + bump_pic[p]); |
30140 | 180 p++; |
181 } | |
182 } | |
183 } | |
184 | |
185 static void scroll(double dCurrentTime) | |
186 { | |
187 int a, s, polovina; | |
188 //static double dLastCycle = -1; | |
189 static double dLastMove = -1; | |
190 | |
191 if (dCurrentTime - dLastMove > 1.0 / (text_y / 1.5)) { | |
192 dLastMove = dCurrentTime; | |
193 | |
194 polovina = text_x * text_y / 2; | |
195 s = 0; | |
196 for (a = text_x * text_y + text_x - 1; a >= text_x; a--) { | |
197 if (speed[s]) | |
198 text_light[a] = text_light[a - text_x]; //scroll light table down | |
199 s++; | |
200 if (s >= text_x) | |
201 s = 0; | |
202 } | |
203 memmove(text_light + text_x, text_light, text_x * text_y); | |
204 memset(text_light, 253, text_x); | |
205 | |
206 s = 0; | |
207 for (a = polovina; a < text_x * text_y; a++) { | |
208 if (text_light[a] == 255) | |
209 text_light[s] = text_light[s + text_x] >> 1; //make black bugs in top line | |
210 | |
211 s++; | |
212 | |
213 if (s >= text_x) | |
214 s = 0; | |
215 } | |
216 } | |
217 } | |
218 | |
219 static void make_change(double dCurrentTime) | |
220 { | |
221 int r = rand() % text_x * text_y; | |
222 | |
223 text[r] += 133; //random bugs | |
224 | |
225 r = rand() % (4 * text_x); | |
226 if (r < text_x && text_light[r]) | |
227 text_light[r] = 255; //white bugs | |
228 | |
229 scroll (dCurrentTime); | |
230 } | |
231 | |
232 | |
233 static void make_text(void) | |
234 { | |
235 int a; | |
236 | |
237 for (a = 0; a < text_x * text_y; a++) | |
238 text[a] = rand() >> 8; // avoid the lowest bits of rand() | |
239 | |
240 for (a = 0; a < text_x; a++) | |
241 speed[a] = rand() >= RAND_MAX / 2; | |
242 } | |
243 | |
244 static void ourBuildTextures(void) | |
245 { | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
246 mpglTexImage2D(GL_TEXTURE_2D, 0, 1, 128, 64, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
247 font_texture); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
248 mpglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
249 mpglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
30140 | 250 |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
251 mpglBindTexture(GL_TEXTURE_2D, 1); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
252 mpglTexImage2D(GL_TEXTURE_2D, 0, 1, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
253 flare); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
254 mpglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
255 mpglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
30140 | 256 |
257 // Some pretty standard settings for wrapping and filtering. | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
258 mpglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
259 mpglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
260 mpglBindTexture(GL_TEXTURE_2D, 0); |
30140 | 261 } |
262 | |
263 void matrixview_init(int w, int h) | |
264 { | |
265 make_text(); | |
266 | |
267 ourBuildTextures(); | |
268 | |
269 // Color to clear color buffer to. | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
270 mpglClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
30140 | 271 |
272 // Allow adjusting of texture color via glColor | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
273 mpglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
30140 | 274 |
34054
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
275 mpglEnable(GL_BLEND); |
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
276 mpglEnable(GL_TEXTURE_2D); |
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
277 |
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
278 mpglBlendFunc(GL_SRC_ALPHA, GL_ONE); |
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
279 |
30140 | 280 matrixview_reshape(w, h); |
281 } | |
282 | |
283 | |
284 void matrixview_reshape(int w, int h) | |
285 { | |
34337
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
286 double nearplane = -Z_Off - Z_Depth; |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
287 // perspective projection, also adjusting vertex position |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
288 // by Z_Off and with simplified Z equation since the absolute |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
289 // Z value does not matter, only relative to other pixels |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
290 float matrix[16] = { |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
291 nearplane / _text_x, 0, 0, 0, |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
292 0, nearplane / _text_y, 0, 0, |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
293 0, 0, 1, -1, |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
294 0, 0, 0, -Z_Off |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
295 }; |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
296 mpglViewport(0, 0, w, h); |
30140 | 297 |
34337
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
298 mpglLoadMatrixf(matrix); |
30140 | 299 } |
300 | |
301 | |
36227 | 302 void matrixview_draw(double currentTime, const uint8_t *data) |
30140 | 303 { |
304 // Clear the color and depth buffers. | |
36242 | 305 mpglClear(GL_COLOR_BUFFER_BIT); |
30140 | 306 |
307 // OK, let's start drawing our planer quads. | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
308 mpglBegin(GL_QUADS); |
30140 | 309 draw_text(data); |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
310 mpglEnd(); |
30140 | 311 |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
312 mpglBindTexture(GL_TEXTURE_2D, 1); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
313 mpglBegin(GL_QUADS); |
30140 | 314 draw_flares(); |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
315 mpglEnd(); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
316 mpglBindTexture(GL_TEXTURE_2D, 0); |
30140 | 317 |
318 make_change(currentTime); | |
319 } | |
320 | |
321 void matrixview_contrast_set(float contrast) | |
322 { | |
323 matrix_contrast = contrast; | |
324 } | |
325 | |
326 void matrixview_brightness_set(float brightness) | |
327 { | |
328 matrix_brightness = brightness; | |
329 } | |
330 | |
331 | |
332 void matrixview_matrix_resize(int w, int h) | |
333 { | |
334 int elems; | |
335 free(speed); | |
336 speed = NULL; | |
337 free(text); | |
338 text = NULL; | |
339 free(text_light); | |
340 text_light = NULL; | |
341 free(text_depth); | |
342 text_depth = NULL; | |
343 if (w > MAX_TEXT_X || h > MAX_TEXT_Y) | |
344 return; | |
345 elems = w * (h + 1); | |
346 speed = calloc(w, sizeof(*speed)); | |
347 text = calloc(elems, sizeof(*text)); | |
348 text_light = calloc(elems, sizeof(*text_light)); | |
349 text_depth = calloc(elems, sizeof(*text_depth)); | |
350 bump_pic = calloc(elems, sizeof(*bump_pic)); | |
351 text_x = w; | |
352 text_y = h; | |
353 make_text(); | |
354 } |