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