glwMDrawingAreaWidgetClass通过X11转发可见吗?

时间:2013-06-08 01:35:56

标签: opengl glx x11-forwarding

我正在使用TeleUSE在Linux机器上开发。我腻到机器做我的工作。我有X11转发和Xming运行。如果我正在远程运行,我似乎无法看到窗口中的OpenGL部分,但是伟大的演示“glxgears”非常有用。是可见的。我唯一能想到的是我试图通过glwMDrawingAreaWidgetClass运行OpenGL,而glxgears是一个新窗口?

这是一些代码(OpenGL部分)

#include <teleuse/tu_runtime.h>
#include <stdbool.h>
#include <GL/GLwMDrawA.h>

void expose_callback(Widget w, XtPointer clientData, XtPointer callData)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(1.0, 0.0, 0.0);
    glRectf(-0.5, -0.5, 0.5, 0.5);
    glColor3f(0.0, 1.0, 0.0);
    glRectf(-0.4, -0.4, 0.4, 0.4);
    glColor3f(0.0, 0.0, 1.0);
    glRectf(-0.3, -0.3, 0.3, 0.3);

    glXSwapBuffers(XtDisplay(w), XtWindow(w));
}

void resize_callback(Widget w, XtPointer clientData, XtPointer callData)
{
    GLwDrawingAreaCallbackStruct    *cbs = (GLwDrawingAreaCallbackStruct *) callData;

    glViewport(0, 0, cbs->width, cbs->height);
}

void make_my_widget(Widget w) {
    XVisualInfo *visinfo;
    Display *dpy;
    int attrib[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_DEPTH_SIZE, 1, None};
    Widget  glw;
    GLXContext  ctx;

    dpy = XtDisplay(w);
    visinfo = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);
    if (visinfo == NULL) {
        printf("glXChooseVisual failed\n");
        return;
    }

    int n;
    Arg args[20];
    n = 0;
    XtSetArg(args[n], GLwNvisualInfo, visinfo);
    n++;
    XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
    n++;
    XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
    n++;
    XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
    n++;
    XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
    n++;
    XtSetArg(args[n], XmNleftOffset, 10);
    n++;
    XtSetArg(args[n], XmNrightOffset, 10);
    n++;
    XtSetArg(args[n], XmNtopOffset, 10);
    n++;
    XtSetArg(args[n], XmNbottomOffset, 10);
    n++;

    glw = XtCreateWidget("glw", glwMDrawingAreaWidgetClass, w, args, n);
    XtAddCallback(glw, GLwNresizeCallback, resize_callback, 0);
    XtAddCallback(glw, GLwNexposeCallback, expose_callback, 0);
    XtManageChild(glw);

    ctx = glXCreateContext(XtDisplay(glw), visinfo, NULL, True);
    if (ctx == NULL) {
        printf("glXCreateContext failed\n");
        return;
    }
    XFree(visinfo);

    if (glXMakeCurrent(XtDisplay(glw), XtWindow(glw), ctx) == false) {
        printf("glXMakeCurrent failed\n");
        return;
    }
}

make_my_widget在创建后由XmFrame小部件调用

1 个答案:

答案 0 :(得分:0)

哈哈!哦,我太蹩脚了。好的,它现在有效。我只需要使用“Xming-mesa”而不是Xming。卫生署!