Computer Science Ilab OpenGL Support

The computer science instructional cluster supports programming using OpenGL. However there are some things to note about it.

There are two main ways to use it: sitting at a desktop in Hill Center, or from home or another remote location.

Desktop Our desktop systems Ubuntu 18.04. They have OpenGL-capable graphics cards and support OpenGL 3.3.

Home To use OpenGL from home, you must use Microsoft Remote Desktop. This is available for Windows, Macs and Linux and connect to iLab machines.

iLab desktop systems have a decent performance graphics systems, but they do not have the same performance as a gaming system. The desktops use what is now a mid to low-end graphics controller.

Remote Desktop

We normally recommend connecting to our systems with X2Go. However that won't work for OpenGL. To use OpenGL, you will have to connect using Microsoft Remote Desktop. see Windows Remote Desktop how to.

By default, you will have the Gnome desktop. If you run into issues, e.g. panels not displaying, you may want to shift to an older desktop. To do that, create a file in your home directory called ".xsession". Note the period at the beginning. It should have one line, either "mate-session" or "xfce4-session", depending upon which window manager you prefer.

About OpenGL versions

OpenGL changed how versions work at version 3.2. Until 3.2, new versions added features, but nothing was removed. Starting with 3.2. some old features were removed, a few functions were renamed, and other changes were made. To avoid breaking old programs, two "profiles" were created, compatibility profile and core profile. Compatibility profile behaves like previous versions. It is the default. Core profile gives you the new behavior.

People learning OpenGL now should start learning the Core Profile.

OpenGL programs typically begin by declaring what version they depend upon. If your hardware doesn't support that version, the program will fail to start. This is generally better than having it fail in odd ways because you're used a feature that the hardware doesn't support. The software will also take account of the version you intend to be using. Here's an example of code that uses the minimum Core Profile:

  glfwInit();
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
  glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);

  GLFWwindow *window=glfwCreateWindow(800,600,"Learn OpenGL",nullptr,nullptr);
Note that it says it uses version 3.3, and the Core Profile. Of course it will work on higher versions of OpenGL, but not lower ones. Programs like this should work on Rutgers Computer Science desktops and when using Remote Desktop. Higher versions will work if you are sitting at the desktops, but not using Remote Desktop.

Test program

Here's a more complete version of the test program given above. This is a minimum useful OpenGL program, simply to verify that everything is working

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>

void key_callback(GLFWwindow* window,int key,int scancode,int action,int mode)
{
  if(key==GLFW_KEY_ESCAPE && action==GLFW_PRESS)
    glfwSetWindowShouldClose(window,GL_TRUE);
}

int main()
{
  glfwInit();
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
  glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
  glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);

  GLFWwindow *window=glfwCreateWindow(800,600,"Learn OpenGL",nullptr,nullptr);
  if(window==nullptr)
    {
      std::cout<<"Failed to create GLFW window!"<<std::endl;
      glfwTerminate();
      return -1;
    }
  glfwMakeContextCurrent(window);

  glewExperimental=GL_TRUE;
  if(glewInit()!=GLEW_OK)
    {
      std::cout<<"Failed to initialize GLEW!"<<std::endl;
      return -1;
    }

  int width,height;
  glfwGetFramebufferSize(window,&width,&height);
  glViewport(0,0,width,height);

  glfwSetKeyCallback(window,key_callback);

  while(!glfwWindowShouldClose(window))
    {
      glfwPollEvents();

      glClearColor(.2f,.3f,.3f,1.f);
      glClear(GL_COLOR_BUFFER_BIT);

      glfwSwapBuffers(window);
    }
  glfwTerminate();

  return 0;
}
Put that into a file main.cpp. To build it:
g++ -O3 main.cpp -o window -lGLEW -lglfw -lGL -lX11 -lpthread -lXrandr -ldl -lXxf86vm -lXinerama -lXcursor -lrt -lm -std=c++11
Run it using
./window
That's because the "-o window" says to put the executable in "window". When you run it, it should open a window that is solid gray. If you click inside the window and hit the ESC key on your keyboard, it should exit.