Question

I'm developing on a Linux machine using TeleUSE. I PuTTY to the machine to do my work. I have X11 forwarding on and Xming running. I can't seem to see the OpenGL part of the window if I'm running remotely, HOWEVER the great demo "glxgears" works great & is visible. The only thing I can think is I'm trying to run OpenGL via a glwMDrawingAreaWidgetClass, whereas glxgears is a new window?

Here's some of the code (the OpenGL part)

#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 is called by a XmFrame widget once it's been created

Was it helpful?

Solution

Ha ha! Oh I'm so lame. Okay, it works now. I just had to use "Xming-mesa" instead of Xming. Doh!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top