Exemplo n.º 1
0
GLWTWindow *glwtWindowCreate(
    const char *title,
    int width, int height,
    GLWTWindow *share,
    void (*win_callback)(GLWTWindow *window, const GLWTWindowEvent *event, void *userdata),
    void *userdata)
{
    GLWTWindow *win = calloc(1, sizeof(GLWTWindow));
    if(!win)
        return 0;

    win->win_callback = win_callback;
    win->userdata = userdata;

    XSetWindowAttributes attrib;
    attrib.colormap = glwt.x11.colormap;
    attrib.event_mask = 0
                        | StructureNotifyMask
                        | PointerMotionMask
                        | ButtonPressMask
                        | ButtonReleaseMask
                        | KeyPressMask
                        | KeyReleaseMask
                        | EnterWindowMask
                        | LeaveWindowMask
                        | FocusChangeMask
                        | ExposureMask;
    unsigned long attrib_mask = CWColormap | CWEventMask;

    win->x11.window = XCreateWindow(
                          glwt.x11.display,
                          RootWindow(glwt.x11.display, glwt.x11.screen_num),
                          0, 0, width, height,
                          0,
                          glwt.x11.depth,
                          InputOutput,
                          glwt.x11.visual,
                          attrib_mask,
                          &attrib);

    Atom protocols[] = {
        glwt.x11.atoms.WM_DELETE_WINDOW,
        glwt.x11.atoms._NET_WM_PING,
    };
    int num_protocols = sizeof(protocols)/sizeof(*protocols);
    if(XSetWMProtocols(glwt.x11.display, win->x11.window, protocols, num_protocols) == 0)
    {
        glwtErrorPrintf("XSetWMProtocols failed");
        goto error;
    }

#ifdef GLWT_USE_EGL
    if(glwtWindowCreateEGL(win, share, win->x11.window) != 0)
#else
    if(glwtWindowCreateGLX(win, share) != 0)
#endif
        goto error;

    if(XSaveContext(glwt.x11.display, win->x11.window, glwt.x11.xcontext, (XPointer)win) != 0)
    {
        glwtErrorPrintf("XSaveContext failed");
        goto error;
    }

    glwtWindowSetTitle(win, title);

    return win;
error:
    glwtWindowDestroy(win);
    return 0;
}
Exemplo n.º 2
0
GLWTWindow *glwtWindowCreate(
    const char *title,
    int width, int height,
    GLWTWindow *share,
    void (*win_callback)(GLWTWindow *window, const GLWTWindowEvent *event, void *userdata),
    void *userdata)
{
    (void)title;

    GLWTWindow *win = calloc(1, sizeof(GLWTWindow));
    if(!win)
        return 0;

    win->win_callback = win_callback;
    win->userdata = userdata;

    DISPMANX_UPDATE_HANDLE_T dispman_update;
    VC_RECT_T dst_rect;
    VC_RECT_T src_rect;

    dst_rect.x = 0;
    dst_rect.y = 0;
    dst_rect.width = glwt.rpi.width;
    dst_rect.height = glwt.rpi.height;

    width = glwt.rpi.width;
    height = glwt.rpi.height;

    src_rect.x = 0;
    src_rect.y = 0;
    src_rect.width = width << 16;
    src_rect.height = height << 16;

    dispman_update = vc_dispmanx_update_start( 0 );

    VC_DISPMANX_ALPHA_T alpha_flags;
    alpha_flags.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
    alpha_flags.opacity = 255;
    alpha_flags.mask = 0;

    win->rpi.nativewindow.element = vc_dispmanx_element_add(
        dispman_update,
        glwt.rpi.dispman_display,
        0 /*layer*/,
        &dst_rect,
        0 /*src*/,
        &src_rect,
        DISPMANX_PROTECTION_NONE,
        &alpha_flags /*alpha*/,
        0 /*clamp*/,
        (DISPMANX_TRANSFORM_T)0 /*transform*/);

    win->rpi.nativewindow.width = width;
    win->rpi.nativewindow.height = height;
    vc_dispmanx_update_submit_sync( dispman_update );

    if(glwtWindowCreateEGL(win, share, &win->rpi.nativewindow) != 0)
        goto error;

    return win;
error:
    glwtWindowDestroy(win);
    return 0;
}