source: libcaca/trunk/doc/tutorial.dox @ 3473

Last change on this file since 3473 was 3473, checked in by Sam Hocevar, 11 years ago

A lot of documentation updates here and there, including bugfixes dating
back to the libcucul merge.

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1/* $Id: tutorial.dox 3473 2009-05-19 00:52:10Z sam $ */
2
3/** \page libcaca-tutorial A libcaca tutorial
4
5First, a very simple working program, to check for basic libcaca
6functionalities.
7
8\code
9
10#include <caca.h>
11
12int main(void)
13{
14    caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
15
16    dp = caca_create_display(NULL);
17    if(!dp) return 1;
18    cv = caca_get_canvas(dp);
19
20    caca_set_display_title(dp, "Hello!");
21    caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
22    caca_put_str(cv, 0, 0, "This is a message");
23    caca_refresh_display(dp);
24    caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
25    caca_free_display(dp);
26
27    return 0;
28}
29
30\endcode
31
32What 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 \c "This is a message" onto the canvas, using the current
42   colour pair.
43 - Refresh the display, causing the text to be effectively displayed.
44 - Wait for an event of type \c 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.
47
48You can then compile this code on an UNIX-like system using the following
49commans (requiring \c pkg-config and \c gcc):
50\code
51gcc `pkg-config --libs --cflags caca` example.c -o example
52\endcode
53
54*/
Note: See TracBrowser for help on using the repository browser.