PDA

View Full Version : Texture still repeats when I ask it not to



4fingers
11-13-2007, 12:57 PM
I have managed to create a texture as you can see here:
http://img255.imageshack.us/img255/5089/tilepl3.th.png (http://img255.imageshack.us/my.php?image=tilepl3.png)
But despite me specifing the GL_TEXTURE_WRAP as GL_CLAMP it still repeats horizontally.

gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);


Here is my init section

public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
glu = new GLU();
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LESS);

makeCheckImage();
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);

gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 0);

gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, checkImageWidth, checkImageHeight, 0,
GL.GL_RGB, GL.GL_UNSIGNED_BYTE, checkImageBuf);

gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL);
//
gl.glShadeModel(GL.GL_FLAT);
}
Here is where I display the texture

public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(-2.0f, -1.0f, 0.0f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(-2.0f, 1.0f, 0.0f);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(0.0f, 1.0f, 0.0f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(0.0f, -1.0f, 0.0f);

gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(2.41421f, 1.0f, -1.41421f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(2.41421f, -1.0f, -1.41421f);
gl.glEnd();

gl.glFlush();
}
And in case you want to know here is how I create the texture

private void makeCheckImage() {
Color lol = new Color(0.90f, 0.0f, 0.0f);

float colorHSB[] = Color.RGBtoHSB(lol.getRed(), lol.getGreen(), lol.getBlue(), null);
for (int h = 0; h < 4; h++) {
// = h / rt( hsq + a )
float hValue = colorHSB[0]+(((h-2.0f) / (float)Math.sqrt( (float)Math.pow((h-2.0f), 2.0f) + 10.0f/*80*/ ) )*20.0f/*0.1*/);
System.out.println( hValue );
for (int s = 0; s < 128; s++) {
for (int b = 0; b < 128; b++) {
// = (s - 0) / (256 - 0)
Color colorRGB = new Color(Color.HSBtoRGB(hValue, ((s / 128.0f)+1.0f)*0.5f, ((b / 128.0f) +1.0f)*0.5f ));
checkImageBuf.put((byte) (colorRGB.getRed())); // R
checkImageBuf.put((byte) (colorRGB.getGreen())); // G
checkImageBuf.put((byte) (colorRGB.getBlue())); // B
}
}
}
checkImageBuf.rewind();
}
I working in JOGL so sorry for the JAVA code

Any ideas as to why it is still repeating would be great,
Thanks

Humus
11-13-2007, 01:38 PM
You texture coordinates are in [0..1], so CLAMP or REPEAT doesn't matter. CLAMP only matters once you go beyond the [0..1] range.

4fingers
11-13-2007, 01:49 PM
Oh ok so how would I stop it from repearing horizontally? I only create the 4 vertical squares, I see no reason why another colum should be created.

ZbuffeR
11-13-2007, 01:57 PM
A bit of nitpicking :
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP); // this is an integer value, not float

gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); // hey, 0 bytes is really a small granularity :) from the man pages : The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries).

And your texture coords are in the [0,1] range, so you are not able to see texture repeat (or clamp) unless you tweak the texture matrix. I did not look at your texture generation code, maybe it has problem. Try with [-1,2] texcoord range.

4fingers
11-13-2007, 02:12 PM
Thanks ZbuffeR your input was greatly aprecaited.
I never noticed that I was setting the parameters as a float and I copied and pasted the gl.glPixelStorei() without really understanding what it does so thanks for the heads up on that.

Now that I knew that the texture coords were not repeating I decided to look into the texture generation function further like you suggested and so I decided to change this line:


gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, checkImageWidth, checkImageHeight, 0,
GL.GL_RGB, GL.GL_UNSIGNED_BYTE, checkImageBuf);


To this:

gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, checkImageWidth/2, checkImageHeight*2, 0,
GL.GL_RGB, GL.GL_UNSIGNED_BYTE, checkImageBuf);


Then some magic happened
http://img148.imageshack.us/img148/3585/yayqi9.th.png (http://img148.imageshack.us/my.php?image=yayqi9.png)

sqrt[-1]
11-13-2007, 08:21 PM
Also note that you probably don't want to use GL_CLAMP, GL_CLAMP_TO_EDGE is probably what you want.