在特定条件下更改对象上的纹理

时间:2014-01-30 09:13:14

标签: java opengl textures jogl

我在Jogl中遇到纹理问题。我画了一个书架,当检测到架子标记时,纹理应该改变。到目前为止,这是我的代码:

    Texture book;

    if (Library.touchTime != 0 && Library.marked.equals(name)){
        long actTime = System.currentTimeMillis();
        if (actTime - Library.touchTime <= 2000){
            this.book = books_marked;
        }
        else{
            Library.touchTime = 0;
            Library.marked = "";
            this.book = books;
        }
    }
    book.enable();
    book.bind();

//---- front --------------------------------------------------
    gl.glBegin(GL.GL_QUADS);
        normVector = front.getNorm();
        gl.glNormal3f(normVector.getX(), normVector.getY(), normVector.getZ());
        drawRect(gl, 0, 1, 2, 3);
    gl.glEnd();

Objects books和books_marked是构造函数的参数,并按如下方式创建:

// ---- Load Book Texture -----------------------------------------------
    try {
        InputStream stream = getClass().getResourceAsStream("books.jpg");
        data = TextureIO.newTextureData(stream, false, "jpg");
        books = TextureIO.newTexture(data);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

// -------------------------------------------------------------
// ---- Load Book_marked Texture -------------------------------------
    try {
        InputStream stream = getClass().getResourceAsStream("books_marked.jpg");
        data = TextureIO.newTextureData(stream, false, "jpg");
        books_marked = TextureIO.newTexture(data);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

// -------------------------------------------------------------------------    

我的目的是在if条件下实现Texture-Object一书,以便bind()命令自动绑定正确的Picture。但纹理不会改变。有谁知道我在这里弄错了什么?

1 个答案:

答案 0 :(得分:0)

调用Texture.bind(GL)或glBindTexture。