   glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
   glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
 
-  win = glfwCreateWindow(1280, 720, "Marching cubes test application", nullptr, nullptr);
-  glfwSetKeyCallback(win, onKey);
-  glfwMakeContextCurrent(win);
-  gladLoadGL(glfwGetProcAddress);
+  GLFWwindow* win = nullptr;
+  GLuint shadedProg = 0;
+  GLuint solidProg = 0;
+  initWindowAndGL(win, shadedProg, solidProg);
 
   unsigned int deviceCount;
   CHECKED_CUDA(cudaGLGetDevices(&deviceCount, nullptr, 0, cudaGLDeviceListAll));



    if (wireframe) {
      glUseProgram(solidPrg);
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glUniformMatrix4fv(0, 1, GL_FALSE, normal_matrix);
      glUniformMatrix4fv(1, 1, GL_FALSE, modelview_projection);

int main(int argc, char** argv)
{
  cudaStream_t stream;
  const char* path = nullptr;
  int deviceIndex = 0;
  bool benchmark = false;

  for (int i = 1; i < argc; i++) {
    if (i + 1 < argc && (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0)) { deviceIndex = std::atoi(argv[i + 1]); i++; }
