Ubuntu – code opengl through SSH, run program though machine’s display

openglsshUbuntu

I am working through the Opengl Bible 5th edition. Due to a recent hardware failure my primary machine is now an old laptop that does not support the opengl standard for my tutorial book. I have a headless server running Ubuntu 11.10 which has a capable graphics card.
I would like to code though SSH and have my compiled program display on a monitor attached to the server. How would I go about doing this?

Best Answer

You did not specify too much about your environment, so let's go one by one. First, if you were running Ubuntu (or any GNU/Linux for that matter) on your previous machine, you are most likely using X Windows for display in your OpenGL applications. Given that assumption, all you need is a working X Windows server on your "headless" server (note that when you attach a monitor, it's not headless anymore). If you don't have it installed (which would be the case if you installed Ubuntu Server edition, for example), you need to install it first, check this:

Note that it's not advisable to install X (or anything not necessary) on pure-servers for various reasons, see Arguments Against a GUI section in the above link to see some of them and decide whether it's something you want to do or not.

When you have that installed (which you can check e.g. by running dpkg -s xserver-xorg-code in terminal and checking Status line) and fired it up, you can test it by launching e.g. xeyes or other sample X applications. First, make sure you have DISPLAY environment variable set:

$ echo $DISPLAY
:0.0

From this:

you can see that this variable has the following format:

hostname:displaynumber.screennumber

with hostname omitted above meaning localhost. If this works (e.g. running xeyes actually displays those funny eyes that track your mouse), you are all set X-wise.

If you don't have a SSH server installed, you need to install it - it's fairly simple, here's one of many tutorials:

Check that your ssh is working by running ssh <target IP> from your laptop, e.g.:

$ ssh 10.0.0.5

if your server's IP is 10.0.0.5. If that succeeds, you are all set.

Now that you can SSH to the server, all you need to do is just run xeyes from within SSH connection. It might be that your DISPLAY variable is not set when you ssh, so if echo $DISPLAY returns nothing, you can run this:

$ export DISPLAY=:0.0

provided you use bash, which is probably the case.

If, on the other hand, you want to run the app itself on the laptop and just display on the server, all you have to do is change the DISPLAY variable and it would work, e.g.:

$ export DISPLAY=10.0.0.5:0.0

providing that IP of your server is 10.0.0.5. You can try the above in terminal following by xeyes and you should again see those funny eyes displaying on your server's monitor.

Hope this helps.