2016-04-29 39 views
1
public class SimpleJOGL2 implements GLEventListener { 

    private float x = 0.5f; 
    private float y = -0.5f; 
    public static void main(String[] args) { 
     Frame frame = new Frame("Simple JOGL Application"); 
     GLCanvas canvas = new GLCanvas(); 


     canvas.addGLEventListener(new SimpleJOGL2()); 
     frame.add(canvas); 
     frame.setSize(640, 640); 
     final Animator animator = new Animator(canvas); 
     frame.addWindowListener(new WindowAdapter() { 

      @Override 
      public void windowClosing(WindowEvent e) { 
       // Run this on another thread than the AWT event queue to 
       // make sure the call to Animator.stop() completes before 
       // exiting 
       new Thread(new Runnable() { 

        public void run() { 
         animator.stop(); 
         System.exit(0); 
        } 
       }).start(); 
      } 
     }); 
     // Center frame 
     frame.setLocationRelativeTo(null); 
     frame.setVisible(true); 
     animator.start(); 
    } 

而且......爲什麼可以顯示的多邊形但有一點不能

public void display(GLAutoDrawable drawable) { 

    GL gl = drawable.getGL(); 


    float a[][] = {{x,y},{x,y-0.05f},{x-0.2f,y-0.15f},{x-0.22f, y-0.17f}}; 
    float b[][] = {{x,y},{x,y-0.05f},{x+0.2f,y-0.15f},{x+0.22f, y-0.17f}}; 
    float c[][]= {{x+0.03f,y-0.25f},{x-0.03f,y-0.25f},{x-0.03f,y-0.4f},{x+0.03f,y-0.4f}}; 
    float col[] ={230/255f,84/255f,109/255f}; 
    drawPolygon(gl,a,col); 
    drawPolygon(gl,b,col); 
    drawPolygon(gl,c,col); 

    gl.glLoadIdentity(); 
    gl.glColor3f(0,0,0); 
    gl.glPointSize(4.0f); 
    gl.glBegin(GL.GL_POINT); 
     gl.glVertex2f(x+0.015f, y-0.33f); 
    gl.glEnd(); 
    gl.glFlush(); 


    } 

我想提請面和點。多邊形可以顯示,但點不能。

public void drawPolygon(GL gl, float a[][], float col[]){ 
     gl.glColor3f(col[0], col[1], col[2]); 
     gl.glBegin(GL.GL_POLYGON); 
      gl.glVertex2f(a[0][0], a[0][1]); 
      gl.glVertex2f(a[1][0], a[1][1]); 
      gl.glVertex2f(a[2][0], a[2][1]); 
      gl.glVertex2f(a[3][0], a[3][1]); 

     gl.glEnd(); 
    } 

} 
+2

它是GL_POINTS,而不是GL_POINT。 – gouessej

回答

0

您好,歡迎#2 :)

該代碼使用過時的OpenGL功能,我們強烈建議不使用那些除非在特殊情況下,我認爲這不是你的情況。

當前的OpenGL實際上允許原語三種tipes:

  • GL_TRIANGLES
  • GL_POINTS
  • GL_LINES

如果您想了解更多關於這一點,你可以閱讀wiki

無論如何,對於初學者來說,最好從一個簡單的Hello Triangle開始,比如我的these ones,然後用它作爲基礎。

所以,如果你想顯示任何一種多邊形的,你應該把它在三角形,並使其通過三角形爲基本類型

如果您需要進一步的幫助,不要猶豫問,良好的工作!

相關問題