Changeset 2879 for libcaca/trunk/doc
- Timestamp:
- Oct 6, 2008, 9:33:15 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/doc/tutorial.dox
r2824 r2879 3 3 /** \page libcaca-tutorial A libcaca tutorial 4 4 5 First, a working program, very simple, to check you can compile and run it: 5 First, a very simple working program, to check for basic libcaca 6 functionalities. 6 7 7 8 \code 8 9 9 10 #include <caca.h> 10 #include <caca.h>11 11 12 12 int main(void) 13 13 { 14 /* Initialise libcaca */15 14 caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev; 15 16 16 dp = caca_create_display(NULL); 17 17 if(!dp) return 1; 18 18 cv = caca_get_canvas(dp); 19 /* Set window title */ 19 20 20 caca_set_display_title(dp, "Hello!"); 21 /* Choose drawing colours */22 21 caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); 23 /* Draw a string at coordinates (0, 0) */24 22 caca_put_str(cv, 0, 0, "This is a message"); 25 /* Refresh display */26 23 caca_refresh_display(dp); 27 /* Wait for a key press event */28 24 caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); 29 /* Clean up library */30 25 caca_free_display(dp); 31 26 … … 35 30 \endcode 36 31 32 What does it do? 33 - Create a display. Physically, the display is either a window or a context 34 in a terminal (ncurses, slang) or even the whole screen (VGA). 35 - Get the display's associated canvas. A canvas is the surface where 36 everything happens: writing characters, sprites, strings, images... It is 37 unavoidable. Here the size of the canvas is set by the display. 38 - Set the display's window name (only available in windowed displays, does 39 nothing otherwise). 40 - Set the current canvas colours to black background and white foreground. 41 - Write the string "This is a message" using the current colors onto the 42 canvas. 43 - Refresh the display. 44 - Wait for an event of type "CACA_EVENT_KEY_PRESS". 45 - Free the display (release memory). Since it was created together with the 46 display, the canvas will be automatically freed as well. 37 47 38 What does it do ? (we skip variable definitions, guessing you have a brain) : 39 - Create a caca canvas. A canvas is where everything happens. Writing characters, sprites, strings, images, everything. It is mandatory and is the reason of libcacas' beeing. Size is there a width of 0 pixels, and a height of 0 pixels. It'll be resized according to contents you put in it. 40 41 - Create a caca display. This is basically the window. Physically it can be a window (most of the displays), a console (ncurses, slang) or a real display (VGA). 42 43 - Set the window name of our display (only available in windowed displays, does nothing otherwise). (so this is libcaca related) 44 45 - Set current colors to black background, and white foreground of our canvas (so this is libcaca related) 46 47 - Put a string "This is a message" with current colors in our libcaca canvas. 48 49 - Refresh our caca display, whish was firstly attached to our canvas 50 51 - Wait for an event of type "CACA_EVENT_KEY_PRESS", which seems obvious. 52 53 - Free display (release memory) 54 55 - Free canvas (release memory and close window if any) 56 57 58 You can then compile this code under UNIX-like systems with following command : (you'll need pkg-config and gcc) 48 You can then compile this code on an UNIX-like system using the following 49 comman (requiring pkg-config and gcc): 59 50 \code 60 51 gcc `pkg-config --libs --cflags caca` example.c -o example
Note: See TracChangeset
for help on using the changeset viewer.