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

Last change on this file since 1988 was 1946, checked in by Sam Hocevar, 12 years ago
  • Add error checking to the tutorial.
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/* $Id: tutorial.dox 1946 2007-11-13 11:19:00Z sam $ */
2
3/** \page libcaca-tutorial A libcucul and libcaca tutorial
4
5 Before writing your first libcaca application, you need to know the difference between libcucul and libcaca :
6- libcucul is the text rendering library. It will do all the work you actually need. From imports (text, ANSI, caca internal format, all of this supporting n-bytes unicode), to exports (sames formats, adding SVG, PostScript, TGA, HTML (both 3 and 4), IRC), it'll cover all your needs.
7- libcaca handle everything that can be hardware related. It includes display (RAW, X11, OpenGL, Windows (GDI), conio (DOS), ncurses, slang, text VGA (IMB-Compatible)), keyboard (same drivers but RAW), mouse (same drivers but RAW and VGA), time and resize events (on windowed drivers).
8
9So, you can write a libcucul only program, but you <b>can't</b> write a libcaca only program, it'll be nonsense. Period.
10
11
12First, a working program, very simple, to check you can compile and run it:
13
14\code
15
16#include <cucul.h>
17#include <caca.h>
18
19int main(void)
20{
21    /* Initialise libcaca */
22    cucul_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
23    cv = cucul_create_canvas(0, 0);
24    if(!cv) return 1;
25    dp = caca_create_display(cv);
26    if(!dp) return 1;
27    /* Set window title */
28    caca_set_display_title(dp, "Hello!");
29    /* Choose drawing colours */
30    cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
31    /* Draw a string at coordinates (0, 0) */
32    cucul_put_str(cv, 0, 0, "This is a message");
33    /* Refresh display */
34    caca_refresh_display(dp);
35    /* Wait for a key press event */
36    caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
37    /* Clean up library */
38    caca_free_display(dp);
39    cucul_free_canvas(cv);
40
41    return 0;
42}
43
44\endcode
45
46
47What does it do ? (we skip variable definitions, guessing you have a brain) :
48- Create a cucul canvas. A canvas is where everything happens. Writing characters, sprites, strings, images, everything. It is mandatory and is the reason of libcuculs' 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.
49
50- 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).
51
52- Set the window name of our display (only available in windowed displays, does nothing otherwise). (so this is libcaca related)
53 
54- Set current colors to black background, and white foreground of our canvas (so this is libcucul related)
55
56- Put a string "This is a message" with current colors in our libcucul canvas.
57
58- Refresh our caca display, whish was firstly attached to our canvas
59
60- Wait for an event of type "CACA_EVENT_KEY_PRESS", which seems obvious.
61
62- Free display (release memory)
63
64- Free canvas (release memory and close window if any)
65
66
67You can then compile this code under UNIX-like systems with following command : (you'll need pkg-config and gcc)
68\code
69gcc `pkg-config --libs --cflags cucul caca` example.c -o example
70\endcode
71
72*/
Note: See TracBrowser for help on using the repository browser.