0
我在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();
對象書籍和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);
}
// -------------------------------------------------------------------------
我的意圖是在如果中實例化的書紋理對象條件,以便bind()命令將自動綁定正確的圖片。但紋理不會改變。有沒有人知道我在這裏弄錯了什麼?
您是否確定您的「if」條件實際上按預期工作? – user1781290
是的,我做到了。我在CONSOL上輸出顯示時間運行,所以它工作正常。 – Raistlin
對不起打擾你,但你仍然使用不再維護的JOGL 1。而是切換到JOGL 2,即使它不足以解決您的問題。 – gouessej