2012-03-01 53 views
1

我想学习JOGL,但在画布上首先画线(如边框)​​,但我无法弄清楚为什么我的线条不显示!我猜测我没有正确设置我的视口。JOGL不知道为什么画线不出现

下面是一些代码片段:

private static final float DISTANCE_FROM_EDGE = 25.0f; 

@Override 
public void init(GLAutoDrawable drawable) 
{ 
    GL2 gl = drawable.getGL().getGL2(); 
    drawable.setGL(new DebugGL2(gl.getGL2())); 

    m_glu = new GLU(); 

    establishProjectionMatrix(gl , getWidth(), getHeight()); 

    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);   
    gl.glEnable(GL2.GL_TEXTURE_2D); 
} 

@Override 
public void reshape(GLAutoDrawable drawable, 
        int x, 
        int y, 
        int width, 
        int height) 
{ 
    GL2 gl = drawable.getGL().getGL2(); 
    establishProjectionMatrix(gl , width, height); 
} 

public void establishProjectionMatrix(GL2 gl,int width,int height) 
{ 

    gl.glViewport(0, 0, width, height); 

    gl.glMatrixMode(GL2.GL_PROJECTION); 
    gl.glLoadIdentity(); 

    m_glu.gluOrtho2D(0,width,height,0); 
} 

@Override 
public void display(GLAutoDrawable drawable) 
{ 
    update(); 
    GL2 gl = drawable.getGL().getGL2(); 
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT); 
    gl.glMatrixMode(GL2.GL_MODELVIEW); 
    gl.glLoadIdentity(); 
    drawBoundary(gl); 

} 

public void drawBoundary(GL2 gl) 
{ 
    gl.glPushMatrix(); 
    gl.glTranslatef(10.0f, 10.0f, 0.0f); 
    gl.glColor3f(0.0f, 0.1f, 0.0f); 
    //Draw left edge 
    drawLine(gl, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE); 
    //Draw top edge 
    drawLine(gl, -DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE); 
    //Draw right edge 
    drawLine(gl, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE); 
    //Draw bottom edge 
    drawLine(gl, DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE); 
    gl.glPopMatrix(); 
} 

private void drawLine(GL2 gl, float x1,float y1, float x2, float y2) 
{ 
    gl.glBegin(GL.GL_LINES); 
    gl.glVertex2f((x1), (y1)); 
    gl.glVertex2f((x2), (y2)); 
    gl.glEnd(); 
} 
+0

Hi @Foo,你还需要帮助吗? – elect 2015-08-12 08:18:51

回答

1

是否启用双缓冲?渲染后请尝试拨打drawable.swapBuffers()

+0

我不相信它的启用..我试图在显示方法的末尾做'drawable.swapBuffers()'方法,但没有任何差异。 – Foo 2012-03-01 01:17:15