Skip to content
Browse files

changes to README and BoxShower.js

  • Loading branch information...
1 parent 56ecb36 commit 84e13b1f8453df5f1d73e5e053cdb6c606084e17 @OhMeadhbh OhMeadhbh committed Sep 14, 2011
Showing with 53 additions and 18 deletions.
  1. +52 −17
  2. +1 −1 examples/BoxShower.js
@@ -6,7 +6,14 @@ Installation of the node-sdl package is straight-forward: first clone the
package using git, then build the C++ portion of the package with the
node-waf command.
-First, check out the source from github:
+This package depends on the SDL libraries being present on the target system.
+The following command was required to install these libraries on a "stock"
+Ubuntu 11.04 install:
+<pre> sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev</pre>
+Now that your library dependencies are satisfied, check out the source from
<pre> git clone</pre>
@@ -21,12 +28,6 @@ example programs:
<pre> cd examples
node img.js</pre>
-This package depends on the SDL libraries being present on the target system.
-The following command was required to install these libraries on a "stock"
-Ubuntu 11.04 install:
-<pre> sudo apt-get install libsdl1.2-dev libghc6-sdl-ttf-dev libghc6-sdl-image-dev</pre>
## Usage
### Initialization and Shutdown
@@ -75,26 +76,60 @@ create a "surface".
<pre> var screen = SDL.setVideoMode( 640, 480, 32, SDL.SURFACE.SWSURFACE );</pre>
+The setVideoMode() function takes four parameters: surface width, surface
+height, bit depth and surface flags. The flags parameter selects options for
+the video buffer:
+<pre> SDL.SURFACE.SWSURFACE - video buffer created in system memory
+ SDL.SURFACE.HWSURFACE - video buffer created in video memory
+ SDL.SURFACE.ASYNCBLIT - enable async updates of display surface
+ SDL.SURFACE.ANYFORMAT - don't emulate unavailable BPPs with a shadow surface
+ SDL.SURFACE.HWPALETTE - give SDL exclusive palette access (not supported)
+ SDL.SURFACE.DOUBLEBUF - enable hardware double buffering. (only works with
+ SDL.SURFACE.FULLSCREEN - use fullscreen mode
+ SDL.SURFACE.OPENGL - create an OpenGL rendering context (not supported)
+ SDL.SURFACE.RESIZABLE - create a resizable window
+ SDL.SURFACE.HWACCEL - use hardware accelerated blitter
+ SDL.SURFACE.SRCCOLORKEY - use color key blitter
+ SDL.SURFACE.RLEACCEL - color key blitting is accelerated with RLE
+ SDL.SURFACE.SRCALPHA - surface blit uses alpha blending
+ SDL.SURFACE.PREALLOC - surface uses preallocated memory
+Like other numeric constants, they may be combined with the or operator:
+<pre> var screen = SDL.setVideoMode( 640, 480, 32, SDL.SURFACE.HWSURFACE | SDL.SURFACE.HWACCEL );</pre>
+The surface created with the setVideoMode() call represents the contents of
+the displayed window. It's common practice to create a buffer surface to hold
+video contents in preparation for drawing on the screen. To create a buffer,
+use the createRGBSurface() call.
+<pre> var surface = SDL.createRGBSurface( SDL.SURFACE.SWSURFACE, 24, 24 );</pre>
+The first parameter describes the type of surface to create, and the remaining
+parameters are x and y sizes.
+To fill a rectangle with a particular color, use the fillRect() function.
+<pre> SDL.fillRect( surface, [0, 0, 24, 24], 0xFF8080AF );</pre>
### Image Functions
This package uses a supplimentary image library intended to make it easy for
node-sdl applications to load and use JPG, PNG or TIFF images. Before using
Image functions, you should initalize them with the image init() function:
-<pre> SDL.IMG.init( SDL.IMG.INIT.PNG );</pre>
-These three constants may be or'ed together to support more than one image
-<pre> SDL.IMG.INIT.JPG - JPEG Support
-SDL.IMG.INIT.TIF - TIFF Support</pre>
+<pre> SDL.IMG.init( 0 );</pre>
To load an image into memory, use the image load() function. It takes a file
path as a parameter and returns a reference to it. The following line loads
-a PNG file called "foo.png".
+a PNG file called "foo.png" into the variable foo.
+<pre> var foo = SDL.IMG.load( __dirname + '/foo.png' );</pre>
-<pre> SDL.IMG.load( __dirname + '/foo.png' );</pre>
+The foo variable can now be used as a surface blit calls (see below.)
After you are finished using the image functions, be sure to use the image
quit() function:
2 examples/BoxShower.js
@@ -5,7 +5,7 @@ SDL.IMG.init( 0 );
var doit = true;
-var screen = SDL.setVideoMode( 640, 640, 32, SDL.SURFACE.SWSURFACE );
+var screen = SDL.setVideoMode( 640, 480, 32, SDL.SURFACE.SWSURFACE );
var rectangles = [];
var colors = [ 0xFFFF0000, 0xFF00FF00, 0xFF0000FF ];

0 comments on commit 84e13b1

Please sign in to comment.
Something went wrong with that request. Please try again.