Allegro Wrapper

Allegro Wrapper è un wrapper ad oggetti della libreria Allegro (versione 4). Le primitive di Allegro Wrapper sono state presentate nel corso della lezione del 14 maggio 2013. Nella prossima lezione vedremo alcune funzionalità avanzate, quali disegno di testo, programmazione a sprite e audio.

Il wrapper è scaricabile al seguente indirizzo: [link]. Ricordarsi di installare i pacchetti della libreria Allegro (quella vera). Per Debian e derivate i pacchetti sono: liballegro4.2-dev, liballegro4.4, liballegro4.4-plugin-alsa. Per compilare ricordatevi di includere -lalleg fra le opzioni di g++.

Chi vuole studiare la libreria Allegro può considerare il libro Game Programming All in One – Third Edition di Jonathan S. Harbour.

Di seguito l’esempio visto a lezione (classe MyAllegro e main).

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Allegro.h"
 
class MyAllegro : public Allegro {
public:
    MyAllegro();
    virtual ~MyAllegro();
 
    void onTick();
 
private:
    Circle* blueCircle;
    Line* redLine;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
MyAllegro::MyAllegro() {
    blueCircle = new Circle(Point(0, 0), 50, Color(0,0,255), true);
    add(DrawablePointer(*blueCircle));
 
    redLine = new Line(Point(0,0), Point(0,0), Color(255,0,0));
    add(DrawablePointer(*redLine));
}
 
MyAllegro::~MyAllegro() {
    delete blueCircle;
    delete redLine;
}
 
void MyAllegro::onTick() {
    if(getKeyboard().isKeyPressed(KEY_DOWN)) {
        blueCircle->incrementCenterY(10);
    }
    if(getKeyboard().isKeyPressed(KEY_UP)) {
        blueCircle->incrementCenterY(-10);
    }
    if(getKeyboard().isKeyPressed(KEY_LEFT)) {
        blueCircle->incrementCenterX(-10);
    }
    if(getKeyboard().isKeyPressed(KEY_RIGHT)) {
        blueCircle->incrementCenterX(10);
    }
    if(getKeyboard().isKeyPressed(KEY_W)) {
        blueCircle->incrementRadius(-1);
    }
    if(getKeyboard().isKeyPressed(KEY_E)) {
        blueCircle->incrementRadius(1);
    }
    if(getKeyboard().isKeyPressed(KEY_Q)) {
        exit = true;
    }
 
    redLine->setPoint2(blueCircle->getCenter());
 
    static unsigned i = 0;
    if(++i % 5 == 0) {
        draw();
        i = 0;
    }
}
1
2
3
4
5
6
7
8
9
#include "MyAllegro.h"
 
int main() {
    MyAllegro allegro;
    allegro.run();
 
    return 0;
}
END_OF_MAIN()

Ecco cosa otteniamo eseguendo il codice riportato sopra.

allegro1

allegro2

28 thoughts on “Allegro Wrapper”

  1. Professore, compilando, mi da il seguente errore:

    Allegro.cpp: In static member function ‘static void Allegro::showMessage(std::string)’:
    Allegro.cpp:89: warning: format not a string literal and no format arguments

  2. Oltre ai precedenti errori mi da anche i seguenti errori:

    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_hide_x_mouse’:
    (.text+0x883e): undefined reference to `XCreatePixmapCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_hide_x_mouse’:
    (.text+0x8851): undefined reference to `XDefineCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_hide_x_mouse’:
    (.text+0x885c): undefined reference to `XFreePixmap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_hide_x_mouse’:
    (.text+0x8877): undefined reference to `XFreeCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x88cc): undefined reference to `XBlackPixel’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x88e1): undefined reference to `XBlackPixel’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x88fc): undefined reference to `XDefaultRootWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x8928): undefined reference to `XCreateWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x893f): undefined reference to `XGetWindowAttributes’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x8980): undefined reference to `XCreateColormap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x8996): undefined reference to `XSetWindowColormap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x89a4): undefined reference to `XInstallColormap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x89d9): undefined reference to `XCreateWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x89ee): undefined reference to `XMapWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x89fc): undefined reference to `XInternAtom’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x8a1a): undefined reference to `XSetWMProtocols’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x8a65): undefined reference to `XCreateGC’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_window’:
    (.text+0x8a76): undefined reference to `XcursorSupportsARGB’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_display_is_local’:
    (.text+0x8c13): undefined reference to `XDisplayName’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `free_modelines’:
    (.text+0x8c8a): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `free_modelines’:
    (.text+0x8ce3): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `free_modelines’:
    (.text+0x8cfd): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `free_modelines’:
    (.text+0x8d17): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `free_modelines’:
    (.text+0x8d31): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o):(.text+0x8d4b): more undefined references to `XFree’ follow
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_fetch_mode_list’:
    (.text+0x93ad): undefined reference to `XF86VidModeQueryExtension’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_fetch_mode_list’:
    (.text+0x93cb): undefined reference to `XF86VidModeQueryVersion’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_fetch_mode_list’:
    (.text+0x93ec): undefined reference to `XF86VidModeGetAllModeLines’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_get_pointer_mapping’:
    (.text+0x94ba): undefined reference to `XGetPointerMapping’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `xwin_set_window_name’:
    (.text+0x95c8): undefined reference to `XSetClassHint’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_set_window_title’:
    (.text+0x969d): undefined reference to `XStoreName’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_flush_buffers’:
    (.text+0x9862): undefined reference to `XSync’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_enable_hardware_cursor’:
    (.text+0x9a1d): undefined reference to `XWarpPointer’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_handle_input’:
    (.text+0x9af0): undefined reference to `XWarpPointer’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_handle_input’:
    (.text+0x9b04): undefined reference to `XEventsQueued’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_handle_input’:
    (.text+0x9b43): undefined reference to `XNextEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_handle_input’:
    (.text+0x9b80): undefined reference to `XNextEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_handle_input’:
    (.text+0x9ba0): undefined reference to `XNextEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_handle_input’:
    (.text+0x9baf): undefined reference to `XNextEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_handle_input’:
    (.text+0x9bcd): undefined reference to `XNextEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o):(.text+0x9bdb): more undefined references to `XNextEvent’ follow
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `.L1354′:
    (.text+0x9fd3): undefined reference to `XWarpPointer’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_vsync’:
    (.text+0xa303): undefined reference to `XSync’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_vsync’:
    (.text+0xa373): undefined reference to `XSync’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_show_mouse’:
    (.text+0xa75d): undefined reference to `XUndefineCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_show_mouse’:
    (.text+0xa769): undefined reference to `XFreeCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_show_mouse’:
    (.text+0xa778): undefined reference to `XcursorImageLoadCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_show_mouse’:
    (.text+0xa789): undefined reference to `XDefineCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_set_mouse_sprite’:
    (.text+0xa830): undefined reference to `XcursorImageDestroy’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_set_mouse_sprite’:
    (.text+0xa87d): undefined reference to `XcursorImageCreate’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xaf5c): undefined reference to `XF86VidModeLockModeSwitch’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xaf77): undefined reference to `XF86VidModeSwitchToMode’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xafee): undefined reference to `XUnmapWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xb01e): undefined reference to `XReparentWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xb030): undefined reference to `XUnmapWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xb041): undefined reference to `XDestroyWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xb068): undefined reference to `XUngrabKeyboard’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xb088): undefined reference to `XUngrabPointer’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_destroy_screen’:
    (.text+0xb0ad): undefined reference to `XShmDetach’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_set_matching_colors’:
    (.text+0xb407): undefined reference to `XStoreColors’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb6ae): undefined reference to `XResizeWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb6ef): undefined reference to `XBlackPixel’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb702): undefined reference to `XBlackPixel’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb726): undefined reference to `XDefaultRootWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb754): undefined reference to `XCreateWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb765): undefined reference to `XMapRaised’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb797): undefined reference to `XMaskEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb7c0): undefined reference to `XRaiseWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb7d9): undefined reference to `XReparentWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb7e3): undefined reference to `XDefaultRootWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb7f5): undefined reference to `XGrabKeyboard’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb825): undefined reference to `XGrabPointer’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb845): undefined reference to `XSync’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb88c): undefined reference to `XMoveWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb8bf): undefined reference to `XWarpPointer’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xb903): undefined reference to `XCreateImage’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xba03): undefined reference to `XAllocColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xba43): undefined reference to `XAllocColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xba86): undefined reference to `XAllocColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xbac9): undefined reference to `XAllocColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xbb0c): undefined reference to `XAllocColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o):(.text+0xbb4f): more undefined references to `XAllocColor’ follow
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc1f3): undefined reference to `XAllocSizeHints’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc206): undefined reference to `XResizeWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc23c): undefined reference to `XSetWMNormalHints’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc247): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc259): undefined reference to `XMapWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc27b): undefined reference to `XMaskEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc2a0): undefined reference to `XShmQueryExtension’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc2d5): undefined reference to `XShmCreateImage’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc33b): undefined reference to `XShmAttach’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc351): undefined reference to `XSync’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc3cb): undefined reference to `XF86VidModeQueryExtension’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc3ee): undefined reference to `XF86VidModeQueryVersion’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc411): undefined reference to `XF86VidModeGetAllModeLines’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xc84b): undefined reference to `XStoreColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xcb73): undefined reference to `XStoreColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xcbe0): undefined reference to `XStoreColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xcc49): undefined reference to `XStoreColor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xcef7): undefined reference to `XF86VidModeSwitchToMode’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xcf39): undefined reference to `XF86VidModeLockModeSwitch’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_private_create_screen’:
    (.text+0xcf47): undefined reference to `XF86VidModeSetViewPort’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd550): undefined reference to `XcursorImageDestroy’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd573): undefined reference to `XFreeGC’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd5a0): undefined reference to `XDestroyWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd5df): undefined reference to `XUnmapWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd5ed): undefined reference to `XDestroyWindow’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd607): undefined reference to `XUninstallColormap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd615): undefined reference to `XFreeColormap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd632): undefined reference to `XUndefineCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_destroy_window’:
    (.text+0xd640): undefined reference to `XFreeCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_close_display’:
    (.text+0xd69b): undefined reference to `XCloseDisplay’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_open_display’:
    (.text+0xd769): undefined reference to `XOpenDisplay’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xwin.o): In function `_xwin_open_display’:
    (.text+0xd77d): undefined reference to `XDefaultScreen’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(umodules.o): In function `_unix_unload_modules’:
    (.text+0x3e): undefined reference to `dlsym’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(umodules.o): In function `_unix_unload_modules’:
    (.text+0x52): undefined reference to `dlsym’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(umodules.o): In function `_unix_unload_modules’:
    (.text+0x76): undefined reference to `dlclose’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(umodules.o): In function `_unix_load_modules’:
    (.text+0x2f3): undefined reference to `dlopen’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(umodules.o): In function `_unix_load_modules’:
    (.text+0x30d): undefined reference to `dlsym’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(uptimer.o): In function `ptimer_exit’:
    (.text+0x30): undefined reference to `pthread_join’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(uptimer.o): In function `ptimer_init’:
    (.text+0x6d): undefined reference to `pthread_create’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(uptimer.o): In function `ptimer_thread_func’:
    (.text+0xb9): undefined reference to `pthread_sigmask’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(uthreads.o): In function `bg_man_pthreads_exit’:
    (.text+0x74a): undefined reference to `pthread_join’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(uthreads.o): In function `bg_man_pthreads_init’:
    (.text+0x880): undefined reference to `pthread_create’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(uthreads.o): In function `bg_man_pthreads_threadfunc’:
    (.text+0x8e9): undefined reference to `pthread_sigmask’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_set_leds’:
    (.text+0x88): undefined reference to `XChangeKeyboardControl’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_set_leds’:
    (.text+0xb0): undefined reference to `XChangeKeyboardControl’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_set_leds’:
    (.text+0xca): undefined reference to `XChangeKeyboardControl’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_exit’:
    (.text+0x15b): undefined reference to `XDestroyIC’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_exit’:
    (.text+0x17b): undefined reference to `XCloseIM’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_exit’:
    (.text+0x19b): undefined reference to `XFreeModifiermap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_exit’:
    (.text+0x1bb): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `find_unknown_key_assignment’:
    (.text+0x2ea): undefined reference to `XKeysymToString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `find_unknown_key_assignment’:
    (.text+0x336): undefined reference to `XKeysymToString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_keyboard_handler’:
    (.text+0x850): undefined reference to `Xutf8LookupString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_keyboard_handler’:
    (.text+0x893): undefined reference to `XFilterEvent’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_keyboard_handler’:
    (.text+0x1451): undefined reference to `XLookupString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x14f1): undefined reference to `XDisplayKeycodes’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x1515): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x153c): undefined reference to `XGetKeyboardMapping’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x158d): undefined reference to `XKeysymToString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x1595): undefined reference to `XKeysymToString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x176e): undefined reference to `XKeysymToString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x17bf): undefined reference to `XFreeModifiermap’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x17d3): undefined reference to `XGetModifierMapping’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x1810): undefined reference to `XKeycodeToKeysym’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `_xwin_get_keyboard_mapping’:
    (.text+0x1818): undefined reference to `XKeysymToString’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_init’:
    (.text+0x19fc): undefined reference to `XOpenIM’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_init’:
    (.text+0x1a21): undefined reference to `XGetIMValues’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_init’:
    (.text+0x1b3d): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_init’:
    (.text+0x1b71): undefined reference to `XCreateIC’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xkeyboard.o): In function `x_keyboard_init’:
    (.text+0x1bbd): undefined reference to `XFree’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_select_system_cursor’:
    (.text+0x78): undefined reference to `XCreateFontCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_select_system_cursor’:
    (.text+0x8b): undefined reference to `XDefineCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_select_system_cursor’:
    (.text+0xd2): undefined reference to `XUndefineCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_select_system_cursor’:
    (.text+0xe0): undefined reference to `XFreeCursor’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_set_mouse_speed’:
    (.text+0x32a): undefined reference to `XChangePointerControl’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_set_mouse_speed’:
    (.text+0x389): undefined reference to `XGetPointerControl’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_mousedrv_exit’:
    (.text+0x467): undefined reference to `XChangePointerControl’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_mouse_leave_notify’:
    (.text+0x4fd): undefined reference to `XChangePointerControl’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xmouse.o): In function `_xwin_mousedrv_position’:
    (.text+0x5e2): undefined reference to `XWarpPointer’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_clear_to_color’:
    (.text+0x35e): undefined reference to `XSetForeground’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_clear_to_color’:
    (.text+0x394): undefined reference to `XFillRectangle’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_rectfill’:
    (.text+0x1beb): undefined reference to `XSetForeground’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_rectfill’:
    (.text+0x1c20): undefined reference to `XFillRectangle’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_hline’:
    (.text+0x1e46): undefined reference to `XSetForeground’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_hline’:
    (.text+0x1e61): undefined reference to `XDrawLine’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_vline’:
    (.text+0x204c): undefined reference to `XSetForeground’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_vline’:
    (.text+0x2067): undefined reference to `XDrawLine’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_putpixel’:
    (.text+0x21f4): undefined reference to `XSetForeground’
    /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/liballeg.a(xvtable.o): In function `_xwin_putpixel’:
    (.text+0x2208): undefined reference to `XDrawPoint’

  3. Sì, esatto, la versione è la 4.4.3. Ho installato liballegro4.2-dev. Nella repository di Ubuntu 10.04 non ho trovato la versione 4.4

  4. Prova con:

    g++ *.cpp `allegro-config –libs`

    Nota gli apici inversi. Se non risolvi così, prova a passare a ricevimento con il computer.

  5. In alternativa, esegui:

    allegro-config –libs

    e aggiungi alle opzioni di g++ quello che ti viene stampato. Ad esempio, da me ottengo:

    -L/usr/lib/x86_64-linux-gnu -lalleg

    L’opzione -L indica a g++ dove cercare i file di libreria. Fammi sapere se risolvi.

  6. Utilizzando g++ *.cpp `allegro-config –libs` mi da sempre lo stesso warning relativo al metodo showMessage. Ho provato a commentare la riga di codice del metodo e compila. Tuttavia l’esecuzione viene abortita quasi immediatamente, e mi da il seguente messaggio:

    a.out: Allegro.cpp:54: Allegro::Allegro(unsigned int, unsigned int, unsigned int, bool): Assertion `0′ failed.
    Shutting down Allegro due to signal #6
    Abortito

    Ora provo, come mi ha suggerito lei, ad indicare la path della libreria ogni qual volta utilizzo il comando g++. Ma non capisco il perchè non individui il percorso della libreria automaticamente…

  7. OK. Per compilare usa `allegro-config –libs`. In teoria è il modo corretto di farlo. Su Debian si riesce a compilare anche con -lalleg. Forse Ubuntu installa la libreria in un percorso diverso.

    Per l’asserzione, credo che non ti stia riconoscendo l’audio. Hai installato il pacchetto liballegro4.4-plugin-alsa o qualcosa di simile? Se non hai questo pacchetto, prova a commentare le linee da 52 a 55 in Allegro.cpp. Non potrai usare l’audio, ma almeno per ora può andare bene così.

  8. Prof, digitando allegro-config –libs mi viene stampato:
    -L/usr/lib -Wl,-Bsymbolic-functions -lalleg-4.2.2

    Perciò, ho provato a compilare digitando:
    g++ *.cpp -L/usr/lib -Wl,-Bsymbolic-functions -lalleg-4.2.2

    Sempre stesso warning…

  9. Puoi ignorare il warning. Non è importante. Prova a commentare le linee che ti ho indicato nel commento precedente e vedi se riesci a far partire l’applicazione.

  10. Ok perfetto, commentando il pezzo di codice inerente all’audio… ora compila e viene eseguito perfettamente.
    Quanto alle librerie installate… ho installato soltanto liballegro4.2-dev. Nella repo di ubuntu non ho trovato liballegro4.4 e liballegro4.4-plugin-alsa. Provo a scaricarli e installarli manualmente.
    Comunque, grazie infinite, almeno per il momento il problema è risolto.

  11. A quanto pare non esiste un pacchetto liballegro4.4 compatibile con ubuntu 10.04.
    Gli unici ad essere compatibili sembrerebbero essere Ubuntu 12.10 e Ubuntu 13.04.

    Vorrei cogliere l’occasione per chiederle quale S.O. utilizza durante le lezioni, grazie.

  12. Sul portatile ho Debian unstable (sid) + pacchetti experimental. Sul netpc ho Linux Mint Debian Edition. Su entrambi uso Xfce come desktop environment.

  13. Professore, compilando con:

    g++ *.cpp `allegro-config –libs`

    ho come risultato il warning alla riga 89. Comunque, ignorandolo, e mandando in esecuzione a.out ottengo questi errori:

    jack_client_new: deprecated
    Cannot connect to server socket err = No such file or directory
    Cannot connect to server socket
    jack server is not running or cannot be started

    e il cursore si posiziona sulla sinistra.

    La finestra si apre e funziona correttamente ma premendo sulla x rimane aperta comunque, riesco a chiuderla solo chiudendo l’intero terminare dalla X (con conseguente messaggio “un processo è ancora in esecuzione……….”)

    Ha idea di cosa possa essere?

    1. Sì, per chiudere devi settare la variable stop della classe Allegro. In questo esempio viene settata premendo Q.

      Il warning puoi ignorarlo. Oppure prova a sostituire la linea 89 di Allegro.cpp con:

      89
      
          allegro_message("%s", s.c_str());

      L’errore su jack_client_new dovrebbe essere per l’audio. Prova a commentare le linee da 52 a 55 di Allegro.cpp. Per cursore intendi il puntatore del mouse?

  14. Ho appena aggiornato il codice. Se l’audio non è supportato, l’applicazione segnala il problema ma non termina l’esecuzione. Il warning su show_message è stato fissato. Ho inoltre aggiunto la possibilità di iterare sui Drawable delle CompositeBitmap in modo da poterli rimuovere (il metodo add ora restituisce un iteratore per questo scopo).

  15. Tutto ok, il warning non viene più visualizzato e commentando dalla riga 52 a 55 di Allegro.cpp l’errore non c’è più…per quanto riguarda il cursore intendevo quello sul terminale ma rimaneva in quel punto solo perchè rimaneva in esecuzione l’a,out…tutto ok….
    Quindi ora l’audio lo posso utilizzare comunque?

  16. Per l’audio servono le righe 52-55. Prova a commentare solo l’assert. Dovrebbe visualizzarti un messaggio d’errore con qualche descrizione del problema.

  17. Commentando solo l’assert mi visualizza le stesse righe di errore di prima, durante l’esecuzione. (jack_client ecc. )

  18. Si l’ho installato, infatti ho provato ad inserire qualche suono e l’audio funziona anche con quei soliti errori…quindi sembra che sia tutto ok…

    1. Sarebbe carino capire perché funziona nonostante l’errore. Ad ogni modo, se non vuoi visualizzare il messaggio d’errore, commenta l’istruzione showMessage(getLastError()) alla linea 53.

Leave a Reply

Your email address will not be published. Required fields are marked *