annotate libvo/matrixview.c @ 30674:553f53cffabf

Reset output color after each line.
author zuxy
date Tue, 23 Feb 2010 06:42:51 +0000
parents ab027cdbba31
children 55917a674d7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
1 /*
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
2 * Copyright (C) 2003 Alex Zolotov <nightradio@knoppix.ru>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
3 * Mucked with by Tugrul Galatali <tugrul@galatali.com>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
4 *
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
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
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
9 *
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
10 * MatrixView is distributed in the hope that it will be useful,
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
13 * GNU General Public License for more details.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
14 *
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
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
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
18 */
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
19
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
20 /**
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
21 * Ported to an MPlayer video out plugin by Pigeon <pigeon at pigeond.net>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
22 * August 2006
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
23 */
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
24
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
25 #include <math.h>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
26 #include <stdio.h>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
27 #include <stdint.h>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
28 #include <stdlib.h>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
29 #include <string.h>
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
30 #include "gl_common.h"
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
31 #include "matrixview.h"
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
32 #include "matrixview_font.h"
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
33
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
34 static float matrix_contrast = 1.5;
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
35 static float matrix_brightness = 1.0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
36
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
37 // Settings for our light. Try playing with these (or add more lights).
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
38 static float Light_Ambient[] = { 0.1f, 0.1f, 0.1f, 1.0f };
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
39 static float Light_Diffuse[] = { 1.2f, 1.2f, 1.2f, 1.0f };
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
40 static float Light_Position[] = { 2.0f, 2.0f, 0.0f, 1.0f };
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
41
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
42 static const uint8_t flare[4][4] = {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
43 { 0, 0, 0, 0},
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
44 { 0, 180, 0, 0},
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
45 { 0, 0, 0, 0},
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
46 { 0, 0, 0, 0}
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
47 };
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
48
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
49 #define MAX_TEXT_X 0x4000
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
50 #define MAX_TEXT_Y 0x4000
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
51 static int text_x = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
52 static int text_y = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
53 #define _text_x text_x/2
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
54 #define _text_y text_y/2
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
55
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
56 // Scene position
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
57 #define Z_Off -128.0f
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
58 #define Z_Depth 8
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
59
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
60 static uint8_t *speed;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
61 static uint8_t *text;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
62 static uint8_t *text_light;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
63 static float *text_depth;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
64
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
65 static float *bump_pic;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
66
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
67 static void draw_char(int num, float light, float x, float y, float z)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
68 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
69 float tx, ty;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
70 int num2, num3;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
71
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
72 num &= 63;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
73 //light = light / 255; //light=7-light;num+=(light*60);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
74 light = light / 255 * matrix_brightness;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
75 num2 = num / 10;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
76 num3 = num - (num2 * 10);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
77 ty = (float)num2 / 7;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
78 tx = (float)num3 / 10;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
79 Normal3f(0.0f, 0.0f, 1.0f); // Needed for lighting
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
80 Color4f(0.0, 1.0, 0.0, light); // Basic polygon color
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
81
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
82 TexCoord2f(tx, ty);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
83 Vertex3f(x, y, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
84 TexCoord2f(tx + 0.1, ty);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
85 Vertex3f(x + 1, y, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
86 TexCoord2f(tx + 0.1, ty + 0.166);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
87 Vertex3f(x + 1, y - 1, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
88 TexCoord2f(tx, ty + 0.166);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
89 Vertex3f(x, y - 1, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
90 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
91
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
92 static void draw_illuminatedchar(int num, float x, float y, float z)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
93 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
94 float tx, ty;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
95 int num2, num3;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
96
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
97 num2 = num / 10;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
98 num3 = num - (num2 * 10);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
99 ty = (float)num2 / 7;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
100 tx = (float)num3 / 10;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
101 Normal3f(0.0f, 0.0f, 1.0f); // Needed for lighting
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
102 Color4f(1.0, 1.0, 1.0, .5); // Basic polygon color
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
103
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
104 TexCoord2f(tx, ty);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
105 Vertex3f(x, y, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
106 TexCoord2f(tx + 0.1, ty);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
107 Vertex3f(x + 1, y, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
108 TexCoord2f(tx + 0.1, ty + 0.166);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
109 Vertex3f(x + 1, y - 1, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
110 TexCoord2f(tx, ty + 0.166);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
111 Vertex3f(x, y - 1, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
112 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
113
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
114 static void draw_flare(float x, float y, float z) //flare
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
115 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
116 Normal3f(0.0f, 0.0f, 1.0f); // Needed for lighting
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
117 Color4f(1.0, 1.0, 1.0, .8); // Basic polygon color
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
118
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
119 TexCoord2f(0, 0);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
120 Vertex3f(x - 1, y + 1, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
121 TexCoord2f(0.75, 0);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
122 Vertex3f(x + 2, y + 1, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
123 TexCoord2f(0.75, 0.75);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
124 Vertex3f(x + 2, y - 2, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
125 TexCoord2f(0, 0.75);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
126 Vertex3f(x - 1, y - 2, z);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
127 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
128
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
129 static void draw_text(uint8_t *pic)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
130 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
131 int x, y;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
132 int p = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
133 int c, c_pic;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
134 int pic_fade = 255;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
135
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
136 for (y = _text_y; y > -_text_y; y--) {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
137 for (x = -_text_x; x < _text_x; x++) {
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
138 c = text_light[p] - (text[p] >> 1);
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
139 c += pic_fade;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
140 if (c > 255)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
141 c = 255;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
142
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
143 if (pic) {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
144 // Original code
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
145 //c_pic = pic[p] * matrix_contrast - (255 - pic_fade);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
146
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
147 c_pic = (255 - pic[p]) * matrix_contrast - (255 - pic_fade);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
148
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
149 if (c_pic < 0)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
150 c_pic = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
151
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
152 c -= c_pic;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
153
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
154 if (c < 0)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
155 c = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
156
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
157 bump_pic[p] = (255.0f - c_pic) / (256 / Z_Depth);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
158 } else {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
159 bump_pic[p] = Z_Depth;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
160 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
161
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
162 if (text[p] && c > 10)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
163 draw_char(text[p] + 1, c, x, y, text_depth[p] + bump_pic[p]);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
164
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
165 if (text_depth[p] < 0.1)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
166 text_depth[p] = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
167 else
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
168 text_depth[p] /= 1.1;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
169
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
170 if (text_light[p] > 128 && text_light[p + text_x] < 10)
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
171 draw_illuminatedchar(text[p] + 1, x, y,
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
172 text_depth[p] + bump_pic[p]);
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
173
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
174 p++;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
175 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
176 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
177 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
178
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
179 static void draw_flares(void)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
180 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
181 float x, y;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
182 int p = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
183
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
184 for (y = _text_y; y > -_text_y; y--) {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
185 for (x = -_text_x; x < _text_x; x++) {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
186 if (text_light[p] > 128 && text_light[p + text_x] < 10)
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
187 draw_flare(x, y, text_depth[p] + bump_pic[p]);
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
188 p++;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
189 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
190 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
191 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
192
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
193 static void scroll(double dCurrentTime)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
194 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
195 int a, s, polovina;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
196 //static double dLastCycle = -1;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
197 static double dLastMove = -1;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
198
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
199 if (dCurrentTime - dLastMove > 1.0 / (text_y / 1.5)) {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
200 dLastMove = dCurrentTime;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
201
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
202 polovina = text_x * text_y / 2;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
203 s = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
204 for (a = text_x * text_y + text_x - 1; a >= text_x; a--) {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
205 if (speed[s])
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
206 text_light[a] = text_light[a - text_x]; //scroll light table down
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
207 s++;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
208 if (s >= text_x)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
209 s = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
210 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
211 memmove(text_light + text_x, text_light, text_x * text_y);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
212 memset(text_light, 253, text_x);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
213
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
214 s = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
215 for (a = polovina; a < text_x * text_y; a++) {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
216 if (text_light[a] == 255)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
217 text_light[s] = text_light[s + text_x] >> 1; //make black bugs in top line
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
218
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
219 s++;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
220
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
221 if (s >= text_x)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
222 s = 0;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
223 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
224 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
225 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
226
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
227 static void make_change(double dCurrentTime)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
228 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
229 int r = rand() % text_x * text_y;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
230
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
231 text[r] += 133; //random bugs
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
232
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
233 r = rand() % (4 * text_x);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
234 if (r < text_x && text_light[r])
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
235 text_light[r] = 255; //white bugs
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
236
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
237 scroll (dCurrentTime);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
238 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
239
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
240
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
241 static void make_text(void)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
242 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
243 int a;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
244
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
245 for (a = 0; a < text_x * text_y; a++)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
246 text[a] = rand() >> 8; // avoid the lowest bits of rand()
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
247
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
248 for (a = 0; a < text_x; a++)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
249 speed[a] = rand() >= RAND_MAX / 2;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
250 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
251
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
252 static void ourBuildTextures(void)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
253 {
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
254 TexImage2D(GL_TEXTURE_2D, 0, 1, 128, 64, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
255 font_texture);
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
256 TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
257 TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
258
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
259 BindTexture(GL_TEXTURE_2D, 1);
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
260 TexImage2D(GL_TEXTURE_2D, 0, 1, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
261 flare);
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
262 TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
263 TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
264
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
265 // Some pretty standard settings for wrapping and filtering.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
266 TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
267 TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
268 BindTexture(GL_TEXTURE_2D, 0);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
269 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
270
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
271 void matrixview_init(int w, int h)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
272 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
273 make_text();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
274
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
275 ourBuildTextures();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
276
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
277 // Color to clear color buffer to.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
278 ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
279
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
280 // Depth to clear depth buffer to; type of test.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
281 ClearDepth(1.0);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
282 DepthFunc(GL_LESS);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
283
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
284 // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
285 ShadeModel(GL_SMOOTH);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
286
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
287 // Set up a light, turn it on.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
288 Lightfv(GL_LIGHT1, GL_POSITION, Light_Position);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
289 Lightfv(GL_LIGHT1, GL_AMBIENT, Light_Ambient);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
290 Lightfv(GL_LIGHT1, GL_DIFFUSE, Light_Diffuse);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
291 Enable(GL_LIGHT1);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
292
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
293 // A handy trick -- have surface material mirror the color.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
294 ColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
295 Enable(GL_COLOR_MATERIAL);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
296
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
297 // Allow adjusting of texture color via glColor
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
298 TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
299
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
300 matrixview_reshape(w, h);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
301 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
302
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
303
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
304 void matrixview_reshape(int w, int h)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
305 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
306 Viewport(0, 0, w, h);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
307
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
308 MatrixMode(GL_PROJECTION);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
309 LoadIdentity();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
310 Frustum(-_text_x, _text_x, -_text_y, _text_y, -Z_Off - Z_Depth, -Z_Off);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
311
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
312 MatrixMode(GL_MODELVIEW);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
313 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
314
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
315
30153
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
316 void matrixview_draw(int w, int h, double currentTime, float frameTime,
4e0755091f55 prettyprinting cosmetics
diego
parents: 30140
diff changeset
317 uint8_t *data)
30140
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
318 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
319 Enable(GL_BLEND);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
320 Enable(GL_TEXTURE_2D);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
321
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
322 Disable(GL_LIGHTING);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
323 BlendFunc(GL_SRC_ALPHA, GL_ONE);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
324 Disable(GL_DEPTH_TEST);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
325
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
326 MatrixMode(GL_MODELVIEW);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
327 LoadIdentity();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
328 Translated(0.0f, 0.0f, Z_Off);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
329
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
330 // Clear the color and depth buffers.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
331 Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
332
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
333 // OK, let's start drawing our planer quads.
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
334 Begin(GL_QUADS);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
335 draw_text(data);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
336 End();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
337
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
338 BindTexture(GL_TEXTURE_2D, 1);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
339 Begin(GL_QUADS);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
340 draw_flares();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
341 End();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
342 BindTexture(GL_TEXTURE_2D, 0);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
343
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
344 make_change(currentTime);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
345
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
346 LoadIdentity();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
347 MatrixMode(GL_PROJECTION);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
348 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
349
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
350 void matrixview_contrast_set(float contrast)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
351 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
352 matrix_contrast = contrast;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
353 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
354
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
355 void matrixview_brightness_set(float brightness)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
356 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
357 matrix_brightness = brightness;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
358 }
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
359
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
360
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
361 void matrixview_matrix_resize(int w, int h)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
362 {
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
363 int elems;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
364 free(speed);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
365 speed = NULL;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
366 free(text);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
367 text = NULL;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
368 free(text_light);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
369 text_light = NULL;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
370 free(text_depth);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
371 text_depth = NULL;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
372 if (w > MAX_TEXT_X || h > MAX_TEXT_Y)
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
373 return;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
374 elems = w * (h + 1);
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
375 speed = calloc(w, sizeof(*speed));
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
376 text = calloc(elems, sizeof(*text));
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
377 text_light = calloc(elems, sizeof(*text_light));
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
378 text_depth = calloc(elems, sizeof(*text_depth));
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
379 bump_pic = calloc(elems, sizeof(*bump_pic));
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
380 text_x = w;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
381 text_y = h;
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
382 make_text();
12a49e9ca30e Finally add matrixview vo.
reimar
parents:
diff changeset
383 }