/[VRac]/Screen.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Screen.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 73 by dpavlin, Tue Jul 31 21:43:57 2007 UTC revision 76 by dpavlin, Wed Aug 1 12:57:15 2007 UTC
# Line 8  use warnings; Line 8  use warnings;
8  use SDL::App;  use SDL::App;
9  use SDL::Rect;  use SDL::Rect;
10  use SDL::Color;  use SDL::Color;
11    use SDL::Constants;
12    
13  use Carp qw/confess/;  use Carp qw/confess/;
14    use Data::Dump qw/dump/;
15    
16  use base qw(Class::Accessor Prefs);  use base qw(Class::Accessor Prefs);
17  __PACKAGE__->mk_accessors(qw(app));  __PACKAGE__->mk_accessors(qw(app));
# Line 41  sub open_screen { Line 43  sub open_screen {
43                  -height => 256 * $self->scale,                  -height => 256 * $self->scale,
44                  -depth  => 16,                  -depth  => 16,
45          );          );
46          #$app->grab_input( 0 );          #$app->grab_input( SDL_GRAB_QUERY );
47            $app->grab_input( SDL_GRAB_OFF );
48    
49          warn "# created SDL::App\n";          warn "# created SDL::App\n";
50          $self->app( $app );          $self->app( $app );
# Line 54  my $red                = SDL::Color->new( -r => 0xff, Line 57  my $red                = SDL::Color->new( -r => 0xff,
57  my $green       = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 );  my $green       = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 );
58  my $blue        = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff );  my $blue        = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff );
59    
60    my $rect_screen = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 );
61    my $rect_mem = SDL::Rect->new( -x => 256, -y => 0, -width => 256, -height => 256 );
62    
63  =head2 p  =head2 p
64    
65   $screen->p( $x, $y, 1 );   $screen->p( $x, $y, 1 );
# Line 168  sub sync { Line 174  sub sync {
174    
175  =head2 render  =head2 render
176    
177    Render one frame of video ram
178    
179    $self->render( @video_memory );    $self->render( @video_memory );
180    
181  =cut  =cut
# Line 177  sub render { Line 185  sub render {
185    
186          die "this function isn't supported if scale isn't 1" unless $self->scale == 1;          die "this function isn't supported if scale isn't 1" unless $self->scale == 1;
187    
188          $app->lock;          my $pixels = pack("C*", @_);
189    
190          my ( $x, $y ) = ( 0,0 );          my $vram = SDL::Surface->new(
191                    -width => 256,
192                    -height => 256,
193                    -depth => 1,    # 1 bit per pixel
194                    -pitch => 32,   # bytes per line
195                    -from => $pixels,
196            );
197            $vram->set_colors( 0, $black, $white, $red );
198            $vram->display_format;
199    
200          foreach my $b ( @_ ) {          my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 );
201                  foreach my $p ( split(//, unpack("B8",pack("C",$b)) ) ) {          $vram->blit( $rect, $app, $rect_screen );
                         $app->pixel( $x, $y, $p ? $white : $black );  
                         $x++;  
                 }  
                 if ( $x == 256 ) {  
                         $x = 0;  
                         $y++;  
                 }  
         }  
202    
         $app->unlock;  
203          $app->sync;          $app->sync;
204    }
205    
206    =head2 render_mem
207    
208      $self->render_mem( @ram );
209    
210    =cut
211    
212    sub render_mem {
213            my $self = shift;
214    
215            return unless $self->show_mem;
216    
217            my $pixels = pack("C*", @_);
218    
219          warn "Screen::render over\n";          my $vram = SDL::Surface->new(
220                    -width => 256,
221                    -height => 256,
222                    -depth => 8,    # 1 bit per pixel
223                    -pitch => 256,  # bytes per line
224                    -from => $pixels,
225                    -Rmask => 0xffff00ff,
226                    -Gmask => 0xffff00ff,
227                    -Bmask => 0xffff00ff,
228            );
229    
230            $vram->display_format;
231    
232            my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 );
233            $vram->blit( $rect, $app, $rect_mem );
234    
235            $app->sync;
236  }  }
237    
238  =head1 SEE ALSO  =head1 SEE ALSO

Legend:
Removed from v.73  
changed lines
  Added in v.76

  ViewVC Help
Powered by ViewVC 1.1.26