title: Java: Drawing lines Slick LWJGL OpenGL
body: <p>I'm learning how to use OpenGL and starting to build some experiments around Slick 2D Game library but I'm running into a few problems.</p>
  
  <p>I'm trying to draw simple lines, store them in a array then iterate over that array to render each single line. This is the main class:</p>
  
  <pre><code>    ArrayList&lt;Bloco&gt; listaBlocos = new ArrayList&lt;Bloco&gt;();
  ArrayList&lt;Linha&gt; listaLinhas = new ArrayList&lt;Linha&gt;();
  boolean random = false;
  
  @Override
  public void init(GameContainer gc) throws SlickException {
      listaBlocos = new ArrayList&lt;Bloco&gt;();
      listaLinhas = new ArrayList&lt;Linha&gt;();
  }
  
  @Override
  public void update(GameContainer gc, int delta) throws SlickException {
      Input input = gc.getInput();
  
      if (input.isMousePressed(0))
          listaBlocos.add(new Bloco(input.getMouseX() - 5, input.getMouseY() - 5, 10, new Color(0, 255, 0)));
      if (input.isMousePressed(1))
          listaBlocos.add(new Bloco(input.getMouseX() - 5, input.getMouseY() - 5, 10, new Color(255, 0, 0)));
  
      if (input.isKeyPressed(Input.KEY_A))
          if (random == false)
              random = true;
          else
              random = false;
  
      if (input.isKeyPressed(Input.KEY_S))
          listaLinhas.add(new Linha(input.getMouseX(), input.getMouseY(), 100, 100));
  
      if (input.isKeyDown(Input.KEY_D))
          listaLinhas.get(0).drawLine();
  
      if (!listaBlocos.isEmpty() &amp;&amp; random)
          for (Bloco b : listaBlocos)
              b.moveRandom(delta);
  
  }
  
  public void render(GameContainer gc, Graphics g) throws SlickException {
  
      for (Linha l : listaLinhas)
          l.drawLine();
  
      for (Bloco b : listaBlocos)
          b.draw(g);
  
  }
  </code></pre>
  
  <p>And this is the Linha class (it extends Line):</p>
  
  <pre><code>public class Linha extends Line {
  
  public Linha(float x1, float y1, float x2, float y2) {
      super(x1, y1, x2, y2);
  }
  
  public void drawLine() {
  
      GL11.glColor3f(1.0f, 1.0f, 1.0f);
      GL11.glBegin(GL11.GL_LINES);
      GL11.glLineWidth(5.0f);
      GL11.glVertex2f(getX1(), getY1());
      GL11.glVertex2f(getX2(), getY2());
      GL11.glEnd();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This was just for testing, if there's a better way to render a bunch of lines please tell me. The problem is that the lines flash on the screen, they're not always there full color. I've recorded the problem so you can see what's happening <a href="http://www.youtube.com/watch?v=ymO00yb5NVE" rel="nofollow">http://www.youtube.com/watch?v=ymO00yb5NVE</a></p>