2 * Copyright (C) 2003 Alex Zolotov <nightradio@knoppix.ru>
3 * Mucked with by Tugrul Galatali <tugrul@galatali.com>
5 * MatrixView is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with MatrixView; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Ported to an MPlayer video out plugin by Pigeon <pigeon at pigeond.net>
30 #include "gl_common.h"
31 #include "matrixview.h"
32 #include "matrixview_font.h"
34 static float matrix_contrast
= 1.5;
35 static float matrix_brightness
= 1.0;
37 // Settings for our light. Try playing with these (or add more lights).
38 static float Light_Ambient
[] = { 0.1f
, 0.1f
, 0.1f
, 1.0f
};
39 static float Light_Diffuse
[] = { 1.2f
, 1.2f
, 1.2f
, 1.0f
};
40 static float Light_Position
[] = { 2.0f
, 2.0f
, 0.0f
, 1.0f
};
42 static const uint8_t flare
[4][4] = {
49 #define MAX_TEXT_X 0x4000
50 #define MAX_TEXT_Y 0x4000
51 static int text_x
= 0;
52 static int text_y
= 0;
53 #define _text_x text_x/2
54 #define _text_y text_y/2
60 static uint8_t *speed
;
62 static uint8_t *text_light
;
63 static float *text_depth
;
65 static float *bump_pic
;
67 static void draw_char(int num
, float light
, float x
, float y
, float z
)
73 //light = light / 255; //light=7-light;num+=(light*60);
74 light
= light
/ 255 * matrix_brightness
;
76 num3
= num
- (num2
* 10);
78 tx
= (float)num3
/ 10;
79 Normal3f(0.0f
, 0.0f
, 1.0f
); // Needed for lighting
80 Color4f(0.0, 1.0, 0.0, light
); // Basic polygon color
84 TexCoord2f(tx
+ 0.1, ty
);
85 Vertex3f(x
+ 1, y
, z
);
86 TexCoord2f(tx
+ 0.1, ty
+ 0.166);
87 Vertex3f(x
+ 1, y
- 1, z
);
88 TexCoord2f(tx
, ty
+ 0.166);
89 Vertex3f(x
, y
- 1, z
);
92 static void draw_illuminatedchar(int num
, float x
, float y
, float z
)
98 num3
= num
- (num2
* 10);
100 tx
= (float)num3
/ 10;
101 Normal3f(0.0f
, 0.0f
, 1.0f
); // Needed for lighting
102 Color4f(1.0, 1.0, 1.0, .5); // Basic polygon color
106 TexCoord2f(tx
+ 0.1, ty
);
107 Vertex3f(x
+ 1, y
, z
);
108 TexCoord2f(tx
+ 0.1, ty
+ 0.166);
109 Vertex3f(x
+ 1, y
- 1, z
);
110 TexCoord2f(tx
, ty
+ 0.166);
111 Vertex3f(x
, y
- 1, z
);
114 static void draw_flare(float x
, float y
, float z
) //flare
116 Normal3f(0.0f
, 0.0f
, 1.0f
); // Needed for lighting
117 Color4f(1.0, 1.0, 1.0, .8); // Basic polygon color
120 Vertex3f(x
- 1, y
+ 1, z
);
122 Vertex3f(x
+ 2, y
+ 1, z
);
123 TexCoord2f(0.75, 0.75);
124 Vertex3f(x
+ 2, y
- 2, z
);
126 Vertex3f(x
- 1, y
- 2, z
);
129 static void draw_text(uint8_t *pic
)
136 for (y
= _text_y
; y
> -_text_y
; y
--) {
137 for (x
= -_text_x
; x
< _text_x
; x
++) {
138 c
= text_light
[p
] - (text
[p
] >> 1);
145 //c_pic = pic[p] * matrix_contrast - (255 - pic_fade);
147 c_pic
= (255 - pic
[p
]) * matrix_contrast
- (255 - pic_fade
);
157 bump_pic
[p
] = (255.0f
- c_pic
) / (256 / Z_Depth
);
159 bump_pic
[p
] = Z_Depth
;
162 if (text
[p
] && c
> 10)
163 draw_char(text
[p
] + 1, c
, x
, y
, text_depth
[p
] + bump_pic
[p
]);
165 if (text_depth
[p
] < 0.1)
168 text_depth
[p
] /= 1.1;
170 if (text_light
[p
] > 128 && text_light
[p
+ text_x
] < 10)
171 draw_illuminatedchar(text
[p
] + 1, x
, y
,
172 text_depth
[p
] + bump_pic
[p
]);
179 static void draw_flares(void)
184 for (y
= _text_y
; y
> -_text_y
; y
--) {
185 for (x
= -_text_x
; x
< _text_x
; x
++) {
186 if (text_light
[p
] > 128 && text_light
[p
+ text_x
] < 10)
187 draw_flare(x
, y
, text_depth
[p
] + bump_pic
[p
]);
193 static void scroll(double dCurrentTime
)
196 //static double dLastCycle = -1;
197 static double dLastMove
= -1;
199 if (dCurrentTime
- dLastMove
> 1.0 / (text_y
/ 1.5)) {
200 dLastMove
= dCurrentTime
;
202 polovina
= text_x
* text_y
/ 2;
204 for (a
= text_x
* text_y
+ text_x
- 1; a
>= text_x
; a
--) {
206 text_light
[a
] = text_light
[a
- text_x
]; //scroll light table down
211 memmove(text_light
+ text_x
, text_light
, text_x
* text_y
);
212 memset(text_light
, 253, text_x
);
215 for (a
= polovina
; a
< text_x
* text_y
; a
++) {
216 if (text_light
[a
] == 255)
217 text_light
[s
] = text_light
[s
+ text_x
] >> 1; //make black bugs in top line
227 static void make_change(double dCurrentTime
)
229 int r
= rand() % text_x
* text_y
;
231 text
[r
] += 133; //random bugs
233 r
= rand() % (4 * text_x
);
234 if (r
< text_x
&& text_light
[r
])
235 text_light
[r
] = 255; //white bugs
237 scroll (dCurrentTime
);
241 static void make_text(void)
245 for (a
= 0; a
< text_x
* text_y
; a
++)
246 text
[a
] = rand() >> 8; // avoid the lowest bits of rand()
248 for (a
= 0; a
< text_x
; a
++)
249 speed
[a
] = rand() >= RAND_MAX
/ 2;
252 static void ourBuildTextures(void)
254 TexImage2D(GL_TEXTURE_2D
, 0, 1, 128, 64, 0, GL_LUMINANCE
, GL_UNSIGNED_BYTE
,
256 TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
257 TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
259 BindTexture(GL_TEXTURE_2D
, 1);
260 TexImage2D(GL_TEXTURE_2D
, 0, 1, 4, 4, 0, GL_LUMINANCE
, GL_UNSIGNED_BYTE
,
262 TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
263 TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
265 // Some pretty standard settings for wrapping and filtering.
266 TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
267 TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
268 BindTexture(GL_TEXTURE_2D
, 0);
271 void matrixview_init(int w
, int h
)
277 // Color to clear color buffer to.
278 ClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
);
280 // Depth to clear depth buffer to; type of test.
284 // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun.
285 ShadeModel(GL_SMOOTH
);
287 // Set up a light, turn it on.
288 Lightfv(GL_LIGHT1
, GL_POSITION
, Light_Position
);
289 Lightfv(GL_LIGHT1
, GL_AMBIENT
, Light_Ambient
);
290 Lightfv(GL_LIGHT1
, GL_DIFFUSE
, Light_Diffuse
);
293 // A handy trick -- have surface material mirror the color.
294 ColorMaterial(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
);
295 Enable(GL_COLOR_MATERIAL
);
297 // Allow adjusting of texture color via glColor
298 TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
300 matrixview_reshape(w
, h
);
304 void matrixview_reshape(int w
, int h
)
306 Viewport(0, 0, w
, h
);
308 MatrixMode(GL_PROJECTION
);
310 Frustum(-_text_x
, _text_x
, -_text_y
, _text_y
, -Z_Off
- Z_Depth
, -Z_Off
);
312 MatrixMode(GL_MODELVIEW
);
316 void matrixview_draw(int w
, int h
, double currentTime
, float frameTime
,
320 Enable(GL_TEXTURE_2D
);
322 Disable(GL_LIGHTING
);
323 BlendFunc(GL_SRC_ALPHA
, GL_ONE
);
324 Disable(GL_DEPTH_TEST
);
326 MatrixMode(GL_MODELVIEW
);
328 Translated(0.0f
, 0.0f
, Z_Off
);
330 // Clear the color and depth buffers.
331 Clear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
333 // OK, let's start drawing our planer quads.
338 BindTexture(GL_TEXTURE_2D
, 1);
342 BindTexture(GL_TEXTURE_2D
, 0);
344 make_change(currentTime
);
347 MatrixMode(GL_PROJECTION
);
350 void matrixview_contrast_set(float contrast
)
352 matrix_contrast
= contrast
;
355 void matrixview_brightness_set(float brightness
)
357 matrix_brightness
= brightness
;
361 void matrixview_matrix_resize(int w
, int h
)
372 if (w
> MAX_TEXT_X
|| h
> MAX_TEXT_Y
)
375 speed
= calloc(w
, sizeof(*speed
));
376 text
= calloc(elems
, sizeof(*text
));
377 text_light
= calloc(elems
, sizeof(*text_light
));
378 text_depth
= calloc(elems
, sizeof(*text_depth
));
379 bump_pic
= calloc(elems
, sizeof(*bump_pic
));