title: drawing from a byte array in java LWJGL
body: <p>I am creating a raycaster using java, LWJGL and Slick2D.
  The problem is that I can't seem to figure out how to draw from this byte array correctly.</p>
  
  <p>This is how I put my texture into the colorbuffer. This works. All the RGB values are the same as the ones in the texture.</p>
  
  <pre><code>    public java.awt.Color[] colorBuffer;
  for (int y = 0; y &lt; image.getHeight(); y++) {
          for (int x = 0; x &lt; image.getWidth(); x++) {
              c = new java.awt.Color(image.getRGB(x, y));
              colorBuffer[y * Width + x] = c;}}
  </code></pre>
  
  <p>now here is how I create my screenbuffer and assign pixels to it:</p>
  
  <pre><code>static byte[] buffer;
  static int screenTexture;
  
  public static void main() {
          buffer = new byte[Display.Height * Display.Width];
          screenTexture = GL11.glGenTextures();
          texture = new Sprite(new Vector2f(0, 0), "src/Content/Textures/tex1.bmp");
  }
  
  // in the raycasting algorithm:
  buffer[y * Display.Width + x] = (byte) texture.colorBuffer[texY * texture.Width + texX].getRed();
                  buffer[y * Display.Width + x + 1] = (byte) texture.colorBuffer[texY * texture.Width + texX].getGreen();
                  buffer[y * Display.Width + x + 2] = (byte) texture.colorBuffer[texY * texture.Width + texX].getBlue();
                  buffer[y * Display.Width + x + 3] = (byte) texture.colorBuffer[texY * texture.Width + texX].getAlpha();
  </code></pre>
  
  <p>and here is how I draw the buffer:</p>
  
  <pre><code>org.newdawn.slick.Color.white.bind();
          ByteBuffer b = BufferUtils.createByteBuffer(buffer.length * 4); // times four due to every pixel having RGBA.
          for (int a = 0; a &lt; buffer.length; a++) {
              b.put(a, buffer[a]);
          }
          GL11.glBindTexture(GL11.GL_TEXTURE_2D, 2);
          GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, Display.Width / 4, Display.Height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, b);
  
          GL11.glBegin(GL11.GL_QUADS);
          {
              GL11.glTexCoord2f(0, 0);
              GL11.glVertex2f(0, 0);
  
              GL11.glTexCoord2f(1, 0);
              GL11.glVertex2f(Display.Width, 0);
  
              GL11.glTexCoord2f(1, 1);
              GL11.glVertex2f(Display.Width, Display.Height);
  
              GL11.glTexCoord2f(0, 1);
              GL11.glVertex2f(0, Display.Height);
          }
          GL11.glEnd();
  </code></pre>
  
  <p>Now, say if I create a texture which are 3 vertical lines: red, green and blue. It will make the red one white and the others pitchblack, as well as adding a few colors to the texture the further it is in the distance.</p>
  
  <p>Here is an image of what it looks like. The paint file is the original texture, and the right window is the raycaster.</p>
  
  <p><a href="http://i.imgur.com/f9jRlPX.png" rel="nofollow">image</a></p>
  
  <p>Does anyone know how to solve this issue?</p>