Login  Register

Re: JOGL GL2.GL_REPEAT

Posted by Demoscene Passivist on Nov 06, 2011; 1:49am
URL: https://forum.jogamp.org/JOGL-GL2-GL-REPEAT-tp3483478p3483879.html

It's quite simple to endlessly repeat a texture using the JOGL Texture class.

E.g. take one of my routines wich render a fullscreen billboard: GL3_AnalogDistortions.java

Change the init method to this, explicitly setting the texture border mode:

    public void init_FBORenderer(GL2 inGL,GLU inGLU,GLUT inGLUT) {
        mTexture_Diffuse = TextureUtils.loadImageAsTexture_UNMODIFIED(inGL,"/binaries/textures/Wallpaper_JOGAMP_MyJapanHoliday_03_1920pel.png");
        mTexture_Diffuse.setTexParameterf(inGL,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        mTexture_Diffuse.setTexParameterf(inGL,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        mTexture_Diffuse.setTexParameterf(inGL,GL_TEXTURE_WRAP_S,GL_REPEAT);
        mTexture_Diffuse.setTexParameterf(inGL,GL_TEXTURE_WRAP_T,GL_REPEAT);
    }

(its done already implicitly in my utility method, but to make things clear I set it here "once more")

Also change the texture coordinates of the billboard to a "double span" vom range 0.0-2.0 instead of the "normal" 0.0-1.0:

        inGL.glBegin(GL_QUADS);
            inGL.glTexCoord2f(0.0f, 0.0f);
            inGL.glVertex2f(0.0f, 0.0f);
            inGL.glTexCoord2f(2.0f, 0.0f);
            inGL.glVertex2f(mBaseFrameBufferObjectRendererExecutor.getWidth(), 0.0f);
            inGL.glTexCoord2f(2.0f, 2.0f);
            inGL.glVertex2f(mBaseFrameBufferObjectRendererExecutor.getWidth(), mBaseFrameBufferObjectRendererExecutor.getHeight());
            inGL.glTexCoord2f(0.0f, 2.0f);
            inGL.glVertex2f(0.0f, mBaseFrameBufferObjectRendererExecutor.getHeight());
        inGL.glEnd();

... this gives u a 2x2 (4 times) repeated texture