LWJGL
May 23, 2012, 04:07:37 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Texture clamping  (Read 4977 times)
Erestar
Newbie
*
Posts: 27


WWW
« on: July 28, 2004, 12:09:42 »

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.

Code:
/*
 * 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);
  }
}
Logged
princec
Nerdus Imperius
*****
Posts: 1782



WWW
« Reply #1 on: July 28, 2004, 12:58:40 »

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 Smiley
Logged

Erestar
Newbie
*
Posts: 27


WWW
« Reply #2 on: July 28, 2004, 13:13:20 »

Thanks for the reply Cas Smiley

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?

Thanks,
  Ere
Logged
elias
Nerdus Imperius
*****
Posts: 899



WWW
« Reply #3 on: July 28, 2004, 15:42:57 »

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

 - elias
Logged

Erestar
Newbie
*
Posts: 27


WWW
« Reply #4 on: July 29, 2004, 09:15:54 »

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:

Code:
     GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
Logged
princec
Nerdus Imperius
*****
Posts: 1782



WWW
« Reply #5 on: July 30, 2004, 02:41:18 »

Whoops Smiley
Found a bug in SPGL for me, too Tongue

Cas Smiley
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!