title: Segmentation fault in OpenGL under Linux
body: <p>I am following some tutorials and came up with the following code:</p>
  
  <pre><code>// rendering.cpp
  
  #include "rendering.h"
  #include &lt;GL/gl.h&gt;
  #include &lt;GL/freeglut.h&gt;
  
  void DrawGLScene()
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();
  }
  
  int InitGL(int argc, char** argv)
  {
      /*glShadeModel(GL_SMOOTH);
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClearDepth(1.0f);
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);
      glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);*/
  
      glutInit(&amp;argc, argv);
      glutInitWindowSize(500, 500);
      glutInitWindowPosition(100, 100);
      glutDisplayFunc(DrawGLScene);
      glutCreateWindow("Swimming Simulation");
      glutMainLoop(); // Enter GLUT's main loop
  
      return true;
  }
  </code></pre>
  
  <p>My main function is very simple and only calls that function:</p>
  
  <pre><code>#include "rendering.h"
  
  int main(int argc, char** argv)
  {
      InitGL(argc, argv);
      return 0;
  }
  </code></pre>
  
  <p>I am compiling with this command:</p>
  
  <pre><code>g++ -Wall -g swim.cpp rendering.cpp -lglut -lGLU -o swim
  </code></pre>
  
  <p>Running <code>swim</code> creates a window as expected. However, if I uncomment the lines in <code>InitGL</code>, then I get a segmentation fault when running the program:</p>
  
  <pre><code>(gdb) r
  Starting program: &lt;dir&gt; 
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib64/libthread_db.so.1".
  
  Program received signal SIGSEGV, Segmentation fault.
  0x000000335ca52ca7 in glShadeModel () from /usr/lib64/libGL.so.1
  Missing separate debuginfos, use: debuginfo-install freeglut-2.6.0-6.fc15.x86_64 glibc-2.14.90-24.fc16.6.x86_64 libX11-1.4.3-1.fc16.x86_64 libXau-1.0.6-2.fc15.x86_64 libXdamage-1.1.3-2.fc15.x86_64 libXext-1.3.0-1.fc16.x86_64 libXfixes-5.0-1.fc16.x86_64 libXi-1.4.5-1.fc16.x86_64 libXxf86vm-1.1.1-2.fc15.x86_64 libdrm-2.4.33-1.fc16.x86_64 libgcc-4.6.3-2.fc16.x86_64 libstdc++-4.6.3-2.fc16.x86_64 libxcb-1.7-3.fc16.x86_64 mesa-libGL-7.11.2-3.fc16.x86_64 mesa-libGLU-7.11.2-3.fc16.x86_64
  (gdb) backtrace
  #0  0x000000335ca52ca7 in glShadeModel () from /usr/lib64/libGL.so.1
  #1  0x0000000000401d67 in InitGL (argc=1, argv=0x7fffffffe198)
      at rendering.cpp:25
  #2  0x0000000000401c8c in main (argc=1, argv=0x7fffffffe198) at swim.cpp:37
  </code></pre>
  
  <p>What should I be doing here to get my program to run without crashing?</p>