-1

I am trying to apply texture filter repeat to my cube but I am not able to fix the issue

Could anyone help me with this

Here is my piece of code

import java.io.IOException;
import java.io.InputStream;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;

import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;

/**
 * Box.java - a class implementation representing a Box object in OpenGL Oct 16,
 * 2013 rdb - derived from Box.cpp
 */

public class BoxNew extends Object3D {
    // --------- instance variables -----------------
    float length;

    // float replication = 1.0f; // # copies of texture on quad in each
    // direction
    // float offset = 0.0f;
    // Texture tex;

    // ------------- constructor -----------------------
    public BoxNew() {
        length = 1;
    }

    // ------------- drawPrimitives ---------------------------
    public void drawPrimitives() {


        JOGL.gl.glPushMatrix();
        JOGL. gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
        tex=setTexture("picc.jpg");
        tex.enable(JOGL.gl);
        //tex.setTexParameteri(JOGL.gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
        //tex.setTexParameteri(JOGL.gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);  
        tex.setTexParameteri(JOGL.gl, GL2.GL_REPEAT,GL2.GL_TEXTURE_WRAP_T);

        tex.bind(JOGL.gl);

        JOGL.gl.glBegin(GL2.GL_QUADS);
        // Front Face
        JOGL.gl.glNormal3f(0.0f, 0.0f, 1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 0.0f);
        JOGL.gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 0.0f);
        JOGL.gl.glVertex3f(1.0f, -1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 1.0f);
        JOGL.gl.glVertex3f(1.0f, 1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 1.0f);
        JOGL.gl.glVertex3f(-1.0f, 1.0f, 1.0f);
        // Back Face
        JOGL.gl.glNormal3f(0.0f, 0.0f, -1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 0.0f);
        JOGL.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 1.0f);
        JOGL.gl.glVertex3f(-1.0f, 1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 1.0f);
        JOGL.gl.glVertex3f(1.0f, 1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 0.0f);
        JOGL.gl.glVertex3f(1.0f, -1.0f, -1.0f);
        // Top Face
        JOGL.gl.glNormal3f(0.0f, 1.0f, 0.0f);
        JOGL.gl.glTexCoord2f(0.0f, 1.0f);
        JOGL.gl.glVertex3f(-1.0f, 1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 0.0f);
        JOGL.gl.glVertex3f(-1.0f, 1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 0.0f);
        JOGL.gl.glVertex3f(1.0f, 1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 1.0f);
        JOGL.gl.glVertex3f(1.0f, 1.0f, -1.0f);
        // Bottom Face
        JOGL.gl.glNormal3f(0.0f, -1.0f, 0.0f);
        JOGL.gl.glTexCoord2f(1.0f, 1.0f);
        JOGL.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 1.0f);
        JOGL.gl.glVertex3f(1.0f, -1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 0.0f);
        JOGL.gl.glVertex3f(1.0f, -1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 0.0f);
        JOGL.gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        // Right face
        JOGL.gl.glNormal3f(1.0f, 0.0f, 0.0f);
        JOGL.gl.glTexCoord2f(1.0f, 0.0f);
        JOGL.gl.glVertex3f(1.0f, -1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 1.0f);
        JOGL.gl.glVertex3f(1.0f, 1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 1.0f);
        JOGL.gl.glVertex3f(1.0f, 1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 0.0f);
        JOGL.gl.glVertex3f(1.0f, -1.0f, 1.0f);
        // Left Face
        JOGL.gl.glNormal3f(-1.0f, 0.0f, 0.0f);
        JOGL.gl.glTexCoord2f(0.0f, 0.0f);
        JOGL.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 0.0f);
        JOGL.gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(1.0f, 1.0f);
        JOGL.gl.glVertex3f(-1.0f, 1.0f, 1.0f);
        JOGL.gl.glTexCoord2f(0.0f, 1.0f);
        JOGL.gl.glVertex3f(-1.0f, 1.0f, -1.0f);
        JOGL.gl.glEnd();
        JOGL.gl.glPopMatrix();

        tex.disable(JOGL.gl);

    }
}
genpfault
  • 51,148
  • 11
  • 85
  • 139

2 Answers2

1

1.) Your parameters in setTexParameteri are reversed.

 tex.setTexParameteri(JOGL.gl, GL2.GL_REPEAT,GL2.GL_TEXTURE_WRAP_T);

should be

 tex.setTexParameteri(JOGL.gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);

Did you check somewhere for gl errors?

2.) Since your texture-coordinates are always in range [0, 1] you will not see anything of the wrap-mode. Wrap mode only define how texturecoordinates outside of the [0,1] range are handled.

BDL
  • 21,052
  • 22
  • 49
  • 55
  • Thank you so much SO my texture cords should be with range above [0, 1] like that : No i dnt have any errors i am getting a cube but the repeat is not working –  Oct 29 '14 at 13:20
  • If you want to have repetitions, then yes. Texture-Coordinates in repeat mode are given by lookup_uv = fract(uv) – BDL Oct 29 '14 at 13:23
0

I am not familiar with how JOGL manages state for its texture class (some important details are hidden here), but traditionally in GL you cannot set parameters such as the texture filter or repeat mode until after you bind the texture.

You might consider altering your code this way:

    tex=setTexture("picc.jpg");
    tex.enable(JOGL.gl);

    /* Bind First */

    tex.bind(JOGL.gl);

    /* Then Set States */

    //tex.setTexParameteri(JOGL.gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
    //tex.setTexParameteri(JOGL.gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);  
    tex.setTexParameteri(JOGL.gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
    tex.setTexParameteri(JOGL.gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);

I also took the liberty of setting the texture repeat mode for the S coordinate direction too. Your code as it was originally written would only repeat in the T direction.

Community
  • 1
  • 1
Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106