Texture clamping

Started by Erestar, July 28, 2004, 19:09:42

Previous topic - Next topic


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) {

    // 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,
    img = op.filter(img, null);

    ByteBuffer bb = ByteBuffer.allocateDirect(4 * img.getWidth() * img.getHeight());
    bb.put((byte[]) img.getRaster().getDataElements(0, 0, img.getWidth(), img.getHeight(), null));
    IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
    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) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIndex);
  public static void bind2(int textureIndex) {

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIndex);


Should be

      GL11.glTexParameteri(ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_ARB, GL11.GL_TEXTURE_WRAP_S, ARBTextureBorderClamp.GL_CLAMP_TO_BORDER_ARB);
      GL11.glTexParameteri(ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_ARB, GL11.GL_TEXTURE_WRAP_T, ARBTextureBorderClamp.GL_CLAMP_TO_BORDER_ARB);

Cas :)


Thanks for the reply Cas :)

Sadly, this didn't exactally fix anything... The black 'outline' is gone, but there's still a noticable line between each of the quads, though this one is a very faint whitish blue (which happens to be the main colors of the sky box... Not sure if that has anything to do with it) and when I put that change in the app got really clunky. I haven't tried to get my frame rate controller working yet, so I can't give specifics, but there's a noticable jerkiness that's not there when I change it back.

Any other ideas? Do I have to change anything when I bind to account for the new values I'm passing in?



I'm pretty sure that GL12.GL_CLAMP_TO_EDGE should be used, not CLAMP_TO_BORDER.

- elias


Quote from: "elias"I'm pretty sure that GL12.GL_CLAMP_TO_EDGE should be used, not CLAMP_TO_BORDER.

- elias

You were right elias, thanks !

Here's the combination fo what ended up working:

      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);


Whoops :)
Found a bug in SPGL for me, too :P

Cas :)