title: c++ with openGl can't render
body: <p>I try to make the code cleaner by extracting the whole main Proramm in some classes. So I have a vertex buffer, index buffer and a shader class. Only the array buffer is in the main and it worked.</p>
  <p>Now I created a layout class and a vertex array class to put different layouts in the vertex array and the renderfunction in my main stopped to work.</p>
  <p>Here is my code:</p>
  <p>vertexBuffer.cpp</p>
  <pre><code>#include &quot;../headerData/VertexBuffer.h&quot;
  
  VertexBuffer::VertexBuffer(const void* data, unsigned int size) {
  
      glGenBuffers(1, &amp;bufferId);
      glBindBuffer(GL_ARRAY_BUFFER, bufferId);
      glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
  
  
  }
  VertexBuffer::~VertexBuffer() {
  
      glDeleteBuffers(1, &amp;bufferId);
  }
  
  void VertexBuffer::bind() const {
      glBindBuffer(GL_ARRAY_BUFFER, bufferId);
  }
  
  void VertexBuffer::unbind() const {
      glBindBuffer(GL_ARRAY_BUFFER, 0);
  }
  </code></pre>
  <p>vertex Index cpp:</p>
  <pre><code>#include &quot;../headerData/IndexBuffer.h&quot;
  
  IndexBuffer::IndexBuffer(const void* data, unsigned int count) {
  
      glGenBuffers(1, &amp;bufferId);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, count, data, GL_STATIC_DRAW);
  
  
  }
  IndexBuffer::~IndexBuffer() {
  
      glDeleteBuffers(1, &amp;bufferId);
  }
  
  void IndexBuffer::bind() const {
      glBindBuffer(GL_ARRAY_BUFFER, bufferId);
  }
  
  void IndexBuffer::unbind() const {
      glBindBuffer(GL_ARRAY_BUFFER, 0);
  }
  </code></pre>
  <p>VertexLayout.h</p>
  <pre><code>#pragma once
  #include &lt;vector&gt;
  
  
  //Stubides Layout da vieles vorgegeben wird
  struct ElementLayout {
      unsigned int size;          //anzahl an koordinaten die zählen
      unsigned int stride;        //Die größe der 
  };
  
  class VertexLayout {
  
  private:
      std::vector&lt;ElementLayout&gt; elements;
  public:
      VertexLayout();
      ~VertexLayout();
  
      void layoutPush(unsigned int size);
      std::vector&lt;ElementLayout&gt; getElements() const;
  };
  </code></pre>
  <p>vertexLayout.cpp:</p>
  <pre><code>#include&quot;../headerData/VertexLayout.h&quot;
  
  
  VertexLayout::VertexLayout() {}
  VertexLayout::~VertexLayout() {}
  
  void VertexLayout::layoutPush(unsigned int size)
  {
      elements.push_back({ size, size * sizeof(float) });
  }
  
  std::vector&lt;ElementLayout&gt; VertexLayout::getElements() const {
      return elements;
  }
  </code></pre>
  <p>VertexArray.cpp</p>
  <pre><code>#include &quot;../headerData/VertexArray.h&quot;
  #include &lt;iostream&gt;
  
  VertexArray::VertexArray() {
      glGenVertexArrays(1, &amp;vertexArrayID);
  
  }
  VertexArray::~VertexArray() {
      glDeleteVertexArrays(1, &amp;vertexArrayID);
  }
  
  void VertexArray::bind() const {
      glBindVertexArray(vertexArrayID);
  }
  void VertexArray::unbind() const {
      glBindVertexArray(0);
  }
  
  //Vom Buffer soll auch das zugehörige Layout übergeben werden
  void VertexArray::addBuffer(VertexBuffer&amp; vb, VertexLayout&amp; layout) {
      bind();
      vb.bind();
      std::vector&lt;ElementLayout&gt; element = layout.getElements();
      unsigned int offset = 0;
      for (int i = 0; i &lt; element.size(); i++) {
  
          glEnableVertexAttribArray(0);
          glVertexAttribPointer(0, element[i].size, GL_FLOAT, GL_FALSE, element[i].stride, (void*)0);
          offset += element[i].size * sizeof(float);
          std::cout &lt;&lt; GL_NO_ERROR;
      }
  
      std::cout &lt;&lt; glGetError();
  
  }
  </code></pre>
  <p>main.cpp:</p>
  <pre><code>#include &lt;glad/glad.h&gt;
  #include &lt;GLFW/glfw3.h&gt;
  
  #include &lt;iostream&gt;
  #include &quot;headerData/VertexBuffer.h&quot;
  #include &quot;headerData/IndexBuffer.h&quot;
  #include &quot;headerData/Shader.h&quot;
  #include &quot;headerData/VertexLayout.h&quot;
  #include &quot;headerData/VertexArray.h&quot;
  
  
  void framebuffer_size_callback(GLFWwindow* window, int width, int height);
  void processInput(GLFWwindow* window)
  {
      if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
          glfwSetWindowShouldClose(window, true);
  }
  
  int main()
  {
      // glfw: initialize and configure
      // ------------------------------
      glfwInit();
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  
  #ifdef __APPLE__
      glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  #endif
  
      // glfw window creation
      // --------------------
      GLFWwindow* window = glfwCreateWindow(800, 800, &quot;LearnOpenGL&quot;, NULL, NULL);
      if (window == NULL)
      {
          std::cout &lt;&lt; &quot;Failed to create GLFW window&quot; &lt;&lt; std::endl;
          glfwTerminate();
          return -1;
      }
      glfwMakeContextCurrent(window);
      glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
  
      // glad: load all OpenGL function pointers
      // ---------------------------------------
      if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
      {
          std::cout &lt;&lt; &quot;Failed to initialize GLAD&quot; &lt;&lt; std::endl;
          return -1;
      }
  
      Shader shader;
      shader.bind();
      // set up vertex data (and buffer(s)) and configure vertex attributes
      // ------------------------------------------------------------------
      float vertices[] = {
           0.5f,  0.5f, 0.0f,  // top right
           0.5f, -0.5f, 0.0f,  // bottom right
          -0.5f, -0.5f, 0.0f,  // bottom left
          -0.5f,  0.5f, 0.0f,   // top left
          -1.0f, -1.0f, 0.0f  //zum Testen
          //dreieck
  
      };
      unsigned int indices[] = {  // note that we start from 0!
          0, 1, 3,   // first triangle
          1, 2, 3    // second triangle
      };
  
      float vertices2[] = {
      -1.0f, -1.0f, 0.0f,
       1.0f, -1.0f, 0.0f,
       0.0f,  0.0f, 0.0f
      };
      unsigned int test;
      glGenVertexArrays(1, &amp;test);
  
      // bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
      glBindVertexArray(test);
  
      //glBindBuffer(GL_ARRAY_BUFFER, VBO);
      //glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
      VertexBuffer vb(vertices, 5 * 3 * sizeof(float));
      IndexBuffer ib(indices, 6 * sizeof(unsigned int));
      VertexLayout layout;
      layout.layoutPush(3);
      VertexArray va;
      //va.addBuffer(vb, layout);
  
  
      //va.addBuffer(vb, layout); when this is uncomment the render function doesn't work
  
      //Parameter
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(0));
      //glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(3 * sizeof(float)));
      glEnableVertexAttribArray(0);
      //glEnableVertexAttribArray(1);
  
  
      // uncomment this call to draw in wireframe polygons.
      //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  
      // render loop
      // -----------
      while (!glfwWindowShouldClose(window))
      {
          // input
          // -----
          processInput(window);
  
          // render
          // ------
          glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
          glClear(GL_COLOR_BUFFER_BIT);
  
          shader.bind();
          //glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, (void*)(sizeof(unsigned int) * 3));
          //glDrawArrays(GL_TRIANGLES, 0, 3);
          //glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, (void*)(sizeof(unsigned int) * 3));
          glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  
          // glBindVertexArray(0); // no need to unbind it every time 
  
          // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
          // -------------------------------------------------------------------------------
          glfwSwapBuffers(window);
          glfwPollEvents();
      }
  
      // optional: de-allocate all resources once they've outlived their purpose:
      // ------------------------------------------------------------------------
      glDeleteVertexArrays(1, &amp;test);
  
  
      // glfw: terminate, clearing all previously allocated GLFW resources.
      // ------------------------------------------------------------------
      glfwTerminate();
      return 0;
  }
  </code></pre>
  <p>With glGetError() I get the number 1281 =&gt;invalid value but where.</p>