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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| private void init(Texture2D t,GL gl) { 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();
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;
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); } }
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); gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); 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, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, buffers[i]); } }
protected void bind(GL gl) { gl.glBindTexture(GL.GL_TEXTURE_2D, textureID ); } |