0

我正在使用 TeleUSE 在 Linux 机器上进行开发。我把 PuTTY 放到机器上来做我的工作。我有 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 小部件调用

4

1 回答 1

0

哈哈!哦,我好跛脚。好的,现在可以了。我只需要使用“Xming-mesa”而不是 Xming。嗬!

于 2013-06-13T22:54:14.280 回答