Questions SDL1 SDK for MorphOs
  • Order of the Butterfly
    Order of the Butterfly
    eliot
    Posts: 457 from 2004/4/15
    Hello,

    since SDL2 is not fully supported on MorphOs I decided to use SDL1.
    So I downloaded the SDL1 SDK (16.1) and looked for working examples and MorphOs specific stuff.
    Sadly I could not find anything which helped me.

    1. Where to copy the content of Developer/usr/local?
    Should it be copied to gg:usr?

    2. I looked into the examples and Makefiles.
    None of the examples provided by the sdk will compile on MorphOs
    Why? Because sdk-config provides wrong include path and cflags.
    There aren't any static libraries in the sdk at all (which is totally ok when you want
    to use the MorphOs). But I wonder how the examples
    should work on MorphOs and why they provided by the SDK?

    So all this leads to one simple short question: Is there somewhere a really short working example
    of using SDL1 on MorphOs?

    EDIT:
    Small example, which does not compile:
    Code:

    #include <proto/exec.h>
    #include <proto/powersdl.h>
    //#include <proto/powersdl_gfx.h>
    #include <iostream>

    struct Library *PowerSDLBase=nullptr;
    //struct Library *PowerSDLGfxBase=nullptr;

    using namespace std;


    static void setupOpengl(int width, int height) {
    }

    static void drawScreen() {

    }

    int main(int argc, char *argv[]) {
    cout << "begin ..." << endl;
    /* mos */
    if ((PowerSDLBase = OpenLibrary((STRPTR)"powersdl.library", 16))==nullptr){
    cout<<"could not open powersdl.library"<<endl;
    return -1;
    }
    /*if ((PowerSDLGfxBase = OpenLibrary((STRPTR)"powersdl_gfx.library", 16))==nullptr){
    cout<<"could not open powersdl_gfx.library"<<endl;
    return -2;
    }*/

    int res = SDL_Init(SDL_INIT_VIDEO);
    if (res) {
    cout << "could not init sdl, result=" << res << ", error=" << SDL_GetError() << endl;
    }

    SDL_Surface *screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
    if (screen == nullptr) {
    cout << "could set display mode, error=" << SDL_GetError() << endl;
    }

    setupOpengl(640, 480);

    SDL_Event event;
    bool b = true;
    while (b) {
    res = SDL_PollEvent(&event);
    if (res) {
    switch (event.type) {
    case SDL_KEYDOWN:
    cout << "key down event" << endl;
    break;
    case SDL_KEYUP:
    cout << "key up event" << endl;
    break;
    case SDL_MOUSEMOTION:
    cout << "mouse motion event" << endl;
    break;
    case SDL_MOUSEBUTTONDOWN:
    cout << "mouse button down event" << endl;
    break;
    case SDL_MOUSEBUTTONUP:
    cout << "mouse button up event" << endl;
    break;
    case SDL_QUIT:
    cout << "quit event" << endl;
    b = false;
    break;
    }
    }
    drawScreen();
    SDL_Delay(40);
    }

    SDL_Quit();
    /* mos */
    CloseLibrary(PowerSDLBase);
    //CloseLibrary(PowerSDLGfxBase);

    cout << "end!" << endl;
    return 0;
    }


    Compiled with: g++ -std=c++11 -noixemul -o test_sdl test_sdl.cpp

    Result:
    Code:

    In file included from /System/Development/GG/usr/include/proto/powersdl.h:12:0,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/clib/powersdl_protos.h:79:69: error: conflicting declaration of C function 'Uint32 SDL_MapRGB(SDL_PixelFormat*, Uint8, Uint8, Uint8)'
    Uint32 SDL_MapRGB(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b);
    ^
    In file included from /System/Development/GG/usr/include/SDL/SDL_mouse.h:32:0,
    from /System/Development/GG/usr/include/SDL/SDL_events.h:35,
    from /System/Development/GG/usr/include/SDL/SDL.h:37,
    from /System/Development/GG/usr/include/clib/powersdl_protos.h:16,
    from /System/Development/GG/usr/include/proto/powersdl.h:12,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/SDL/SDL_video.h:492:32: note: previous declaration 'Uint32 SDL_MapRGB(const SDL_PixelFormat*, Uint8, Uint8, Uint8)'
    extern DECLSPEC Uint32 SDLCALL SDL_MapRGB
    ^
    In file included from /System/Development/GG/usr/include/proto/powersdl.h:12:0,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/clib/powersdl_protos.h:80:79: error: conflicting declaration of C function 'Uint32 SDL_MapRGBA(SDL_PixelFormat*, Uint8, Uint8, Uint8, Uint8)'
    Uint32 SDL_MapRGBA(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
    ^
    In file included from /System/Development/GG/usr/include/SDL/SDL_mouse.h:32:0,
    from /System/Development/GG/usr/include/SDL/SDL_events.h:35,
    from /System/Development/GG/usr/include/SDL/SDL.h:37,
    from /System/Development/GG/usr/include/clib/powersdl_protos.h:16,
    from /System/Development/GG/usr/include/proto/powersdl.h:12,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/SDL/SDL_video.h:499:32: note: previous declaration 'Uint32 SDL_MapRGBA(const SDL_PixelFormat*, Uint8, Uint8, Uint8, Uint8)'
    extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA
    ^
    In file included from /System/Development/GG/usr/include/proto/powersdl.h:12:0,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/clib/powersdl_protos.h:91:79: error: conflicting declaration of C function 'void SDL_GetRGB(Uint32, SDL_PixelFormat*, Uint8*, Uint8*, Uint8*)'
    void SDL_GetRGB(Uint32 pix, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b);
    ^
    In file included from /System/Development/GG/usr/include/SDL/SDL_mouse.h:32:0,
    from /System/Development/GG/usr/include/SDL/SDL_events.h:35,
    from /System/Development/GG/usr/include/SDL/SDL.h:37,
    from /System/Development/GG/usr/include/clib/powersdl_protos.h:16,
    from /System/Development/GG/usr/include/proto/powersdl.h:12,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/SDL/SDL_video.h:506:30: note: previous declaration 'void SDL_GetRGB(Uint32, const SDL_PixelFormat*, Uint8*, Uint8*, Uint8*)'
    extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
    ^
    In file included from /System/Development/GG/usr/include/proto/powersdl.h:12:0,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/clib/powersdl_protos.h:92:90: error: conflicting declaration of C function 'void SDL_GetRGBA(Uint32, SDL_PixelFormat*, Uint8*, Uint8*, Uint8*, Uint8*)'
    void SDL_GetRGBA(Uint32 pix, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
    ^
    In file included from /System/Development/GG/usr/include/SDL/SDL_mouse.h:32:0,
    from /System/Development/GG/usr/include/SDL/SDL_events.h:35,
    from /System/Development/GG/usr/include/SDL/SDL.h:37,
    from /System/Development/GG/usr/include/clib/powersdl_protos.h:16,
    from /System/Development/GG/usr/include/proto/powersdl.h:12,
    from test_sdl.cpp:2:
    /System/Development/GG/usr/include/SDL/SDL_video.h:513:30: note: previous declaration 'void SDL_GetRGBA(Uint32, const SDL_PixelFormat*, Uint8*, Uint8*, Uint8*, Uint8*)'
    extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,


    regards
    eliot

    www.exception-dev.de
  • »08.02.17 - 08:55
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    eliot
    Posts: 457 from 2004/4/15
    Finally I found a way to use SDL if I statcally link sdl:

    Code:

    //#include <proto/exec.h>
    //#include <proto/powersdl.h>
    //#include <proto/powersdl_gfx.h>
    #include <SDL/SDL.h>
    #include <GL/gl.h>
    #include <iostream>

    //struct Library *PowerSDLBase=nullptr;
    //struct Library *PowerSDLGfxBase=nullptr;

    using namespace std;

    static void setupOpengl(int width, int height) {
    float ratio = (float) width / (float) height;
    glShadeModel(GL_SMOOTH);

    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glEnable(GL_CULL_FACE);

    glClearColor(0, 0, 0, 0);

    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, ratio, 1.0, 1024.0);
    }

    static void drawScreen() {
    /* Our angle of rotation. */
    static float angle = 0.0f;

    static GLfloat v0[] = {-1.0f, -1.0f, 1.0f};
    static GLfloat v1[] = {1.0f, -1.0f, 1.0f};
    static GLfloat v2[] = {1.0f, 1.0f, 1.0f};
    static GLfloat v3[] = {-1.0f, 1.0f, 1.0f};
    static GLfloat v4[] = {-1.0f, -1.0f, -1.0f};
    static GLfloat v5[] = {1.0f, -1.0f, -1.0f};
    static GLfloat v6[] = {1.0f, 1.0f, -1.0f};
    static GLfloat v7[] = {-1.0f, 1.0f, -1.0f};
    static GLubyte red[] = {255, 0, 0, 255};
    static GLubyte green[] = {0, 255, 0, 255};
    static GLubyte blue[] = {0, 0, 255, 255};
    static GLubyte white[] = {255, 255, 255, 255};
    static GLubyte yellow[] = {0, 255, 255, 255};
    static GLubyte black[] = {0, 0, 0, 255};
    static GLubyte orange[] = {255, 255, 0, 255};
    static GLubyte purple[] = {255, 0, 255, 0};

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0.0, 0.0, -5.0);

    glRotatef(angle, 0.0, 1.0, 0.0);

    if (++angle > 360.0f) {
    angle = 0.0f;
    }


    glBegin(GL_TRIANGLES);

    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(blue);
    glVertex3fv(v2);

    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(blue);
    glVertex3fv(v2);
    glColor4ubv(white);
    glVertex3fv(v3);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(black);
    glVertex3fv(v5);
    glColor4ubv(orange);
    glVertex3fv(v6);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(orange);
    glVertex3fv(v6);
    glColor4ubv(blue);
    glVertex3fv(v2);

    glColor4ubv(black);
    glVertex3fv(v5);
    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(purple);
    glVertex3fv(v7);

    glColor4ubv(black);
    glVertex3fv(v5);
    glColor4ubv(purple);
    glVertex3fv(v7);
    glColor4ubv(orange);
    glVertex3fv(v6);

    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(white);
    glVertex3fv(v3);

    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(white);
    glVertex3fv(v3);
    glColor4ubv(purple);
    glVertex3fv(v7);

    glColor4ubv(white);
    glVertex3fv(v3);
    glColor4ubv(blue);
    glVertex3fv(v2);
    glColor4ubv(orange);
    glVertex3fv(v6);

    glColor4ubv(white);
    glVertex3fv(v3);
    glColor4ubv(orange);
    glVertex3fv(v6);
    glColor4ubv(purple);
    glVertex3fv(v7);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(yellow);
    glVertex3fv(v4);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(black);
    glVertex3fv(v5);

    glEnd();

    SDL_GL_SwapBuffers();
    }

    int main(int argc, char *argv[]) {
    cout << "begin ..." << endl;
    /* mos */
    /*if ((PowerSDLBase = OpenLibrary((STRPTR)"powersdl.library", 16))==nullptr){
    cout<<"could not open powersdl.library"<<endl;
    return -1;
    }*/
    /*if ((PowerSDLGfxBase = OpenLibrary((STRPTR)"powersdl_gfx.library", 11))==nullptr){
    cout<<"could not open powersdl_gfx.library"<<endl;
    return -2;
    } */

    int res = SDL_Init(SDL_INIT_VIDEO);
    if (res) {
    cout << "could not init sdl, result=" << res << ", error=" << SDL_GetError() << endl;
    }

    SDL_Surface *screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
    if (screen == nullptr) {
    cout << "could set display mode, error=" << SDL_GetError() << endl;
    }

    setupOpengl(640, 480);

    SDL_Event event;
    bool b = true;
    while (b) {
    res = SDL_PollEvent(&event);
    if (res) {
    switch (event.type) {
    case SDL_KEYDOWN:
    cout << "key down event" << endl;
    break;
    case SDL_KEYUP:
    cout << "key up event" << endl;
    break;
    case SDL_MOUSEMOTION:
    cout << "mouse motion event" << endl;
    break;
    case SDL_MOUSEBUTTONDOWN:
    cout << "mouse button down event" << endl;
    break;
    case SDL_MOUSEBUTTONUP:
    cout << "mouse button up event" << endl;
    break;
    case SDL_QUIT:
    cout << "quit event" << endl;
    b = false;
    break;
    }
    }
    drawScreen();
    SDL_Delay(40);
    }

    SDL_Quit();
    /* mos */
    //CloseLibrary(PowerSDLBase);
    //CloseLibrary(PowerSDLGfxBase);

    cout << "end!" << endl;
    return 0;
    }


    and compile it: g++ -std=c++11 -noixemul -o test_sdl test_sdl_mos.cpp -lm -lSDL

    Sadly I did find a proper way to compile it using sdl dynamically
    regards
    eliot

    www.exception-dev.de
  • »08.02.17 - 13:35
    Profile Visit Website
  • MorphOS Developer
    Henes
    Posts: 492 from 2003/6/14
    Developer/usr/local should be copied to /gg/usr/local

    If you installed the libSDL.a file coming with the PowerSDL SDK... then -lSDL will make you use the shared library ;-)
    In fact, libSDL.a is full of simple stubs using the shared library.
    Also, you don't really need to open the library yourself. The libSDL.a code does it for you.

    Then try to rename powersdl.library, flush it (or just reboot) and start your application again...
    It should whine about the missing powersdl.library
  • »08.02.17 - 13:49
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    eliot
    Posts: 457 from 2004/4/15
    Thx Henes for your quick answer.
    Than I have done all right, nice :)

    Here is a Snoopium.log of opnening the SDL test application:
    Code:

    [1] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [2] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [3] [ramlib] [Load] [MOSSYS:LIBS/powersdl.library.elf] [] [Fehlgeschlagen]
    [4] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library] [Lesen] [Fehlgeschlagen]
    [5] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library] [Lesen] [Fehlgeschlagen]
    [6] [ramlib] [Load] [MOSSYS:LIBS/powersdl.library] [] [Fehlgeschlagen]
    [7] [ramlib] [Open] [LIBS:powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [8] [ramlib] [Open] [LIBS:powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [9] [ramlib] [Load] [LIBS:powersdl.library.elf] [] [Fehlgeschlagen]
    [10] [ramlib] [Open] [powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [11] [ramlib] [Open] [powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [12] [ramlib] [Load] [powersdl.library.elf] [] [Fehlgeschlagen]
    [13] [test_sdl] [Open] [PROGDIR:Catalogs/deutsch/PowerSDL.catalog] [Lesen] [Fehlgeschlagen]
    [14] [test_sdl] [Open] [MOSSYS:LOCALE/Catalogs/deutsch/PowerSDL.catalog] [Lesen] [Fehlgeschlagen]
    [15] [test_sdl] [Open] [LOCALE:Catalogs/deutsch/PowerSDL.catalog] [Lesen] [Fehlgeschlagen]
    [16] [ramlib] [Open] [MOSSYS:LIBS/tinygl.library.elf] [Lesen] [Fehlgeschlagen]
    [17] [ramlib] [Open] [MOSSYS:LIBS/tinygl.library.elf] [Lesen] [Fehlgeschlagen]
    [18] [ramlib] [Load] [MOSSYS:LIBS/tinygl.library.elf] [] [Fehlgeschlagen]
    [19] [test_sdl] [Open] [TGLDEBUG] [Lesen] [Fehlgeschlagen]
    [20] [test_sdl] [Open] [TGLNOMIP] [Lesen] [Fehlgeschlagen]
    [21] [test_sdl] [Open] [TGLLOWQTEXTURES] [Lesen] [Fehlgeschlagen]
    [22] [test_sdl] [Open] [TGLSYNC] [Lesen] [Fehlgeschlagen]
    [23] [test_sdl] [Open] [SDL_VIDEO_CENTERED] [Lesen] [Fehlgeschlagen]
    [24] [Shell Process] [Open] [shellppc.prefs] [Lesen] [Fehlgeschlagen]


    What I do not understand: why do all these system calls fail (Fehlgeschlagen) but the test_sdl binrary is running well?


    EDIT:
    Ok, Snoppium just shows failed system calls at default.
    This settings can be found in Funtions, not as I expected in Settings.
    This looks much better:
    Code:

    [4] [Shell Process] [ChangeDir] [Work:tmp] [] []
    [5] [Shell Process] [Open] [test_sdl] [Lesen] [Ok]
    [6] [Shell Process] [Load] [test_sdl] [] [Ok]
    [7] [Shell Process] [Open] [test_sdl] [Lesen] [Ok]
    [8] [Shell Process] [ChangeDir] [Work:tmp] [] []
    [9] [ramlib] [Load] [MOSSYS:LIBS/powersdl.library.elf] [] [Fehlgeschlagen]
    [10] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [11] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [12] [ramlib] [Load] [MOSSYS:LIBS/powersdl.library] [] [Fehlgeschlagen]
    [13] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library] [Lesen] [Fehlgeschlagen]
    [14] [ramlib] [Open] [MOSSYS:LIBS/powersdl.library] [Lesen] [Fehlgeschlagen]
    [15] [ramlib] [Load] [LIBS:powersdl.library.elf] [] [Fehlgeschlagen]
    [16] [ramlib] [Open] [LIBS:powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [17] [ramlib] [Open] [LIBS:powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [18] [ramlib] [Load] [powersdl.library.elf] [] [Fehlgeschlagen]
    [19] [ramlib] [Open] [powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [20] [ramlib] [Open] [powersdl.library.elf] [Lesen] [Fehlgeschlagen]
    [21] [ramlib] [Load] [LIBS:powersdl.library] [] [Ok]
    [22] [ramlib] [Open] [LIBS:powersdl.library] [Lesen] [Ok]
    [23] [test_sdl] [Open] [NIL:] [Lesen] [Ok]
    [24] [test_sdl] [Open] [NIL:] [Schreiben] [Ok]
    [25] [test_sdl] [Open] [NIL:] [Lesen] [Ok]
    [26] [test_sdl] [Open] [NIL:] [Schreiben] [Ok]
    [27] [test_sdl] [ChangeDir] [Ram Disk:ENV] [] []
    [28] [test_sdl] [Open] [SDL_CGX_PREFERENCES] [Lesen] [Ok]
    [29] [test_sdl] [ChangeDir] [Work:tmp] [] []
    [30] [test_sdl] [Open] [PROGDIR:Catalogs/deutsch/PowerSDL.catalog] [Lesen] [Fehlgeschlagen]
    [31] [test_sdl] [Open] [MOSSYS:LOCALE/Catalogs/deutsch/PowerSDL.catalog] [Lesen] [Fehlgeschlagen]
    [32] [test_sdl] [Open] [LOCALE:Catalogs/deutsch/PowerSDL.catalog] [Lesen] [Fehlgeschlagen]
    [33] [test_sdl] [ChangeDir] [Work:tmp] [] []
    [34] [ramlib] [Load] [MOSSYS:LIBS/tinygl.library.elf] [] [Fehlgeschlagen]
    [35] [ramlib] [Open] [MOSSYS:LIBS/tinygl.library.elf] [Lesen] [Fehlgeschlagen]
    [36] [ramlib] [Open] [MOSSYS:LIBS/tinygl.library.elf] [Lesen] [Fehlgeschlagen]
    [37] [ramlib] [Load] [MOSSYS:LIBS/tinygl.library] [] [Ok]
    [38] [ramlib] [Open] [MOSSYS:LIBS/tinygl.library] [Lesen] [Ok]
    [39] [test_sdl] [ChangeDir] [System:MorphOS/Libs/tinygl] [] []
    [40] [test_sdl] [Load] [System:MorphOS/Libs/tinygl/r200.library] [] [Ok]
    [41] [test_sdl] [Open] [System:MorphOS/Libs/tinygl/r200.library] [Lesen] [Ok]
    [42] [test_sdl] [Load] [System:MorphOS/Libs/tinygl/r300.library] [] [Ok]
    [43] [test_sdl] [Open] [System:MorphOS/Libs/tinygl/r300.library] [Lesen] [Ok]
    [44] [test_sdl] [ChangeDir] [Work:tmp] [] []
    [45] [test_sdl] [ChangeDir] [Ram Disk:ENV] [] []
    [46] [test_sdl] [Open] [TGLDEBUG] [Lesen] [Fehlgeschlagen]
    [47] [test_sdl] [ChangeDir] [Work:tmp] [] []
    [48] [test_sdl] [ChangeDir] [Ram Disk:ENV] [] []
    [49] [test_sdl] [Open] [TGLNOMIP] [Lesen] [Fehlgeschlagen]
    [50] [test_sdl] [ChangeDir] [Work:tmp] [] []
    [51] [test_sdl] [ChangeDir] [Ram Disk:ENV] [] []
    [52] [test_sdl] [Open] [TGLLOWQTEXTURES] [Lesen] [Fehlgeschlagen]
    [53] [test_sdl] [ChangeDir] [Work:tmp] [] []
    [54] [test_sdl] [ChangeDir] [Ram Disk:ENV] [] []
    [55] [test_sdl] [Open] [TGLSYNC] [Lesen] [Fehlgeschlagen]
    [56] [test_sdl] [ChangeDir] [Work:tmp] [] []
    [57] [test_sdl] [LockScreen] [Workbench] [] [Ok]
    [58] [test_sdl] [LockScreen] [Workbench] [] [Ok]
    [59] [test_sdl] [ChangeDir] [Ram Disk:ENV] [] []
    [60] [test_sdl] [Open] [SDL_VIDEO_CENTERED] [Lesen] [Fehlgeschlagen]
    [61] [test_sdl] [ChangeDir] [Work:tmp] [] []




    [ Edited by eliot 09.02.2017 - 06:14 ]
    regards
    eliot

    www.exception-dev.de
  • »09.02.17 - 07:03
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    eliot
    Posts: 457 from 2004/4/15
    Just for completeness, here is a better example to handle the input events:
    Code:

    #define GL_GLEXT_PROTOTYPES

    #ifdef __APPLE__

    #include <gl.h>
    #include <glu.h>

    #else

    #include <GL/gl.h>
    #include <GL/glu.h>

    #endif

    #include <iostream>
    #include <SDL/SDL.h>

    using namespace std;

    static void setupOpenGl(int width, int height) {
    const float ratio = (float) width / (float) height;

    glShadeModel(GL_SMOOTH);

    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glEnable(GL_CULL_FACE);

    glClearColor(0, 0, 0, 0);

    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, ratio, 1.0, 1024.0);
    }

    static void drawScreen() {
    static float angle = 0.0f;

    static GLfloat v0[] = {-1.0f, -1.0f, 1.0f};
    static GLfloat v1[] = {1.0f, -1.0f, 1.0f};
    static GLfloat v2[] = {1.0f, 1.0f, 1.0f};
    static GLfloat v3[] = {-1.0f, 1.0f, 1.0f};
    static GLfloat v4[] = {-1.0f, -1.0f, -1.0f};
    static GLfloat v5[] = {1.0f, -1.0f, -1.0f};
    static GLfloat v6[] = {1.0f, 1.0f, -1.0f};
    static GLfloat v7[] = {-1.0f, 1.0f, -1.0f};
    static GLubyte red[] = {255, 0, 0, 255};
    static GLubyte green[] = {0, 255, 0, 255};
    static GLubyte blue[] = {0, 0, 255, 255};
    static GLubyte white[] = {255, 255, 255, 255};
    static GLubyte yellow[] = {0, 255, 255, 255};
    static GLubyte black[] = {0, 0, 0, 255};
    static GLubyte orange[] = {255, 255, 0, 255};
    static GLubyte purple[] = {255, 0, 255, 0};

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0.0, 0.0, -5.0);

    glRotatef(angle, 0.0, 1.0, 0.0);

    if (++angle > 360.0f) {
    angle = 0.0f;
    }

    glBegin(GL_TRIANGLES);

    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(blue);
    glVertex3fv(v2);

    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(blue);
    glVertex3fv(v2);
    glColor4ubv(white);
    glVertex3fv(v3);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(black);
    glVertex3fv(v5);
    glColor4ubv(orange);
    glVertex3fv(v6);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(orange);
    glVertex3fv(v6);
    glColor4ubv(blue);
    glVertex3fv(v2);

    glColor4ubv(black);
    glVertex3fv(v5);
    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(purple);
    glVertex3fv(v7);

    glColor4ubv(black);
    glVertex3fv(v5);
    glColor4ubv(purple);
    glVertex3fv(v7);
    glColor4ubv(orange);
    glVertex3fv(v6);

    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(white);
    glVertex3fv(v3);

    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(white);
    glVertex3fv(v3);
    glColor4ubv(purple);
    glVertex3fv(v7);

    glColor4ubv(white);
    glVertex3fv(v3);
    glColor4ubv(blue);
    glVertex3fv(v2);
    glColor4ubv(orange);
    glVertex3fv(v6);

    glColor4ubv(white);
    glVertex3fv(v3);
    glColor4ubv(orange);
    glVertex3fv(v6);
    glColor4ubv(purple);
    glVertex3fv(v7);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(red);
    glVertex3fv(v0);
    glColor4ubv(yellow);
    glVertex3fv(v4);

    glColor4ubv(green);
    glVertex3fv(v1);
    glColor4ubv(yellow);
    glVertex3fv(v4);
    glColor4ubv(black);
    glVertex3fv(v5);

    glEnd();

    SDL_GL_SwapBuffers();
    }

    int main(int argc, char *argv[]) {
    cout << "begin ..." << endl;

    int res = SDL_Init(SDL_INIT_VIDEO);
    if (res) {
    cout << "could not init sdl, result=" << res << ", error=" << SDL_GetError() << endl;
    return -1;
    }

    SDL_Surface *screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
    if (screen == nullptr) {
    cout << "could set display mode, error=" << SDL_GetError() << endl;
    return -2;
    }
    SDL_WM_SetCaption("sdl_test", nullptr);
    setupOpenGl(640, 480);

    SDL_Event events[16];
    bool b = true;
    while (b) {
    SDL_PumpEvents();
    res = SDL_PeepEvents(events, 16, SDL_GETEVENT,
    SDL_KEYDOWNMASK |
    SDL_KEYUPMASK |
    SDL_MOUSEMOTIONMASK |
    SDL_MOUSEBUTTONDOWNMASK |
    SDL_MOUSEBUTTONUPMASK |
    SDL_QUITMASK);
    for (int i = 0; i < res; ++i) {
    switch (events[i].type) {
    case SDL_KEYDOWN:
    cout << "key down event" << endl;
    break;
    case SDL_KEYUP:
    cout << "key up event" << endl;
    break;
    case SDL_MOUSEMOTION:
    cout << "mouse motion event, x=" << events[i].motion.x << ", y=" << events[i].motion.y << endl;
    break;
    case SDL_MOUSEBUTTONDOWN:
    cout << "mouse button down event" << endl;
    break;
    case SDL_MOUSEBUTTONUP:
    cout << "mouse button up event" << endl;
    break;
    case SDL_QUIT:
    cout << "quit event" << endl;
    b = false;
    break;
    }
    }
    drawScreen();
    SDL_Delay(40);
    }

    SDL_Quit();
    cout << "end!" << endl;
    return 0;
    }
    regards
    eliot

    www.exception-dev.de
  • »09.02.17 - 13:19
    Profile Visit Website
  • MorphOS Developer
    geit
    Posts: 885 from 2004/9/23
    The errors you see are normal. Libraries are sinply searched all over the place and for historical (and compatilby) reasons with ".elf" extension. Of course those calls fail until the right one was found.

    The last errors are tries to load ENV: variabled. When unset, they fail. Again, quite normal.
  • »09.02.17 - 13:23
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    eliot
    Posts: 457 from 2004/4/15
    Quote:

    geit wrote:

    The errors you see are normal. Libraries are sinply searched all over the place and for historical (and compatilby) reasons with ".elf" extension. Of course those calls fail until the right one was found.

    The last errors are tries to load ENV: variabled. When unset, they fail. Again, quite normal.


    Yes, I just wondered why did not see any successful calls but the binary runs perfectly.
    My snoopium was wrongly configured (successful calls were not logged).
    The failed calls are absolutely ok and explainable.
    regards
    eliot

    www.exception-dev.de
  • »09.02.17 - 13:39
    Profile Visit Website