title: C++ OpenGL Rendering Simple OBJ From File
body: <p>I am currently following a basic OpenGL tutorial where the goal is to read data from an .OBJ file and then render the model. The tutorial is located here - <a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/" rel="nofollow">http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/</a>.</p>
  
  <p>Currently, my program opens the OBJ file specified and parses it using the parsing engine discussed in the tutorial here - <a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/#Reading_the_file" rel="nofollow">http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/#Reading_the_file</a>.</p>
  
  <p>The object I am trying to render is the Cube located on the same tutorial page URL.</p>
  
  <p>I believe my problem lies in my display(void) function. After I execute          <code>glutDisplayFunc(display);</code> in my main(), I am presented with a black window, rather than my rendered model.</p>
  
  <p>This is my current display(void) function:</p>
  
  <pre><code>void display(void)
  {
      GLuint vbo;
  
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
  
      glBegin(GL_TRIANGLES);
      glGenBuffers(1, &amp;vbo);
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3) * 3, &amp;vertices[0], GL_STATIC_DRAW);
      glDrawElements(GL_TRIANGLES, vertices.size() * sizeof(glm::vec3) * 3, GL_UNSIGNED_INT, &amp;vertices[0]);
  
      // check OpenGL error
      GLenum err;
      while ((err = glGetError()) != GL_NO_ERROR)
      {
          printf("OpenGL error: %u", err);
      }
  
      glEnd();
  
      glutSwapBuffers();
  }
  </code></pre>
  
  <p>And here is the data my parser reads in, perhaps it is a parsing issue:</p>
  
  <p><code>
  Success: GLEW_OK
  Success: Opened OBJ File cube.obj
  Read in Vertices: 1.000000,     -1.000000,      -1.000000
  Read in Vertices: 1.000000,     -1.000000,      1.000000
  Read in Vertices: -1.000000,    -1.000000,      1.000000
  Read in Vertices: -1.000000,    -1.000000,      -1.000000
  Read in Vertices: 1.000000,     1.000000,       -1.000000
  Read in Vertices: 0.999999,     1.000000,       1.000001
  Read in Vertices: -1.000000,    1.000000,       1.000000
  Read in Vertices: -1.000000,    1.000000,       -1.000000
  Read in texture coordinate: 0.748573,   0.750412
  Read in texture coordinate: 0.749279,   0.501284
  Read in texture coordinate: 0.999110,   0.501077
  Read in texture coordinate: 0.999455,   0.750380
  Read in texture coordinate: 0.250471,   0.500702
  Read in texture coordinate: 0.249682,   0.749677
  Read in texture coordinate: 0.001085,   0.750380
  Read in texture coordinate: 0.001517,   0.499994
  Read in texture coordinate: 0.499422,   0.500239
  Read in texture coordinate: 0.500149,   0.750166
  Read in texture coordinate: 0.748355,   0.998230
  Read in texture coordinate: 0.500193,   0.998728
  Read in texture coordinate: 0.498993,   0.250415
  Read in texture coordinate: 0.748953,   0.250920
  Read in Normals: 0.000000,      0.000000,       -1.000000
  Read in Normals: -1.000000,     -0.000000,      -0.000000
  Read in Normals: -0.000000,     -0.000000,      1.000000
  Read in Normals: -0.000001,     0.000000,       1.000000
  Read in Normals: 1.000000,      -0.000000,      0.000000
  Read in Normals: 1.000000,      0.000000,       0.000001
  Read in Normals: 0.000000,      1.000000,       -0.000000
  Read in Normals: -0.000000,     -1.000000,      0.000000
  Reached end of file
  Out Vertices Size: 234</code></p>
  
  <p>glGetError() has not produced an error for me once, so I was not able to debug the issue that way.</p>
  
  <p>Any suggestions / input?</p>