annotate libvo/matrixview.c @ 36242:406e87858d1f

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