Ejemplo n.º 1
0
Archivo: s52glx.c Proyecto: sduclos/S52
int main(int argc, char* argv[])
{
    (void)argc;
    (void)argv;

    Display     *dpy = _getXdis  ();
    XVisualInfo *vis = _getXvis  (dpy, _attr);
    Window       win = _setXwin  (dpy, vis);
    GLXContext   ctx = _getGLXctx(dpy, vis);

    // bind the rendering context to the window
    Bool ret = glXMakeCurrent(dpy, win, ctx);
    if (False == ret) {
        printf("ERROR: glXMakeCurrent() fail\n");
        exit(0);
    }

    {   // init S52 lib (Screen No 0)
#ifdef SET_SCREEN_SIZE
        int w      = 1280;
        int h      = 1024;
        int wmm    = 376;
        int hmm    = 307;
#else
        int h   = XDisplayHeight  (dpy, 0);
        int hmm = XDisplayHeightMM(dpy, 0);
        int w   = XDisplayWidth   (dpy, 0);
        int wmm = XDisplayWidthMM (dpy, 0);
#endif
        S52_init(w, h, wmm, hmm, NULL);
    }

    // differ from w/h
    S52_setViewPort(0, 0, WIDTH, HEIGHT);

    /* debug - use for timing rendering
    S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_SY);
    //S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_LS);
    S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_LC);
    S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_AC);
    S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_AP);
    S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_TX);
    //*/

    // load cell from s52.cfg
    S52_loadCell(NULL, NULL);

    { // main loop
        XEvent event;
        while (True) {
            do {
                XNextEvent(dpy, &event);
                switch (event.type) {
                case ConfigureNotify: break;
                //case GraphicsExpose:
                //    S52_setViewPort(0, 0, event.xconfigure.width, event.xconfigure.height); break;
                //case ...

                case KeyPress:
                case KeyRelease:
                    {
                        unsigned int keycode = ((XKeyEvent *)&event)->keycode;
                        unsigned int keysym  = XkbKeycodeToKeysym(dpy, keycode, 0, 1);

                        // ESC - quit
                        if (XK_Escape == keysym) {
                            goto exit;
                        }
                    }
                }
            } while (XPending(dpy));
            S52_draw();
            S52_drawLast();  // nothing to do

            glXSwapBuffers(dpy,  win);
        }
    }

exit:

    XKillClient(dpy, win);

    S52_done();

    return True;
}
Ejemplo n.º 2
0
static int      _s52_draw_cb    (gpointer user_data)
// return TRUE for the signal to be called again
{
    s52engine *engine = (s52engine*)user_data;

    //g_print("s52egl:_s52_draw_cb(): begin .. \n");

    if (NULL == engine) {
        g_print("_s52_draw_cb(): no engine ..\n");
        goto exit;
    }

    // wait for libS52 to init - no use to go further - bailout
    if (TRUE == engine->do_S52init) {
        g_print("s52egl:_s52_draw_cb(): re-starting .. waiting for S52_init() to finish\n");
        goto exit;
    }

    if ((NULL==engine->eglDisplay) || (EGL_NO_DISPLAY==engine->eglDisplay)) {
        g_print("_s52_draw_cb(): no display ..\n");
        goto exit;
    }

    // no draw at all, the window is not visible
    if ((FALSE==engine->do_S52draw) && (FALSE==engine->do_S52drawLast)) {
        //g_print("s52egl:_s52_draw_cb(): nothing to draw (do_S52draw & do_S52drawLast FALSE)\n");
        goto exit;
    }

#ifndef S52_USE_EGL
    _egl_beg(engine);
#endif

    // draw background
    if (TRUE == engine->do_S52draw) {
        if (TRUE == engine->do_S52setViewPort) {
            eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_WIDTH,  &engine->width);
            eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_HEIGHT, &engine->height);

            S52_setViewPort(0, 0, engine->width, engine->height);

            engine->do_S52setViewPort = FALSE;
        }

        S52_draw();
        engine->do_S52draw = FALSE;
    }

    // draw AIS
    if (TRUE == engine->do_S52drawLast) {

#ifdef USE_FAKE_AIS
        _s52_updTimeTag(engine);
#endif
        S52_drawLast();
    }

#ifndef S52_USE_EGL
    _egl_end(engine);
#endif


exit:

    // debug
    //g_print("s52egl:_s52_draw_cb(): end .. \n");

    return EGL_TRUE;
}
Ejemplo n.º 3
0
static int      _s52_draw_cb(GtkWidget *widget,
							 GdkEventExpose *event,
							 gpointer user_data)
// return TRUE for the signal to be called again
{
    (void)widget;
    (void)event;

    struct s52engine *engine = (struct s52engine*)user_data;
    //g_print("s52egl:_s52_draw_cb(): begin .. \n");

    /*
    GTimeVal now;  // 2 glong (at least 32 bits each - but amd64 !?
    g_get_current_time(&now);
    if (0 == (now.tv_sec - engine->timeLastDraw.tv_sec))
        goto exit;
    //*/

    if (NULL == engine) {
        g_print("_s52_draw_cb(): no engine ..\n");
        goto exit;
    }

    if ((NULL==engine->eglDisplay) || (EGL_NO_DISPLAY==engine->eglDisplay)) {
        g_print("_s52_draw_cb(): no display ..\n");
        goto exit;
    }

    // wait for libS52 to init - no use to go further - bailout
    if (TRUE == engine->state.do_S52init) {
        g_print("s52egl:_s52_draw_cb(): re-starting .. waiting for S52_init() to finish\n");
        goto exit;
    }

    // no draw at all, the window is not visible
    if ((FALSE==engine->do_S52draw) && (FALSE==engine->do_S52drawLast)) {
        //g_print("s52egl:_s52_draw_cb(): nothing to draw (do_S52draw & do_S52drawLast FALSE)\n");
        goto exit;
    }

#if !defined(S52_USE_EGL)
    _egl_beg(engine, "test");
#endif

    // draw background
    if (TRUE == engine->do_S52draw) {
        if (TRUE == engine->do_S52setViewPort) {
            eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_WIDTH,  &engine->width);
            eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_HEIGHT, &engine->height);

            S52_setViewPort(0, 0, engine->width, engine->height);

            engine->do_S52setViewPort = FALSE;
        }

        S52_draw();
        engine->do_S52draw = FALSE;
    }

    // draw AIS
    if (TRUE == engine->do_S52drawLast) {

#ifdef USE_FAKE_AIS
        _s52_updTimeTag(engine);
#endif
        S52_drawLast();
    }

#if !defined(S52_USE_EGL)
    _egl_end(engine);
#endif


exit:

    // debug
    //g_print("s52egl:_s52_draw_cb(): end .. \n");

    return EGL_TRUE;
}