Thanks for your time,
here is the method I did from here and there and I used to load a texture, I tried to print the result of this :
System.out.println(bufferedImage.getColorModel());
and I obtained this : (we can clearly see the problem)
ColorModel: #pixelBits = 32 numComponents = 4 color space = java.awt.color.ICC_ColorSpace@67ac19 transparency = 3 has alpha = true isAlphaPre = false
Code :
HashMap<String, BufferedImage> imageDatabase = new HashMap<String, BufferedImage>();
private Texture loadTexture(String path, int xOffSet, int yOffSet,
int width, int height) {
BufferedImage bufferedImage = null;
try {
if (imageDatabase.get(path) != null)
bufferedImage = (BufferedImage) imageDatabase.get(path);
else {
System.out.println("Chargement de l'image : " + path);
bufferedImage = ImageIO.read(new File(path));
imageDatabase.put(path, bufferedImage);
}
} catch (IOException e) {
e.printStackTrace();
}
int bytesPerPixel = bufferedImage.getColorModel().getPixelSize() / 8;
ByteBuffer scratch = ByteBuffer.allocateDirect(
width * height * bytesPerPixel).order(ByteOrder.nativeOrder());
DataBufferByte data = ((DataBufferByte) bufferedImage.getRaster()
.getDataBuffer());
for (int i = 0; i < height; i++)
scratch.put(data.getData(), (xOffSet + (yOffSet + i)
* bufferedImage.getWidth())
* bytesPerPixel, width * bytesPerPixel);
scratch.rewind();
// Create A IntBuffer For Image Address In Memory
IntBuffer buffer = ByteBuffer.allocateDirect(4).order(
ByteOrder.nativeOrder()).asIntBuffer();
GL11.glGenTextures(buffer); // Create Texture In OpenGL
// Create Nearest Filtered Texture
GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffer.get(0));
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
GL11.GL_LINEAR);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height,
0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch);
Texture craftedTexture = new Texture();
craftedTexture.textureId = buffer.get(0);
craftedTexture.textureHeight = height;
craftedTexture.textureWidth = width;
return craftedTexture;
}