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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1/** \page libcaca-tutorial A libcaca tutorial
2
3First, a very simple working program, to check for basic libcaca
4functionalities.
5
6\code
7
8#include <caca.h>
9
10int main(void)
11{
12    caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
13
14    dp = caca_create_display(NULL);
15    if(!dp) return 1;
16    cv = caca_get_canvas(dp);
17
18    caca_set_display_title(dp, "Hello!");
19    caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
20    caca_put_str(cv, 0, 0, "This is a message");
21    caca_refresh_display(dp);
22    caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
23    caca_free_display(dp);
24
25    return 0;
26}
27
28\endcode
29
30What does it do?
31 - Create a display. Physically, the display is either a window or a context
32   in a terminal (ncurses, slang) or even the whole screen (VGA).
33 - Get the display's associated canvas. A canvas is the surface where
34   everything happens: writing characters, sprites, strings, images... It is
35   unavoidable. Here the size of the canvas is set by the display.
36 - Set the display's window name (only available in windowed displays, does
37   nothing otherwise).
38 - Set the current canvas colours to black background and white foreground.
39 - Write the string \c "This is a message" onto the canvas, using the current
40   colour pair.
41 - Refresh the display, causing the text to be effectively displayed.
42 - Wait for an event of type \c CACA_EVENT_KEY_PRESS.
43 - Free the display (release memory). Since it was created together with the
44   display, the canvas will be automatically freed as well.
45
46You can then compile this code on an UNIX-like system using the following
47commans (requiring \c pkg-config and \c gcc):
48\code
49gcc `pkg-config --libs --cflags caca` example.c -o example
50\endcode
51
52*/
Note: See TracBrowser for help on using the repository browser.