Hi All,
I’m seeing my mipmapped textures corrupted with unexpected colours (usually bright red). The corruption seems to be occuring in the
2x2 or possibly 1x1 mipmap levels. All the other levels seem OK.
This happens on both Win32 and Solaris9, so I suspect it’s not a driver problem. If anyone can suggest anything wrong with my texture loading code, I’d appreciate the feedback. Note that this code is overriding all mipmap data to be white pixels, and I’m still seeing the unexpected ‘red’.
If anyone can explain to me how to attach a screen grab here, I’ll happily show what I’m seeing.
(Apologies for the indentation of the attached)
Code follows:
private void init(Texture2D t,GL gl) {
//
// Convert the BufferedImages to buffers that JOGL can deal with
//
BufferedImage[] images = t.getImages();
buffers = new ByteBuffer[images.length];
for (int i = 0; i < images.length; i++) {
switch(images[i].getType()) {
case BufferedImage.TYPE_INT_ARGB: {
int[] data = ((DataBufferInt)
images[i].getRaster().getDataBuffer()).getData();
buffers[i] = ByteBuffer.allocateDirect(data.length * 3);
byte[] b = new byte[3];
int h = images[i].getHeight();
int w = images[i].getWidth();
// We must invert the image
for (int y = h - 1; y >= 0; y--) {
for (int x = 0; x < w; x++) {
int index = y * w + x;
int val = data[index];
int blue = val & 0xff;
int green = (val >> 8) & 0xff;
int red = (val >> 16) & 0xff;
b[0] = (byte)red;
b[1] = (byte)green;
b[2] = (byte)blue;
//
// Debug - override the supplied data
// with WHITE
//
b[0] = (byte)0xff;
b[1] = (byte)0xff;
b[2] = (byte)0xff;
buffers[i].put(b);
}
}
break;
}
default:
System.out.println("Unsupported image type " +
images[i].getType());
System.exit(-1);
}
}
//
// Allocate a texture id
//
textureID = createTextureID();
bind(gl);
gl.glTexParameteri( GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_WRAP_S,
GL.GL_REPEAT);
gl.glTexParameteri( GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_WRAP_T,
GL.GL_REPEAT);
gl.glTexParameteri( GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MIN_FILTER,
GL.GL_LINEAR_MIPMAP_LINEAR); // Check this
gl.glTexParameteri( GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MAG_FILTER,
GL.GL_LINEAR); // Check this
//
//
//
for (int i = 0; i < buffers.length; i++) {
gl.glTexImage2D(GL.GL_TEXTURE_2D,
i,
GL.GL_RGB,
images[i].getWidth(),
images[i].getHeight(),
0, // border width
GL.GL_RGB,
GL.GL_UNSIGNED_BYTE,
buffers[i]);
}
}
protected void bind(GL gl) {
gl.glBindTexture(GL.GL_TEXTURE_2D, textureID );
}