Permalink
Browse files

add a simple loading screen

  • Loading branch information...
1 parent 1ea85f2 commit 80a67fb27c1d8edfd6bd2f4c77c5a263a9da9755 @penma committed Feb 21, 2010
Showing with 45 additions and 1 deletion.
  1. +42 −1 dizzy
  2. +3 −0 lib/Dizzy/Core.pm
View
43 dizzy
@@ -70,8 +70,49 @@ Dizzy::Handlers::register_last(
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);
+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 ($event->poll()) {
+ my $type = $event->type();
+ if ($type == SDL_QUIT()) {
+ print STDERR "warning: exiting during initialization\n";
+ SDL::Quit();
+ exit(2);
+ } elsif ($type == SDL_VIDEORESIZE()) {
+ do_resize($event->resize_w(), $event->resize_h());
+ }
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ # bar background
+ glColor3f(0.5, 0.5, 0.5);
+ glBegin(GL_QUADS);
+ glVertex2f(-2.0, +0.125); glVertex2f(+2.0, +0.125);
+ glVertex2f(+2.0, -0.125); glVertex2f(-2.0, -0.125);
+ glEnd();
+
+ # bar itself
+ glColor3f(1.0, 1.0, 1.0);
+ glBegin(GL_QUADS);
+ glVertex2f(-2.0, +0.125); glVertex2f(-2.0 + 4.0 * ($args{current} / $args{total}), +0.125);
+ glVertex2f(-2.0 + 4.0 * ($args{current} / $args{total}), -0.125); glVertex2f(-2.0, -0.125);
+ glEnd();
+
+ glFlush();
+ SDL::GLSwapBuffers();
+ },
+);
if ($options{debug_time_startup}) {
print "debug: startup complete, exiting as requested\n";
View
@@ -168,6 +168,9 @@ sub init_subsystems {
my @textures = Dizzy::Textures::textures();
foreach my $tex (0..$#textures) {
print STDERR sprintf("Loading textures (%d/%d)\r", $tex + 1, scalar(@textures));
+ if ($options{callback_texture_load}) {
+ $options{callback_texture_load}->(current => $tex, total => scalar(@textures));
+ }
Dizzy::TextureManager::add(%{$textures[$tex]});
}

0 comments on commit 80a67fb

Please sign in to comment.