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