[PDD] Add docs for the Parrot_PMC_push_* and Parrot_PMC_pop_* functions
[parrot.git] / examples / sdl / raw_pixels.pir
blob56a9b3bc8b56564116fa7b8f448cbf3b3fca63a9
1 # $Id$
3 =head1 TITLE
5 raw_pixels.pir - paint the screen blue, pixel by pixel
7 =head1 SYNOPSIS
9 To run this file, run the following command from the Parrot directory:
11         $ ./parrot examples/sdl/raw_pixels.pir
12         $
14 =cut
16 .include 'datatypes.pasm'
18 .sub _main :main
19         # first load the necessary libraries
20         load_bytecode "SDL/App.pir"
21         load_bytecode "SDL/Rect.pir"
22         load_bytecode "SDL/Color.pir"
25         # create an SDL::App object
26         .local pmc app
27         .local int app_type
29         app = new ['SDL'; 'App']
30         app.'init'( 'height' => 480, 'width' => 640, 'bpp' => 0, 'flags' => 1 )
32         # fetch the SDL::Surface representing the main window
33         .local pmc main_screen
34         main_screen = app.'surface'()
37         # create an SDL::Rect representing the entire main screen
38         .local pmc rect
39         .local int rect_type
40         rect = new ['SDL'; 'Rect']
41         rect.'init'( 'height' => 480, 'width' => 640, 'x' => 0, 'y' => 0 )
43         # create a white color to paint the background; make new pixels show up
44         .local pmc white
45         white = new ['SDL'; 'Color']
46         white.'init'( 'r' => 255, 'g' => 255, 'b' => 255 )
48         # create a blue color to paint the new pixels
49         .local pmc blue
50         blue = new ['SDL'; 'Color']
51         blue.'init'( 'r' => 0, 'g' => 0, 'b' => 255 )
53         # draw the background
54         main_screen.'fill_rect'( rect, white )
55         main_screen.'update_rect'( rect )
57         # lock the raw framebuffer
58         main_screen.'lock'()
60         # if you convert the color ahead of time, it's much faster!
61         .local int converted_blue
62         converted_blue = blue.'color_for_surface'( main_screen )
64         # draw a vertical line of pixels from left to right on each iteration
65         .local int x
66         .local int y
67         x = 0
69 loop_x:
70         y = 0
72 loop_y:
73         main_screen.'draw_pixel'( x, y, converted_blue )
75         inc y
76         if y < 480 goto loop_y
77         inc x
79         # update the screen on each iteration
80         main_screen.'update_rect'( rect )
81         if x < 640 goto loop_x
83 loop_end:
85         # no more raw pixel access necessary
86         main_screen.'unlock'()
88         # show off for a bit then exit
89         sleep 2
90         app.'quit'()
92         end
93 .end
95 =head1 AUTHOR
97 chromatic, E<lt>chromatic at wgz dot orgE<gt>.
99 =head1 COPYRIGHT
101 Copyright (C) 2004-2008, Parrot Foundation.
103 =cut
105 # Local Variables:
106 #   mode: pir
107 #   fill-column: 100
108 # End:
109 # vim: expandtab shiftwidth=4 ft=pir: