title: glDrawElements Segmentation Fault
body: <p>I am currently trying to draw an object using VBOs.
  In the Cube-Class I came up with to test the functionality of VBOs, I create the VBOs like this:</p>
  
  <pre><code>//Vertex
  glGenBuffers(1, &amp;m_bufVertex);
  glBindBuffer(GL_ARRAY_BUFFER, m_bufVertex);
  glBufferData(GL_ARRAY_BUFFER, 6*4*3*sizeof(GLfloat), vertex_data, GL_STATIC_DRAW);
  //TexCoord
  glGenBuffers(1, &amp;m_bufTexCoord);
  glBindBuffer(GL_ARRAY_BUFFER, m_bufTexCoord);
  glBufferData(GL_ARRAY_BUFFER, 6*4*2*sizeof(GLfloat), texcoord_data, GL_STATIC_DRAW);
  //Index
  glGenBuffers(1,&amp;m_bufIndex);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_bufIndex);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER,24*sizeof(GLuint), indices, GL_STATIC_DRAW);
  </code></pre>
  
  <p>I already double checked if the data is in the buffers e.g. like this (the vertex buffer is binded at that time):</p>
  
  <pre><code>GLfloat* test = (GLfloat *) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
  for (unsigned int i = 0; i &lt; 6*4*3; i++)
      cout &lt;&lt; "Value " &lt;&lt; i &lt;&lt; " = " &lt;&lt; test[i] &lt;&lt; endl;
  </code></pre>
  
  <p>So the data is where it is supposed to be, so the problem seems to lie within the Render-Function. The Segmentation-Error happens when glDrawElements() or glDrawArrays() is called.
  Here is the code:</p>
  
  <pre><code>glBindTexture(GL_TEXTURE_2D, m_texture);
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  // some translation, currently fixed, just testing code
  glTranslatef(0.0f, 0.0f, -200.0f);
  glRotatef(30.f, 1.f, 0.f, 0.f);
  glRotatef(30.f, 0.f, 1.f, 0.f);
  glRotatef(30.f, 0.f, 0.f, 1.f);
  // enable client states
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  // set pointers
  glBindBuffer(GL_ARRAY_BUFFER, m_bufVertex);
  glVertexPointer(3, GL_FLOAT, 0, 0);
  glBindBuffer(GL_ARRAY_BUFFER, m_bufTexCoord);
  glTexCoordPointer(2, GL_FLOAT, 0, 0);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_bufIndex);
  // just error check to see if something went wrong previously
  GLenum err = glGetError();
  if (GL_NO_ERROR != err)
      cout &lt;&lt; "GL: " &lt;&lt; err &lt;&lt; " - " &lt;&lt; gluErrorString(err) &lt;&lt; endl;
  glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, 0);
  // disable state and pop matrix
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  glPopMatrix();
  </code></pre>
  
  <p>I assume I am using the pointers not right or glDrawElements(), but I don't know what.
  Some more informations:
  The code is compiled on MacOSX Lion (OpenGL2.1) using the GNU-toolchain and GLEW.</p>
  
  <p>EDIT:</p>
  
  <pre><code>GLfloat vertex_data[6*4*3] = {-m_fSize, -m_fSize, -m_fSize,
                         -m_fSize,  m_fSize, -m_fSize,
                          m_fSize,  m_fSize, -m_fSize,
                          m_fSize, -m_fSize, -m_fSize,
                          -m_fSize, -m_fSize, m_fSize,
                          -m_fSize,  m_fSize, m_fSize,
                           m_fSize,  m_fSize, m_fSize,
                           m_fSize, -m_fSize, m_fSize,
                         -m_fSize, -m_fSize, -m_fSize,
                         -m_fSize,  m_fSize, -m_fSize,
                         -m_fSize,  m_fSize,  m_fSize,
                         -m_fSize, -m_fSize,  m_fSize,
                          m_fSize, -m_fSize, -m_fSize,
                          m_fSize,  m_fSize, -m_fSize,
                          m_fSize,  m_fSize,  m_fSize,
                          m_fSize, -m_fSize,  m_fSize,
                         -m_fSize, -m_fSize,  m_fSize,
                         -m_fSize, -m_fSize, -m_fSize,
                          m_fSize, -m_fSize, -m_fSize,
                          m_fSize, -m_fSize,  m_fSize,
                          -m_fSize, m_fSize,  m_fSize,
                          -m_fSize, m_fSize, -m_fSize,
                           m_fSize, m_fSize, -m_fSize,
                          m_fSize, m_fSize,  m_fSize};
   GLfloat texcoord_data[6*4*2] = {0, 0, 0, 1, 1, 1, 1, 
                                  0, 0, 0, 0, 1, 1, 1, 
                                  1, 0, 0, 0, 0, 1, 1, 
                                  1, 1, 0, 0, 0, 0, 1,
                                  1, 1, 1, 0, 0, 1, 0, 
                                  0, 1, 0, 1, 1, 0, 1,
                                  0, 0, 1, 0, 1, 1};
  GLuint indices[24] = {0,1,2,3,
                       4,5,6,7,
                       8,9,10,11,
                       12,13,14,15,
                       16,17,18,19,
                       20,21,22,23};
  </code></pre>
  
  <p>I know am defining every vertex instead of just 8...</p>
  
  <p>EDIT2:
  The makefile:</p>
  
  <pre><code>OUT = bin/test
  CC = g++
  INCDIR = inc
  OBJDIR = obj
  SRCDIR = src
  INC = -I$(INCDIR) -I/opt/local/include
  LIBS = -L/opt/local/lib -lGLEW -lsfml-graphics -lsfml-window -lsfml-system -framework AGL -framework OpenGL -framework Foundation
  
  _OBJS = Main.o \
      Timer.o \
      Cube.o \
      chrono.o process_cpu_clocks.o thread_clock.o error_code.o
  
  OBJS = $(patsubst %,$(OBJDIR)/%,$(_OBJS))
  
  $(OBJDIR)/%.o: $(SRCDIR)/%.cpp 
  $(CC) -c $(INC) -o $@ $&lt; $(CFLAGS) 
  
  
  $(OUT): $(OBJS)
  $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
  strip $(OUT)
  
  clean:
  rm -f $(OBJDIR)/*.o $(OUT)
  </code></pre>