You need to know the name of the display to which you wish to connect (it will probably be “:0”, i.e. display 0 on the host running the program), the display has to exist (i.e. an X server has to be running for that display), and you need permission to connect to the X server.
If the X server is running because the system started it automatically on boot, the system probably started a display manager (e.g. xdm, gdm, kdm) which displays a login dialog. If that’s the case, you’ll need to actually complete the login process before the display manager will give you the credentials which programs will need in order to connect to the X server.
If the X server isn’t running, you need to start it. That may need to be done from the root account.
If the system is meant to act as a “display server” (i.e. you’re only going to use it remotely), your best bet is to modify the boot process to start the X server directly, without running a display manager, and to just store the authentication credentials in the .Xauthority file in the home directory of the intended user (or start the X server with authentication disabled; if you do that, ensure that it only accepts connections from the local system, not from the network, and don’t do this on a multi-user system).
This is going to require reading some documentation. The boot sequence is different for each distribution, so I can’t give details; you’ll need to read the documentation for your particular distribution. The manual pages for X, Xserver and/or Xorg may help. As may the manual pages for xinit and/or startx and the startx script itself, if those are available for your distribution.
X authentication works via shared secrets. The X server is started with the -auth flag followed by the name of a file containing authentication tokens. A user is given access to an X server by storing the same tokens in the .Xauthority file in their home directory. When an X program connects to an X server that requires authentication, it obtains a token from that file (or the file specified by the XAUTHORITY environment variable, if set) and presents it to the X server. Thus, a client can only connect if it has read access to a file containing authentication tokens.
Normally this is handled by a display manager, which generates the tokens, starts the X server, and displays a login dialog. Upon successful login, it copies the tokens to the .Xauthority file for the logged-in user. If you aren’t using a display manager, you need to do this yourself. The authentication files can be manipulated using the xauth utility.
Ultimately, this is an X11 question rather than an OpenGL question. If you can get any X program to show up on the display, you shouldn’t have any particular problems with an OpenGL program (whether using GLFW, GLUT, GTK, Qt or whatever).