title: Why texture is displayed with the wrong color
body: <p>I'm rendering a skybox with a cube texture. But the color of the texture turned out to be wrong. The code below is used to load images. Is that because of the GL_RGB format? Any ideas about that?</p>
  
  <pre><code>protected void loadImageData()
  {
      String fileDir;
  
      for (int i = 0; i &lt; 6; i++)
      {
          fileDir = "images/skybox/sky" + (i + 1) + ".jpg";
  
          try
          {
              BufferedImage image = ImageIO.read(new File(fileDir));
              byte[] data = ((DataBufferByte) image.getData().getDataBuffer()).getData();
              imageBuff[i] = GLBuffers.newDirectByteBuffer(data);
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>setup texture:</p>
  
  <pre><code>    loadImageData();
  
      gl.glGenTextures(1, cubeTexBuff);
      gl.glBindTexture(GL4.GL_TEXTURE_CUBE_MAP, cubeTexBuff.get(0));
  
      gl.glTexStorage2D(GL4.GL_TEXTURE_CUBE_MAP, 0, GL4.GL_RGB8, imageSize, imageSize);
  
      for (int i = 0; i &lt; 6; i++)
      {
          gl.glTexImage2D(GL4.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL4.GL_RGB8, 
                  imageSize, imageSize, 0, GL4.GL_RGB, GL4.GL_UNSIGNED_BYTE, imageBuff[i]);
      }
  
      gl.glTexParameteri(GL4.GL_TEXTURE_CUBE_MAP, GL4.GL_TEXTURE_MAG_FILTER, GL4.GL_LINEAR);
      gl.glTexParameteri(GL4.GL_TEXTURE_CUBE_MAP, GL4.GL_TEXTURE_MIN_FILTER, GL4.GL_LINEAR);
  </code></pre>
  
  <p>Original image:
  <img src="https://i.stack.imgur.com/05XWh.jpg" alt="original image"></p>
  
  <p>Mapping result:
  <img src="https://i.stack.imgur.com/YQJf4.png" alt="result with wrong color"></p>
  
  <p>updated:</p>
  
  <p>with this alternative provided: <a href="https://github.com/elect86/modern-jogl-examples/blob/master/modern-jogl-examples/src/tut16/gammaRamp/GammaRamp.java#L221-233" rel="nofollow noreferrer">enter link description here</a> the color turns out to be correct finally, yet still a small problem (the direction becomes opposite), see the result below:</p>
  
  <pre><code>    String fileDir;
      TextureData texData = null;
  
      for (int i = 0; i &lt; 6; i++)
      {
          fileDir = "images/skybox/sky" + (i + 1) + ".jpg";
  
          try
          {
              texData = TextureIO.newTextureData(gl.getGLProfile(), 
                      new File(fileDir), false, TextureIO.JPG);
  
              texDataBuff[i] = texData.getBuffer();
              texDataBuff[i].rewind();
  
              //notice that the image used for skybox must be square
              imageSize = texData.getHeight();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
      }
  
      gl.glGenTextures(1, cubeTexBuff);
      gl.glBindTexture(GL4.GL_TEXTURE_CUBE_MAP, cubeTexBuff.get(0));
  
      gl.glTexStorage2D(GL4.GL_TEXTURE_CUBE_MAP, 0, GL4.GL_RGB8, imageSize, imageSize);
  
      for (int i = 0; i &lt; 6; i++)
      {
          gl.glTexImage2D(GL4.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL4.GL_RGB8, 
                  imageSize, imageSize, 0, texData.getPixelFormat(), texData.getPixelType(), texDataBuff[i]);
      }
  
      gl.glTexParameteri(GL4.GL_TEXTURE_CUBE_MAP, GL4.GL_TEXTURE_MAG_FILTER, GL4.GL_LINEAR);
      gl.glTexParameteri(GL4.GL_TEXTURE_CUBE_MAP, GL4.GL_TEXTURE_MIN_FILTER, GL4.GL_LINEAR);
  </code></pre>
  
  <p>original image:</p>
  
  <p><img src="https://i.stack.imgur.com/nel7g.jpg" alt="enter image description here"></p>
  
  <p>mapping result:</p>
  
  <p><img src="https://i.stack.imgur.com/Q7NAB.png" alt="enter image description here"></p>