Hey guys,
I haven't messed with LWJGL since earler this year, and now I'm porting everything from .8 to .9. Aside from this, I've switched to Linux.
The problem I'm having now is that my skybox is ending up with lines around the quads, whereas before they were clamping fine all the way to the edges and blending seemlessly.
I was wondering if anyone could look at my texture loader and see if anything is obviously screwed up, as I've been away from this for so long I might be not remembering correctly, or I screwed something up in the LWJGL conversion.
/*
* TextureLoader.java
*
* Created on January 27, 2004, 2:19 AM
*/
package net.erestar.glutil;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.glu.GLU;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.lwjgl.util.vector.Vector3f;
/**
*
* @author Jim Podroskey
*/
public final class TextureLoader {
private TextureLoader() { }
/* clamping support added to make skybox lookbetter */
public static int load(String path) {
return load(path, false);
}
public static int load(String path, boolean clamp) {
BufferedImage img = null;
try {
img = ImageIO.read(new File(path));
}
catch(Exception e) {
e.printStackTrace();
}
// Flip Image vertically because Java's coords system are different from openGls
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -img.getHeight(null));
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.
TYPE_NEAREST_NEIGHBOR);
img = op.filter(img, null);
ByteBuffer bb = ByteBuffer.allocateDirect(4 * img.getWidth() * img.getHeight());
bb.clear();
bb.put((byte[]) img.getRaster().getDataElements(0, 0, img.getWidth(), img.getHeight(), null));
bb.rewind();
IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
GL11.glGenTextures(buf);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
if(clamp) {
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
}
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 3, img.getWidth(), img.getHeight(),
GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, bb);
return buf.get(0);
}
public static void bind(int textureIndex) {
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIndex);
}
public static void bind2(int textureIndex) {
GL13.glActiveTexture(GL13.GL_TEXTURE1);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIndex);
}
}