title: glxGetCurrentDisplay() is null (GLEW)
body: <p>I have just switched to linux mint and I am trying to get up and running with opengl on it. The problem is that the program has a segfault:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  #include "GL/glew.h"
  #include "GLFW/glfw3.h"
  
  int main(int, char*[])
  {
      GLFWwindow *window = nullptr;
  
      if(!glfwInit()) {
          std::cout &lt;&lt; "Failed glfw" &lt;&lt; std::endl;
          return -1;
      }
  
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
  
      window = glfwCreateWindow(1280, 720, "Hey there", nullptr, nullptr);    
  
      if(window == nullptr) {
          std::cout &lt;&lt; "Failed to create window" &lt;&lt; std::endl;
          glfwTerminate();
          return -1;  
      }
  
      glfwMakeContextCurrent(window);
  
      std::cout &lt;&lt; glGetString(GL_VERSION) &lt;&lt; std::endl;
  
      glewExperimental = GL_TRUE;
  
      if(glewInit() != GLEW_OK) {
          std::cout &lt;&lt; "glew failed" &lt;&lt; std::endl;
          return -1;
      }
  
      std::vector&lt;float&gt; positions = {
          -0.5f, -0.5f,
           0.0f,  0.5f,
           0.5f, -0.5f
      };
  
      unsigned int vao;
      glGenVertexArrays(1, &amp;vao);
      glBindVertexArray(vao);
  
      unsigned int vbo;
      glGenBuffers(1, &amp;vbo);
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      glBufferData(GL_ARRAY_BUFFER, positions.size() * sizeof(float), &amp;positions[0], GL_STATIC_DRAW); 
  
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), nullptr);
  
      glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  
      while(!glfwWindowShouldClose(window) &amp;&amp; glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS) {
          glClear(GL_COLOR_BUFFER_BIT);       
  
          glDrawArrays(GL_TRIANGLES, 0, positions.size() / 2);        
  
          glfwSwapBuffers(window);
          glfwPollEvents();
      }
  
      glfwTerminate();
  
      return 0;
  }
  </code></pre>
  
  <p>Running gdb on the executable led me to the conclusion that the context is not created properly:</p>
  
  <pre><code>3.3.0 NVIDIA 390.67
  
  Breakpoint 1, main () at /home/alex/Desktop/misc/opengltest/main.cpp:35
  35      if(glewInit() != GLEW_OK) {
  (gdb) step
  glewInit () at /home/alex/Desktop/misc/opengltest/glew-cmake/src/glew.c:18012
  18012     r = glewContextInit();
  (gdb) n
  18013     if ( r != 0 ) return r;
  (gdb) n
  18022     return glxewInit();
  (gdb) step
  glxewInit () at /home/alex/Desktop/misc/opengltest/glew-cmake/src/glew.c:17686
  17686   {
  (gdb) 
  17692     display = glXGetCurrentDisplay();
  (gdb) step
  
  Program received signal SIGSEGV, Segmentation fault.
  0x0000000000000000 in ?? ()
  </code></pre>
  
  <p>My gpu is an Nvidia Geforce GT630 and the driver:</p>
  
  <pre><code>glxinfo | grep "OpenGL version"
  OpenGL version string: 4.6.0 NVIDIA 390.67
  </code></pre>
  
  <p>I have searched numerous threads regarding context creation in opengl but I can't find anything that helps me. Note that the window is created, but right after that the 'Segmentation fault (core dumped)
  ' error appears.</p>
  
  <p>This is my CMakeLists.txt (GLFW examples run just fine):</p>
  
  <pre><code>cmake_minimum_required( VERSION 3.5 )
  
  project( OpenGLTest )
  
  find_package( OpenGL REQUIRED )
  
  include_directories( ${PROJECT_SOURCE_DIR}/glfw/include/ )
  
  add_subdirectory( ${PROJECT_SOURCE_DIR}/glfw/ )
  add_subdirectory( ${PROJECT_SOURCE_DIR}/glew-cmake/build/cmake )
  
  set( SRC_FILES ${PROJECT_SOURCE_DIR}/main.cpp )
  
  add_executable( ogltest ${SRC_FILES} )
  
  target_link_libraries( ogltest ${OPENGL_LIBRARIES} glew_s glfw )
  </code></pre>
  
  <p>So the question is: What causes this problem and what can I do about that?</p>
  
  <p>EDIT: I am not really used to gdb but is this the correct use of bt command?</p>
  
  <pre><code>(gdb) n
  35      if(glewInit() != GLEW_OK) {
  (gdb) n
  
  Program received signal SIGSEGV, Segmentation fault.
  0x0000000000000000 in ?? ()
  (gdb) bt 4
  #0  0x0000000000000000 in ?? ()
  #1  0x00000000004291f3 in glxewInit () at /home/alex/Desktop/misc/opengltest/glew-cmake/src/glew.c:17692
  #2  0x000000000042a075 in glewInit () at /home/alex/Desktop/misc/opengltest/glew-cmake/src/glew.c:18022
  #3  0x0000000000404335 in main () at /home/alex/Desktop/misc/opengltest/main.cpp:35
  </code></pre>