Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在特定条件下更改对象上的纹理_Java_Opengl_Textures_Jogl - Fatal编程技术网

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

Java 在特定条件下更改对象上的纹理,java,opengl,textures,jogl,Java,Opengl,Textures,Jogl,我对Jogl中的纹理有问题。我画了一个书架,当书架被检测到有标记时,纹理应该改变。以下是我目前的代码: Texture book; if (Library.touchTime != 0 && Library.marked.equals(name)){ long actTime = System.currentTimeMillis(); if (actTime - Library.touchTime <= 2000){

我对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();

我的目的是在if条件中实例化book纹理对象,以便bind()命令将自动绑定正确的图片。但是纹理没有改变。有人知道我这里出了什么问题吗?

调用Texture.bind(GL)或glBindTexture。

你确定你的
if
-条件实际按预期工作了吗?是的,我确定了。我在控制台上有显示时间运行的输出,因此它工作正常。很抱歉打扰您,但您仍在使用不再维护的JOGL 1。即使它不足以解决您的问题,也要切换到JOGL2。
// ---- 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);
    }

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