5 raw_pixels.pir - paint the screen blue, pixel by pixel
9 To run this file, run the following command from the Parrot directory:
11 $ ./parrot examples/sdl/raw_pixels.pir
16 .include 'datatypes.pasm'
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
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
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
45 white = new ['SDL'; 'Color']
46 white.'init'( 'r' => 255, 'g' => 255, 'b' => 255 )
48 # create a blue color to paint the new pixels
50 blue = new ['SDL'; 'Color']
51 blue.'init'( 'r' => 0, 'g' => 0, 'b' => 255 )
54 main_screen.'fill_rect'( rect, white )
55 main_screen.'update_rect'( rect )
57 # lock the raw framebuffer
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
73 main_screen.'draw_pixel'( x, y, converted_blue )
76 if y < 480 goto loop_y
79 # update the screen on each iteration
80 main_screen.'update_rect'( rect )
81 if x < 640 goto loop_x
85 # no more raw pixel access necessary
86 main_screen.'unlock'()
88 # show off for a bit then exit
97 chromatic, E<lt>chromatic at wgz dot orgE<gt>.
101 Copyright (C) 2004-2008, Parrot Foundation.
109 # vim: expandtab shiftwidth=4 ft=pir: