Using the code below to load mipmaps, get a "0" at the print statement so assume the load went fine. But no texture shows up, which the opengl book says is what happens when opengl is not happy with your mipmap params. See what the problem might be?
public static int loadMipMaps(String path) {
IntBuffer buf = ByteBuffer.allocateDirect(4).order(
ByteOrder.nativeOrder()).asIntBuffer();
IntBuffer image = ByteBuffer.allocateDirect(4).order(
ByteOrder.nativeOrder()).asIntBuffer();
IL.ilGenImages(image);
IL.ilBindImage(image.get(0));
IL.ilLoadImage(path);
IL.ilConvertImage(IL.IL_RGB, IL.IL_BYTE);
ByteBuffer scratch = ByteBuffer.allocateDirect(IL
.ilGetInteger(IL.IL_IMAGE_WIDTH)
* IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 3);
IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL
.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGB,
IL.IL_BYTE, scratch);
// Create A IntBuffer For Image Address In Memory
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_MIPMAP_NEAREST);
// Linear Filtering
GL11.glTexParameteri(GL11.GL_TEXTURE_2D,
GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
// Set mipmaps to use
GL.glTexParameterf(GL11.GL_TEXTURE_2D,
GL12.GL_TEXTURE_MIN_LOD, 0.5f);
GL.glTexParameterf(GL11.GL_TEXTURE_2D,
GL12.GL_TEXTURE_MAX_LOD, 1.5f);
// Generate The Textures
int test = GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, GL11.GL_RGB,
IL.ilGetInteger(IL.IL_IMAGE_WIDTH),
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), GL11.GL_RGB,
GL11.GL_UNSIGNED_BYTE, scratch);
System.out.println("MM Test "+test);
return buf.get(0);
}
This only gives me one index is that correct?
Thanks,
Jim
Yes, it gives you one index, but should handle mipmapping with it. This is my simplest code for mipmapping and is working fine:
private int loadTextureIL_MIP_RGB(String path) {
IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
IL.ilGenImages(image);
IL.ilBindImage(image.get(0));
IL.ilLoadImage(path);
IL.ilConvertImage(IL.IL_RGB, IL.IL_BYTE);
ByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 3);
IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGB, IL.IL_BYTE, scratch);
// Create A IntBuffer For Image Address In Memory
IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
GL11.glGenTextures(buf); // Create Texture In OpenGL
GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
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_MIPMAP_LINEAR);
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 3, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), IL.IL_RGB, GL11.GL_UNSIGNED_BYTE, scratch);
return buf.get(0);
}
Only big difference is in your LOD parameter, so try to comment it out and see.....
hvor,
Thanks for the help, it seems as though my problem is not so much in the texture loading as in the texture state management in the rest of my code.
Jim