2014-12-30 25 views
0

我使用的是2-3周前下載的Jogl 10-Oct-2014版本。我不能輕易找到實際的版本號,所以我希望這足以指導一個答案。Jogl推/爆矩陣和顏色

我的問題是我似乎無法找到推動和彈出一種顏色的方法。一個小小的代碼來指導這個問題。

我有一個小方法來繪製一個正方形;

protected void   linear (GL2 gl 
            ,double ax,double ay,double az 
            ,double bx,double by,double bz 
            ) 
{ 
    gl.glBegin(GL.GL_LINES); 
    gl.glVertex3d(ax,ay,az); 
    gl.glVertex3d(bx,by,bz); 
    gl.glEnd(); 
} 

這是從一個渲染方法稱爲像這樣

protected void    render(GL2 gl) 
{ 
    /* 
    * glPushMatrix not for color 
    * glPushattrib(GL2.GL_COLOR) not for color 
    * gl.glPushAttrib(GL2.GL_COLOR_BUFFER_BIT) not for color 
    */ 
    //  gl.glPushMatrix(); 
    //  gl.glPushAttrib(GL2.GL_COLOR_BUFFER_BIT); 
    //  gl.glPushAttrib(GL2.GL_COLOR); 
    gl.glColor3d(0.0,0.0,1.0); 
    linear(gl,0,0,0, 1, 1,0); 
    //  gl.glPopAttrib(); 
    //  gl.glPopMatrix(); 

    // force reset of color because either it is not part of the matrix or the matrix is buggy 
    gl.glColor3d(1.0,1.0,1.0); 
    linear(gl,0,0,0, 1,-1,0); 

}

最後此呈現方法從正常顯示方法調用。

public  void   display(GLAutoDrawable drawable) 
{ 
    GL2 gl = drawable.getGL().getGL2(); 

    // Clear screen. 
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); 

    // Make sure the correct matrix is loaded prior to rendering 
    //  gl.glMatrixMode(GL2.GL_MODELVIEW); 
    gl.glLoadIdentity(); 

    render(gl); 

    // ensure all gl command are executed and the display updated nothing left in the pipeline 
    gl.glFlush(); 
} 

問題是用來嘗試推送和彈出顏色的三種替代方法都不工作。如果在彈出操作(矩陣或屬性)後沒有手動重置顏色,顏色將保持與最後使用的顏色相同。

推/彈出工程的變換,所以我認爲我正確使用它們,但顏色沒有。我還嘗試了其他任何屬性,這是我第一次嘗試,而我正在學習Jogl。到目前爲止,多於礦井。

我已經複製了一些代碼片段,並試圖使用那些具有相同效果的代碼片段。所以現在我很難過。

線索,提示或伴隨的笑聲表示讚賞。

+0

喜傑夫,你應該避免遺留的OpenGL – elect

回答