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