title: OpenGL function in a class
body: <p>I'm creating an OpenGL project which includes <code>ParticleFactory</code> class to generate particles in a scene.</p>
  
  <p>To achieve that I have created a class:</p>
  
  <pre><code>#ifndef PARTICLE_H
  #define PARTICLE_H
  
  #include &lt;glad/glad.h&gt;
  #include &lt;GLFW/glfw3.h&gt;
  #include &lt;glm/glm.hpp&gt;
  #include &lt;glm/gtc/matrix_transform.hpp&gt;
  #include &lt;glm/gtc/type_ptr.hpp&gt;
  #include &lt;iostream&gt; 
  #include &lt;vector&gt;
  #include "vertex.h"
  
  #include &lt;shader_s.h&gt;
  
  class ParticleFactory {
      public:
          Shader* shader;
          std::vector&lt;Particle&gt; particles;
          unsigned int VAO, VBO, EBO;
          unsigned int nr_particles;
  
          ParticleFactory(unsigned int nr_particles, unsigned int color){
              Shader sh("shaders/particle.vs", "shaders/particle.fs");
              shader = &amp;sh;
              this-&gt;nr_particles = nr_particles;
              for(unsigned int i = 0; i &lt; nr_particles; i++) {
                  float x = (rand()%200)/100.0 - 1;
                  float y = (rand()%200)/100.0 - 1;
                  float z = (rand()%200)/100.0 - 1;
                  particles.push_back(Particle(glm::vec4(x, y, z, 0.0)));
              }
  
              glGenVertexArrays(1, &amp;VAO);
              glGenBuffers(1, &amp;VBO);
              glGenBuffers(1, &amp;EBO);
              glBindVertexArray(VAO);
              glBindBuffer(GL_ARRAY_BUFFER, VBO);
              glBufferData(GL_ARRAY_BUFFER, sizeof(base_particle), base_particle, GL_STREAM_DRAW);
              glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
              glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(base_particle_indices), base_particle_indices, GL_STREAM_DRAW);
              glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
              glEnableVertexAttribArray(0);
          }
  
          void draw() {
              shader-&gt;use();
              shader-&gt;setMat4("model", model);
              shader-&gt;setMat4("view", view);
              shader-&gt;setMat4("projection", projection);
              shader-&gt;setMat4("transform", transform);
              for (int i=0; i&lt;nr_particles; i++) {
                  shader-&gt;setVec4("offset", particles[i].offset);
                  glBindVertexArray(VAO);
                  glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, 0);
                  particles[i].offset += glm::vec4(0.0f, -0.001f, 0.0f, 0.0f);
                  if (particles[i].offset.y &lt;= -1.0f) {
                      particles[i].offset.y = 1.0f;
                  }
              }
          }
  };
  
  #endif
  </code></pre>
  
  <p>My approach here is to first instantiate an object and then call <code>.draw()</code> on the main loop but it doesn't seems to work and I don't know why.</p>