title: Making another object with OpenGL
body: <p>First question so sorry if somethings out of place.</p>
  
  <p>Below is a code snippet that works just fine.</p>
  
  <p>Init function</p>
  
  <pre><code>    ShaderLoader shaderloader;
      Program = shaderloader.LoadShaders("VertexShader.vs", "FragmentShader.fs");
      glGenVertexArrays(1, &amp;VertexArrayObject);
      glBindVertexArray(VertexArrayObject);
      glGenBuffers(1, &amp;VertexBuffer);
      glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBufferData) * 
      vertexBufferData.size(), &amp;vertexBufferData.front(), GL_STATIC_DRAW);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
      glEnableVertexAttribArray(0);
      glBindVertexArray(0);
  </code></pre>
  
  <p>Render function</p>
  
  <pre><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glClearColor(0.0, 0.0, 0.0, 1.0);
  glUseProgram(Program);
  glBindVertexArray(VertexArrayObject);
  glDrawArrays(GL_TRIANGLES, 0, 6);
  glBindVertexArray(0);
  glutSwapBuffers();
  </code></pre>
  
  <p>This all works fine within my main.cpp but when i put this into a class it gives me an access violation error. My class container holds its own VertexArrayObject and VertexBuffer so I am assuming that should be enough information to draw a simple triangle as it draws fine when it is not in a class. My end goal here is to create two objects so if I'm going about this completely wrong please point me in the right direction!</p>
  
  <p>Code in the sprite class:</p>
  
  <pre><code>    void Mesh::init(std::vector&lt;GLfloat&gt; vertexBufferData)
      {
          glGenVertexArrays(1, &amp;VertexArrayObject);
          glBindVertexArray(VertexArrayObject);
          glGenBuffers(1, &amp;VertexArrayObject);
          glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
          glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBufferData) *         
          vertexBufferData.size(), &amp;vertexBufferData.front(), GL_STATIC_DRAW);
          glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
          glEnableVertexAttribArray(0);
          glBindVertexArray(0);
      }
  
      void Mesh::Draw()
      {
          glBindVertexArray(VertexArrayObject);
          glDrawArrays(GL_TRIANGLES, 0, 6);
          glBindVertexArray(0);
      }
  </code></pre>
  
  <p>How I'm using the class in the main.cpp:</p>
  
  <pre><code>    Mesh object1;
  
      void init()
      {
          ShaderLoader shaderloader;
          Program = shaderloader.LoadShaders("VertexShader.vs", "FragmentShader.fs");
          object1.init(vertexBufferData);
      }
  
      void Render()
      {
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
          glClearColor(0.0, 0.0, 0.0, 1.0);
          glUseProgram(Program);
          object1.Draw();
          glutSwapBuffers();
      }
  </code></pre>
  
  <p>And the exception thrown is: 0x5253F00A </p>
  
  <p>Access Violation reading location</p>