title: drawing multiple objects in OpenGL
body: <p>I started learning OpenGL. I can load a .obj model and draw it with an elementBuffer. But I'm stuck at trying to two different models at a time. The model I want to draw is in an Entity class.
  Most tutorials I can find about this only shows how to load and draw a sinlge model. None explains (In a way I can find/understand at least) how to handle multiple models.</p>
  
  <p>Here is all my code:</p>
  
  <pre><code>public static void main(String[] args) throws LWJGLException, IOException
  {
      PixelFormat pixelFormat = new PixelFormat();
      ContextAttribs contextAtrributes = new ContextAttribs(3, 2);
      contextAtrributes.withForwardCompatible(true);
      contextAtrributes.withProfileCore(true);
  
      Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
      Display.setTitle("Textured quad!");
      Display.create(pixelFormat, contextAtrributes);
  
      Mouse.create();
      Mouse.setGrabbed(true);
      Keyboard.create();
  
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
  
      entity = new Entity("planeTex.obj");
      entity2 = new Entity("modelTex2.obj");
  
      Shaders.load();
      Textures.load();
      Camera.create(new Vector3f(0, 1, -0.75f), new Vector3f(-50, 0, 20), HEIGHT, WIDTH);
  
      while (!Display.isCloseRequested())
      {
  
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
          entity.draw();
          entity2.draw();
  
          Display.update();
          Display.sync(60);
      }
  
  }
  
  public class Entity
  {
      private int vao, vbo, ebo;
      private int elementSize;
  
      public Entity(String name)
      {
          vao = glGenVertexArrays();
          glBindVertexArray(vao);
          vbo = glGenBuffers();
          *Load vertex data into buffer*
          glBindBuffer(GL_ARRAY_BUFFER, vbo);
          glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
          ebo = glGenBuffers();
          *load data into elementBuffer*
          *Set elementSize to the element count*
          glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
          glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementBuffer, GL_STATIC_DRAW);
      }
  
      public void draw()
      {
          glBindVertexArray(vao);
          glBindBuffer(GL_ARRAY_BUFFER, vbo);
          glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
  
          glDrawElements(GL_TRIANGLES, elementSize, GL_UNSIGNED_INT, 0);
      }
  }
  
  public class Shaders
  {
  
  public static int vertexShader, fragmentShader;
  public static int shaderProgram;
  public static int uniTrans;
  
      public static void load()
      {
          vertexShader = glCreateShader(GL_VERTEX_SHADER);
          glShaderSource(vertexShader, loadFile("vertex.shader"));
          glCompileShader(vertexShader);
  
          fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
          glShaderSource(fragmentShader, loadFile("fragment.shader"));
          glCompileShader(fragmentShader);
  
  
          shaderProgram = glCreateProgram();
          glAttachShader(shaderProgram, vertexShader);
          glAttachShader(shaderProgram, fragmentShader);
          glBindFragDataLocation(shaderProgram, 0, "outColor");
          glLinkProgram(shaderProgram);
          glUseProgram(shaderProgram);
  
  
          // Specify the layout of the vertex data
          int posAttrib = glGetAttribLocation(shaderProgram, "position");
          glEnableVertexAttribArray(posAttrib);
          glVertexAttribPointer(posAttrib, 3, GL_FLOAT, false, (Float.SIZE / 8) * 8, 0);
  
          int colAttrib = glGetAttribLocation(shaderProgram, "color");
          glEnableVertexAttribArray(colAttrib);
          glVertexAttribPointer(colAttrib, 3, GL_FLOAT, false, (Float.SIZE / 8) * 8, (Float.SIZE / 8) * 3);
  
          int texAttrib = glGetAttribLocation(shaderProgram, "texcoord");
          glEnableVertexAttribArray(texAttrib);
          glVertexAttribPointer(texAttrib, 2, GL_FLOAT, false, (Float.SIZE / 8) * 8, (Float.SIZE / 8) * 6);
  
          uniTrans = glGetUniformLocation(Shaders.shaderProgram, "model");
      }
  }
  </code></pre>
  
  <p>The result is that only the Entity object created last will be drawn. No matter the draw order.</p>