纹理过滤器在JOGL中不起作用

时间:2014-10-29 12:02:49

标签: java opengl jogl

我正在尝试将纹理过滤器重复应用到我的多维数据集,但我无法解决问题

任何人都可以帮助我吗

这是我的一段代码

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

    }
}

2 个答案:

答案 0 :(得分:1)

1。)setTexParameteri中的参数是相反的。

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

应该是

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

你在某地检查了gl错误吗?

2。)由于纹理坐标始终在[0,1]范围内,因此您将看不到任何包裹模式。换行模式仅定义如何处理[0,1]范围之外的纹理坐标。

答案 1 :(得分:0)

我不熟悉JOGL如何为其纹理类管理状态(这里隐藏了一些重要的细节),但传统上在GL中你不能设置参数,如纹理过滤器或重复模式,直到 之后绑定 纹理。

您可以考虑以这种方式更改代码:

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

我也冒昧地为S坐标方向设置纹理重复模式。您最初编写的代码只会在T方向重复。