File: dizzy

package info (click to toggle)
dizzy 0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 284 kB
  • ctags: 118
  • sloc: perl: 1,863; makefile: 12; xml: 12; sh: 6
file content (336 lines) | stat: -rwxr-xr-x 7,450 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;

use lib 'lib';

use OpenGL qw(:all);
use SDL 2.5 qw(:init);
use SDL::Mouse;
use SDL::Video;
use SDL::Surface;
use SDL::Event;
use SDL::Events;

use Math::Trig;
use Time::HiRes qw(sleep time);
use Dizzy::Handlers;
use Dizzy::Core;
use Dizzy::GLFeatures;

my %options = Dizzy::Core::init_arguments();

sub do_resize {
	my ($w, $h) = @_;

	# set default resolutions:
	if (!$w or !$h) {
		if ($options{fullscreen}) {
			# no specific resolution for fullscreen mode
			$w = $h = 0;
		} else {
			# 800x500 for windowed mode
			($w, $h) = (800, 500);
		}
	}

	my $surf = SDL::Video::set_video_mode($w, $h, 0,
		SDL_OPENGL() |
		SDL_HWSURFACE() |
		SDL_RESIZABLE() |
		($options{fullscreen} ? SDL_FULLSCREEN() : 0));

	if (!$surf) {
		print STDERR "fatal: SDL Error: " .  SDL::get_error() . "\n";
		exit(1);
	}

	# find out actual new window size and reset projection
	($w, $h) = ($surf->w, $surf->h);
	glViewport(0, 0, $w, $h);
	Dizzy::Render::init_projection($w / $h);
}

# initialize OpenGL
# (returns 0 on success, therefore "and", not "or")
SDL::init(SDL_INIT_VIDEO()) and die(SDL::get_error());
SDL::Video::wm_set_caption("Dizzy", "");
SDL::Video::GL_set_attribute(SDL_GL_DOUBLEBUFFER(), 1) and die(SDL::get_error());
do_resize($options{width}, $options{height});
if ($options{fullscreen}) {
	SDL::Mouse::show_cursor(0);
}

Dizzy::Handlers::register_last(
	render => sub {
		Dizzy::Core::_fps_tick();
		Dizzy::Handlers::GO_ON;
	},
	'exit' => sub {
		my $ev = SDL::Event->new();
		$ev->type(SDL_QUIT());
		SDL::Events::push_event($ev);
		Dizzy::Handlers::GO_ON;
	},
);

Dizzy::GLFeatures::update_capabilities();

# prepare for progress screen
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

# initialize dizzy subsystems
Dizzy::Core::init_subsystems(%options,
	callback_texture_load => sub {
		my %args = @_;

		# if window is resized while displaying the progress bar, handle that
		my $event = SDL::Event->new();
		while (SDL::Events::poll_event($event)) {
			my $type = $event->type();
			if ($type == SDL_QUIT()) {
				print STDERR "warning: exiting during initialization\n";
				exit(2);
			} elsif ($type == SDL_VIDEORESIZE()) {
				do_resize($event->resize_w(), $event->resize_h());
			}
		}

		glClear(GL_COLOR_BUFFER_BIT);

		# bar background
		glColor3f((0.125) x 3);
		glRectf(-2.0, +0.0625, +2.0, -0.125);

		# bar itself
		glColor3f((1.0) x 3);
		glRectf(-2.0, +0.0625, -2.0 + 4.0 * ($args{current} / $args{total}), -0.125);

		glFlush();
		SDL::Video::GL_swap_buffers();
	},
);

if ($options{debug_time_startup}) {
	print "debug: startup complete, exiting as requested\n";
	exit(0);
}

my $event = SDL::Event->new();
while (1) {
	if (SDL::Events::poll_event($event)) {
		my $type = $event->type();
		if ($type == SDL_QUIT()) {
			exit(0);
		} elsif ($type == SDL_KEYDOWN()) {
			my $keysym = $event->key_sym();
			my $k;
			if ($keysym == SDLK_LEFT()) {
				$k = "LEFT";
			} elsif ($keysym == SDLK_RIGHT()) {
				$k = "RIGHT";
			} elsif ($keysym == SDLK_DOWN()) {
				$k = "DOWN";
			} elsif ($keysym == SDLK_UP()) {
				$k = "UP";
			} elsif ($keysym == SDLK_ESCAPE()) {
				$k = "\e";
			} elsif ($keysym == SDLK_q()) {
				$k = "q";
			} else {
				$k = "OTHER:$keysym";
			}

			Dizzy::Handlers::invoke("keyboard", key => $k);
		} elsif ($type == SDL_VIDEORESIZE()) {
			do_resize($event->resize_w(), $event->resize_h());
		}
	}

	Dizzy::Handlers::invoke("render");
	glFlush();
	SDL::Video::GL_swap_buffers();
}

__END__

=head1 NAME

B<dizzy> - a graphics demo that makes you dizzy using rotating textures

=head1 SYNOPSIS

B<dizzy> [B<-f>|B<-w> I<width> B<-h> I<height>] [B<-t> I<switch_module>] [B<-T> I<options>]

=head1 DESCRIPTION

B<dizzy> is a graphics demo that rotates planes of patterns on a colored
background to make you dizzy. Textures can be cross-faded and there is a mode
that automatically changes textures, allowing Dizzy to be run as a screensaver.

=head1 OPTIONS

=over

=item B<-w> I<width>

=item B<--width> I<width>

=item B<-h> I<height>

=item B<--height> I<height>

Sets the window width and height.

=item B<-f>

=item B<--fullscreen>

Attempts to switch into a true fullscreen mode, if possible. The window size
parameters are ignored.

=item B<-a>

=item B<--automode> I<time>

Automatically switches textures after a specified number of seconds has passed.
I<time> can be fractional and the decimal separator is always the period.

=item B<-t> I<module>

=item B<--texswitcher> I<module>

Selects the texture switching module to use. Default is B<Simple>.

See below for available texture switchers and their descriptions.

=item B<-T> I<option>=I<value>

=item B<--texswitcher-options> I<option>=I<value>

Passes an option I<option> with the value I<value> to the selected texture
switcher. The available options depend on the texture switcher used.

This option can be given multiple times to set multiple options.

=item B<-d> I<module>

=item B<--rotswitcher> I<module>

Selects the rotator switching module to use. Default is B<Simple>.

See below for available texture switchers and their descriptions.

=item B<-D> I<option>=I<value>

=item B<--rotswitcher-options> I<option>=I<value>

Passes an option I<option> with the value I<value> to the selected rotator
switcher. The available options depend on the rotator switcher used.

This option can be given multiple times to set multiple options.

=item B<-r> I<resolution>

=item B<--texture-resolution> I<resolution>

Changes the texture resolution. I<resolution> must be a power of two. The default
value is 256.

=item B<-R> I<resolution>

=item B<--shader-resolution> I<resolution>

Changes the resolution used when rendering using shaders. I<resolution> must be
a power of two. The default is 1024.

=item B<-z> I<zoom>

=item B<--zoom> I<zoom>

Zooms the textures. The default value is 100.

=item B<-c> I<path>

=item B<--cache-paths> I<path>

Use a different path for cached textures. This option can be specified multiple
times.

=item B<-C>

=item B<--disable-cache>

Don't use any texture cache at all.

=item B<--debug-show-planes>

Zooms out of the normal view so you can see how Dizzy creates the animation. A
white border will also be drawn around the area that would have been shown had
this option not been used.

=back

=head1 TEXTURE SWITCHERS

=head2 Simple

A simple texture switcher. It just sets the new texture when it is told to do
so. It takes no options.

=head2 Blend

A texture switcher that crossfades between textures to generate a smooth
transition. It takes one option:

=over

=item B<duration>=I<duration>

Sets the duration of a blend to I<duration> seconds. The value can be fractional
(the decimal separator is always a period).  The default value is 2.

Note that you have to add the time you specify here to the automode time, so if
you want the transition to take two seconds and every image to stay for five
seconds, you set the duration to 2 and automode to 7 (not 5).

=back

=head1 ROTATOR SWITCHERS

=head2 Simple

A simple switcher that just activates the new rotator without any transition.

=head1 KEYBOARD COMMANDS

=over

=item Cursor left

Select previous available texture.

=item Cursor right

Select next available texture.

=item Cursor down

Select previous available rotator function.

=item Cursor up

Select next available rotator function.

=item Escape

=item q

Exit Dizzy.

=back

=cut