0

I am trying to make a opengl context with glx on a debian server. The problem is that I can't make the display and it seems the reason is because there is no X server running and I cannot start an X server with sudo startx because it says there are no screens.

The server is offsite and there is no way of adding a display onto it and I need to make an opengl application that can run on it and render things and some stuff.

This is my current c++ test code:

#include <cstdio>
#include <X11/Xutil.h>
#include <GL/gl.h>
#include <GL/glx.h>

typedef GLXContext (*glXCreateContextAttribsARBProc) (Display*, GLXFBConfig, GLXContext, Bool, const int*);
typedef Bool (*glXMakeContextCurrentARBProc) (Display*, GLXDrawable, GLXDrawable, GLXContext);
static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = NULL;
static glxMakeContextCurrentARBProc glxMakeContextCurrentARB = NULL;

int main(){
    printf("tacos\n");
    glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB((const GLubyte*) "glXCreateContextAttribsARB");
    glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc) glXGetProcAddressARB((const GLubyte*) "glXMakeContextCurrent");

    [ ... ] // Check if the two funcs are null, they are not when I run the program.

    const char* display_name = NULL;
    Display* display = XOpenDisplay(display_name);
    if (display == NULL){
        printf("failed to open display\n"); // outputs this and ends program
        return 0;
    }

    printf("Great Success\n"); // does not get this far ^
    return 0;
}

I check if X Server is running with this:

if ! xset q &>/dev/null; then
    echo "No X server at \$DISPLAY [$DISPLAY]" >&2;
fi

Which outputs the following:

No X server at $DISPLAY []

Which leads me to think the $DISPLAY var is not set, though I don't know how to check if it is set.

I then ran 'sudo startx' and got the following:

Fatal server error:
(EE) no screens found(EE)
MichaelMitchell
  • 1,069
  • 2
  • 13
  • 38

1 Answers1

2

Well, GLX is the X11 OpenGL transport protocol. So you absolutely need an X server running (do you have a GPU at the off-site location available?).

The later versions of the Xorg server in the default configuration will refuse to start if no monitors are connected. However using the right xorg.conf placed in /etc/X11 and with the right command line options you can coax the server into starting even then. However you will either have to start a redirecting composite manager or rewrite your OpenGL programs to use a Framebuffer Objects, otherwise you'll not get a framebuffer to draw to (I highly recommend going the Framebuffer Object route).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • I am sorry, I am very new to linux could you please link to some pages that could give further information? There is an integrated GPU, but not a dedicated one. – MichaelMitchell Jan 31 '15 at 18:59
  • @MichaelMitchell: Which kind of GPU exactly? Could please post the output of `lspci` into a pastebin or similar (you probably have to run lspci as superuser (sudo lspci)). – datenwolf Jan 31 '15 at 22:42
  • There is nothing in the PCIs. There is an integrated intel gpu. – MichaelMitchell Feb 01 '15 at 00:13
  • @MichaelMitchell: That integrated Intel GPU is accessed via PCI. Heck even the memory controllers of modern Intel CPU show up ad PCI devices. Just do it already and report the results. – datenwolf Feb 01 '15 at 13:39
  • I ran `sudo lspci` no results, as in no output at all. I then ran `sudo lspci -vv`, again nothing. And finally I did `sudo lspci -m` and that just output something like `[000:000]` – MichaelMitchell Feb 01 '15 at 16:31
  • @MichaelMitchell: either you're running in a virtualized environment, which case you don't have a GPU at all, or something in your installation is broken. Anyway, if there's no physical GPU available (CPU integrated or not), you'll have to resort to software implementations of OpenGL. Which would be Mesa llvm/softpipe. If you go that route, then you don't have to bother with X11/GLX at all and instead should use OSMesa (offscreen Mesa) that gives you OpenGL routines operating on a memory region you offer to it. – datenwolf Feb 01 '15 at 18:32
  • I did some research into the virtual frame buffer objects like you suggested and I found `Xvfb` which allows essentially a virtual display. After installing that I was able to run my program in a similar manner to what is described in this post http://stackoverflow.com/questions/6281998/can-i-run-glu-opengl-on-a-headless-server If you want to add that to your answer I will do the green check mark thing. – MichaelMitchell Feb 01 '15 at 18:35
  • @MichaelMitchell: Actually I was not referring to Xvfb, but to OpenGL FBOs (https://www.opengl.org/wiki/Framebuffer_Object), which are required if you want to leverage an actual GPU in the system in a off-screen rendering setting. Using Xvfb will inevitably drop you into Mesa's softpipe mode, but you can use that with OSMesa as well (http://www.mesa3d.org/osmesa.html) saving you the need for a running X server. – datenwolf Feb 01 '15 at 20:08