Mercurial > mplayer.hg
annotate libvo/matrixview.c @ 36247:b9aec2e77319
Remove array that always contains only 0.
author | reimar |
---|---|
date | Wed, 12 Jun 2013 18:54:22 +0000 |
parents | b474a1e925c0 |
children | 15de38d9f726 |
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 #define MAX_TEXT_X 0x4000 | |
38 #define MAX_TEXT_Y 0x4000 | |
39 static int text_x = 0; | |
40 static int text_y = 0; | |
34060
fab4513840cb
Add () around macro definitions where necessary to avoid bad surprises.
reimar
parents:
34054
diff
changeset
|
41 #define _text_x (text_x/2) |
fab4513840cb
Add () around macro definitions where necessary to avoid bad surprises.
reimar
parents:
34054
diff
changeset
|
42 #define _text_y (text_y/2) |
30140 | 43 |
44 // Scene position | |
45 #define Z_Off -128.0f | |
46 #define Z_Depth 8 | |
47 | |
48 static uint8_t *speed; | |
49 static uint8_t *text; | |
50 static uint8_t *text_light; | |
51 | |
52 static float *bump_pic; | |
53 | |
54 static void draw_char(int num, float light, float x, float y, float z) | |
55 { | |
56 float tx, ty; | |
57 int num2, num3; | |
58 | |
36244 | 59 num %= 55; |
30140 | 60 //light = light / 255; //light=7-light;num+=(light*60); |
36127 | 61 light *= matrix_brightness; |
30140 | 62 num2 = num / 10; |
63 num3 = num - (num2 * 10); | |
36244 | 64 ty = (float)num2 / 6; |
30140 | 65 tx = (float)num3 / 10; |
36243 | 66 mpglColor4ub(0, light, 0, 255); // Basic polygon color |
30140 | 67 |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
68 mpglTexCoord2f(tx, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
69 mpglVertex3f(x, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
70 mpglTexCoord2f(tx + 0.1, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
71 mpglVertex3f(x + 1, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
72 mpglTexCoord2f(tx + 0.1, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
73 mpglVertex3f(x + 1, y - 1, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
74 mpglTexCoord2f(tx, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
75 mpglVertex3f(x, y - 1, z); |
30140 | 76 } |
77 | |
78 static void draw_illuminatedchar(int num, float x, float y, float z) | |
79 { | |
80 float tx, ty; | |
81 int num2, num3; | |
82 | |
36244 | 83 num %= 55; |
30140 | 84 num2 = num / 10; |
85 num3 = num - (num2 * 10); | |
36244 | 86 ty = (float)num2 / 6; |
30140 | 87 tx = (float)num3 / 10; |
36243 | 88 mpglColor4ub(128, 128, 128, 255); // Basic polygon color |
30140 | 89 |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
90 mpglTexCoord2f(tx, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
91 mpglVertex3f(x, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
92 mpglTexCoord2f(tx + 0.1, ty); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
93 mpglVertex3f(x + 1, y, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
94 mpglTexCoord2f(tx + 0.1, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
95 mpglVertex3f(x + 1, y - 1, z); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
96 mpglTexCoord2f(tx, ty + 0.166); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
97 mpglVertex3f(x, y - 1, z); |
30140 | 98 } |
99 | |
100 static void draw_flare(float x, float y, float z) //flare | |
101 { | |
36243 | 102 mpglColor4ub(204, 204, 204, 255); // Basic polygon color |
30140 | 103 |
36245 | 104 mpglTexCoord2f(1.0 - 4.0/128, 1.0 - 4.0/64); |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
105 mpglVertex3f(x - 1, y + 1, z); |
36245 | 106 mpglTexCoord2f(1.0 - 1.0/128, 1.0 - 4.0/64); |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
107 mpglVertex3f(x + 2, y + 1, z); |
36245 | 108 mpglTexCoord2f(1.0 - 1.0/128, 1.0 - 1.0/64); |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
109 mpglVertex3f(x + 2, y - 2, z); |
36245 | 110 mpglTexCoord2f(1.0 - 4.0/128, 1.0 - 1.0/64); |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
111 mpglVertex3f(x - 1, y - 2, z); |
30140 | 112 } |
113 | |
36227 | 114 static void draw_text(const uint8_t *pic) |
30140 | 115 { |
116 int x, y; | |
117 int p = 0; | |
118 int c, c_pic; | |
119 int pic_fade = 255; | |
120 | |
121 for (y = _text_y; y > -_text_y; y--) { | |
122 for (x = -_text_x; x < _text_x; x++) { | |
30153 | 123 c = text_light[p] - (text[p] >> 1); |
30140 | 124 c += pic_fade; |
125 if (c > 255) | |
126 c = 255; | |
127 | |
128 if (pic) { | |
129 // Original code | |
130 //c_pic = pic[p] * matrix_contrast - (255 - pic_fade); | |
131 | |
132 c_pic = (255 - pic[p]) * matrix_contrast - (255 - pic_fade); | |
133 | |
134 if (c_pic < 0) | |
135 c_pic = 0; | |
136 | |
137 c -= c_pic; | |
138 | |
139 if (c < 0) | |
140 c = 0; | |
141 | |
142 bump_pic[p] = (255.0f - c_pic) / (256 / Z_Depth); | |
143 } else { | |
144 bump_pic[p] = Z_Depth; | |
145 } | |
146 | |
36246
b474a1e925c0
Remove a special-case that doesn't really make much
reimar
parents:
36245
diff
changeset
|
147 if (c > 10) |
36247 | 148 draw_char(text[p], c, x, y, bump_pic[p]); |
30140 | 149 |
150 if (text_light[p] > 128 && text_light[p + text_x] < 10) | |
36246
b474a1e925c0
Remove a special-case that doesn't really make much
reimar
parents:
36245
diff
changeset
|
151 draw_illuminatedchar(text[p], x, y, |
36247 | 152 bump_pic[p]); |
30140 | 153 |
154 p++; | |
155 } | |
156 } | |
157 } | |
158 | |
159 static void draw_flares(void) | |
160 { | |
161 float x, y; | |
162 int p = 0; | |
163 | |
164 for (y = _text_y; y > -_text_y; y--) { | |
165 for (x = -_text_x; x < _text_x; x++) { | |
166 if (text_light[p] > 128 && text_light[p + text_x] < 10) | |
36247 | 167 draw_flare(x, y, bump_pic[p]); |
30140 | 168 p++; |
169 } | |
170 } | |
171 } | |
172 | |
173 static void scroll(double dCurrentTime) | |
174 { | |
175 int a, s, polovina; | |
176 //static double dLastCycle = -1; | |
177 static double dLastMove = -1; | |
178 | |
179 if (dCurrentTime - dLastMove > 1.0 / (text_y / 1.5)) { | |
180 dLastMove = dCurrentTime; | |
181 | |
182 polovina = text_x * text_y / 2; | |
183 s = 0; | |
184 for (a = text_x * text_y + text_x - 1; a >= text_x; a--) { | |
185 if (speed[s]) | |
186 text_light[a] = text_light[a - text_x]; //scroll light table down | |
187 s++; | |
188 if (s >= text_x) | |
189 s = 0; | |
190 } | |
191 memmove(text_light + text_x, text_light, text_x * text_y); | |
192 memset(text_light, 253, text_x); | |
193 | |
194 s = 0; | |
195 for (a = polovina; a < text_x * text_y; a++) { | |
196 if (text_light[a] == 255) | |
197 text_light[s] = text_light[s + text_x] >> 1; //make black bugs in top line | |
198 | |
199 s++; | |
200 | |
201 if (s >= text_x) | |
202 s = 0; | |
203 } | |
204 } | |
205 } | |
206 | |
207 static void make_change(double dCurrentTime) | |
208 { | |
209 int r = rand() % text_x * text_y; | |
210 | |
211 text[r] += 133; //random bugs | |
212 | |
213 r = rand() % (4 * text_x); | |
214 if (r < text_x && text_light[r]) | |
215 text_light[r] = 255; //white bugs | |
216 | |
217 scroll (dCurrentTime); | |
218 } | |
219 | |
220 | |
221 static void make_text(void) | |
222 { | |
223 int a; | |
224 | |
225 for (a = 0; a < text_x * text_y; a++) | |
226 text[a] = rand() >> 8; // avoid the lowest bits of rand() | |
227 | |
228 for (a = 0; a < text_x; a++) | |
229 speed[a] = rand() >= RAND_MAX / 2; | |
230 } | |
231 | |
232 static void ourBuildTextures(void) | |
233 { | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
234 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
|
235 font_texture); |
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
236 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
|
237 mpglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
30140 | 238 } |
239 | |
240 void matrixview_init(int w, int h) | |
241 { | |
242 make_text(); | |
243 | |
244 ourBuildTextures(); | |
245 | |
246 // Color to clear color buffer to. | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
247 mpglClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
30140 | 248 |
249 // Allow adjusting of texture color via glColor | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
250 mpglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
30140 | 251 |
34054
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
252 mpglEnable(GL_BLEND); |
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
253 mpglEnable(GL_TEXTURE_2D); |
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
254 |
36243 | 255 mpglBlendFunc(GL_ONE, GL_ONE); |
34054
a70e8abec089
Change silly matrixview code to not needlessly change state on every frame
reimar
parents:
30945
diff
changeset
|
256 |
30140 | 257 matrixview_reshape(w, h); |
258 } | |
259 | |
260 | |
261 void matrixview_reshape(int w, int h) | |
262 { | |
34337
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
263 double nearplane = -Z_Off - Z_Depth; |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
264 // perspective projection, also adjusting vertex position |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
265 // 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
|
266 // 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
|
267 float matrix[16] = { |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
268 nearplane / _text_x, 0, 0, 0, |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
269 0, nearplane / _text_y, 0, 0, |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
270 0, 0, 1, -1, |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
271 0, 0, 0, -Z_Off |
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
272 }; |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
273 mpglViewport(0, 0, w, h); |
30140 | 274 |
34337
f8c523d09e5e
Use glLoadMatrixf. This makes it easier to support OpenGL ES.
reimar
parents:
34060
diff
changeset
|
275 mpglLoadMatrixf(matrix); |
30140 | 276 } |
277 | |
278 | |
36227 | 279 void matrixview_draw(double currentTime, const uint8_t *data) |
30140 | 280 { |
281 // Clear the color and depth buffers. | |
36242 | 282 mpglClear(GL_COLOR_BUFFER_BIT); |
30140 | 283 |
284 // OK, let's start drawing our planer quads. | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
285 mpglBegin(GL_QUADS); |
30140 | 286 draw_text(data); |
287 draw_flares(); | |
30945
55917a674d7d
Add mpgl prefix to all OpenGL-related function pointers.
reimar
parents:
30182
diff
changeset
|
288 mpglEnd(); |
30140 | 289 |
290 make_change(currentTime); | |
291 } | |
292 | |
293 void matrixview_contrast_set(float contrast) | |
294 { | |
295 matrix_contrast = contrast; | |
296 } | |
297 | |
298 void matrixview_brightness_set(float brightness) | |
299 { | |
300 matrix_brightness = brightness; | |
301 } | |
302 | |
303 | |
304 void matrixview_matrix_resize(int w, int h) | |
305 { | |
306 int elems; | |
307 free(speed); | |
308 speed = NULL; | |
309 free(text); | |
310 text = NULL; | |
311 free(text_light); | |
312 text_light = NULL; | |
313 if (w > MAX_TEXT_X || h > MAX_TEXT_Y) | |
314 return; | |
315 elems = w * (h + 1); | |
316 speed = calloc(w, sizeof(*speed)); | |
317 text = calloc(elems, sizeof(*text)); | |
318 text_light = calloc(elems, sizeof(*text_light)); | |
319 bump_pic = calloc(elems, sizeof(*bump_pic)); | |
320 text_x = w; | |
321 text_y = h; | |
322 make_text(); | |
323 } |