title: Cube is not rendering in OpenGL
body: <p>I'm trying to write a basic OpenGL 3.3 program with shaders, buffers, etc. drawing a cube. The problem is that the cube is not drawn. Sorry for such an amout of code, but i feel like the error might be anywhere, because to me it all seems right: display function is looping, shaders are compiled, matrices are passed to shaders. I suspecting that something might be  wrong with culling. Please take a look. Here is the code (I'm using freeglut, first init() is called, then display runs in a loop):</p>
  
  <p>initialization code:</p>
  
  <pre><code>struct ProgramData
  {
      GLuint theProgram;
      GLuint iModel;
      GLuint iView;
      GLuint iProjection;
  };
  
  ProgramData shaderProgram;
  
  ProgramData LoadProgram(const std::string &amp;strVertexShader, 
                          const std::string &amp;strFragmentShader)
  {
      std::vector&lt;GLuint&gt; shaderList;
  
      shaderList.push_back(LoadShader(GL_VERTEX_SHADER, strVertexShader));
      shaderList.push_back(LoadShader(GL_FRAGMENT_SHADER, strFragmentShader));
  
      ProgramData data;
      data.theProgram = CreateProgram(shaderList);
      data.iModel = glGetUniformLocation(data.theProgram, "mModel");
      data.iView = glGetUniformLocation(data.theProgram, "mView");
      data.iProjection = glGetUniformLocation(data.theProgram, "mProjection");
  
      return data;
  }
  
  float cube_vertices[] = {
      -1.0f, -1.0f,  1.0f,
       1.0f, -1.0f,  1.0f,
       1.0f,  1.0f,  1.0f,
      -1.0f,  1.0f,  1.0f,
      -1.0f, -1.0f, -1.0f,
       1.0f, -1.0f, -1.0f,
       1.0f,  1.0f, -1.0f,
      -1.0f,  1.0f, -1.0f,
  
      GREEN_COLOR,
      BLUE_COLOR,
      RED_COLOR,
      BROWN_COLOR,
  
      GREEN_COLOR,
      BLUE_COLOR,
      RED_COLOR,
      BROWN_COLOR,
  };
  
  GLubyte cube_elements[] = {
       0,1,2, 2,3,0,   
       0,3,4, 4,5,0,
       0,5,6, 6,1,0,
       1,6,7, 7,2,1,
       7,4,3, 3,2,7,
       4,7,6, 6,5,4
  };
  
  void InitializeProgram()
  {
  
      //initialize vertex buffer
      glGenBuffers(1, &amp;vertex_buffer_obj);
      glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_obj);
      glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), 
                     cube_vertices, GL_STATIC_DRAW);
      glBindBuffer(GL_ARRAY_BUFFER, 0);
  
      //initialize index buffer
      glGenBuffers(1, &amp;index_buffer_obj);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_obj);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_elements), 
                             cube_elements, GL_STATIC_DRAW);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  
      shaderProgram = LoadProgram("shader.vert", "shader.frag");
  }
  
  void init()
  {
      InitializeProgram();
  
      int numberOfVertices = 8;
      size_t color_data_offset = sizeof(float) * 3 * numberOfVertices;
  
      glGenVertexArrays(1, &amp;vao);
      glBindVertexArray(vao);
  
      glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_obj);
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
      glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 
                            (void*)color_data_offset);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_obj);
      glBindVertexArray(0);
  
  
      glEnable(GL_CULL_FACE);
      glCullFace(GL_BACK);
      glFrontFace(GL_CW);
  
      glEnable(GL_DEPTH_TEST);
      glDepthMask(GL_TRUE);
      glDepthFunc(GL_LEQUAL);
      glDepthRange(0.0f, 1.0f);
  
  }
  </code></pre>
  
  <p>vertex shader:</p>
  
  <pre><code>#version 330
  
  layout (location = 0) in vec3 inPosition;
  layout (location = 1) in vec3 color;
  
  uniform mat4 mProjection;
  uniform mat4 mView;
  uniform mat4 mModel;
  
  smooth out vec3 theColor;
  
  void main()
  {
      gl_Position = mProjection * mView * mModel * vec4(inPosition, 1);
      theColor = color;
  }
  </code></pre>
  
  <p>fragment shader:</p>
  
  <pre><code>#version 330
  
  smooth in vec3 theColor;
  out vec4 outputColor;
  
  void main()
  {
      outputColor = vec4(theColor, 1);
  }
  </code></pre>
  
  <p>draw code:</p>
  
  <pre><code>glm::vec3 cam_pos(3, 2, 3);
  void display()
  {
  
  glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  glClearDepth(1.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  glUseProgram(shaderProgram.theProgram);
  
  glm::mat4 model_matrix = glm::translate(glm::vec3(0, 0, 0));
  glm::mat4 view_matrix = glm::lookAt(cam_pos, 
                           glm::vec3(0, 0, 0), glm::vec3(0, 0, 1));
  glm::mat4 proj_matrix = glm::perspective(45.0f, 1.0f, 1.0f, 100.0f);
  
  glUniformMatrix4fv(shaderProgram.iProjection, 1, 
                         GL_FALSE, glm::value_ptr(proj_matrix));
  glUniformMatrix4fv(shaderProgram.iView, 1, 
                         GL_FALSE, glm::value_ptr(view_matrix));
  glUniformMatrix4fv(shaderProgram.iModel, 1, 
                         GL_FALSE, glm::value_ptr(model_matrix));
  
  glBindVertexArray(vao);
  int size;  glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, 
                                        GL_BUFFER_SIZE, &amp;size);
  glDrawElements(GL_TRIANGLES, size / sizeof(GLubyte), GL_UNSIGNED_SHORT, 0);
  
  glBindVertexArray(0);
  glUseProgram(0);
  
      glutSwapBuffers();
      glutPostRedisplay();
  }
  </code></pre>
  
  <p>UPD: in init method when an offset for colors is calculated should be 
  <code>sizeof(float) * 3 * numberOfVertices</code> instead of 
  <code>sizeof(GLubyte) * 3 * numberOfVertices</code>, colors are stored as floats. Rendering problem not solved.</p>
  
  <p>SOLVED: thank you for help. See my answer below.</p>