When I load my texture using NEHE's texture loader it looks fine but when I do it my way it looks like a whole bunch of red, green and blue pixels fudged all over.
My guess is that my code (below) doesn't get the appropriate colour values?
Or is it something else?
(In C++, reading a file like I have works fine, why not in Java? Assuming the problem is that I'm reading the file)
public final static int loadTextureMod(String path)
{
ImageIcon imgIc = new ImageIcon(path);
Image img = (Image)imgIc.getImage();
BufferedImage bImg = new BufferedImage
(
img.getWidth(null),
img.getHeight(null),
BufferedImage.TYPE_3BYTE_BGR
);
final int fileSize = bImg.getHeight() * bImg.getWidth() * 4;
FileReader fr;
int[] tmpBuff = new int[fileSize];
int i = 0;
try
{
fr = new FileReader(path);
while((tmpBuff[i] = fr.read()) != -1)
{
i++;
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
IntBuffer buf = BufferUtils.createIntBuffer(fileSize);
buf.rewind();
GL11.glGenTextures(buf); // Create Texture In OpenGL
GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
// Typical Texture Generation Using Data From The Image
// Linear Filtering
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
// Linear Filtering
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
// Generate The Texture
GL11.glTexImage2D
(
GL11.GL_TEXTURE_2D,
0,
GL11.GL_RGB,
bImg.getWidth(),
bImg.getHeight(),
0, GL11.GL_RGB,
GL11.GL_UNSIGNED_BYTE,
buf
);
return buf.get(0);
}
That's coz you've specified a GL_RGB image when you have 4 bytes in your source image (GL_RGBA)...
Cas :)
I've fixed it.
A 24bit bitmap graphic has values of:
R8, G8, B8 and A0 = 3 colour channels * 8bits = 24bits per pixel + 0 alpha.
I've fixed my code to reflect that, however it still doesn't work properly.
Now the box has red stripes all over it instead of a pixel mess of RGB. :lol:
What else could be wrong?
Quote from: "K.I.L.E.R"
final int fileSize = bImg.getHeight() * bImg.getWidth() * 4;
[...]
IntBuffer buf = BufferUtils.createIntBuffer(fileSize);
buf.rewind();
GL11.glGenTextures(buf); // Create Texture In OpenGL
I think you've got your buffers mixed up. You're generating a huge number of texture object names in buf, when you only want one. You're then uploading those names to the GL as an image.