jogl GLEventListener.display()不绘制

时间:2015-08-26 05:19:55

标签: java jogl

我已经像教程一样设置了这个项目。它创建一个窗口,但不绘制任何东西,它使用opengl 2.0与jogl。     包f8fGLbase;

import java.util.ArrayList;

import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLEventListener;

public class f8fGLRenderer implements GLEventListener{

ArrayList<f8fGLDrawable> mDrawList=null;

public ArrayList<f8fGLDrawable> getDrawList() {
    return mDrawList;
}

public void setDrawList(ArrayList<f8fGLDrawable> mDrawList) {
    this.mDrawList = mDrawList;
}
public void addDrawList(f8fGLDrawable Drawable) {
    this.mDrawList.add(Drawable);
}
public void removeDrawList(f8fGLDrawable Drawable) {
    this.mDrawList.remove(Drawable);
}

@Override
public void display(GLAutoDrawable gLDrawable) {
    // TODO Auto-generated method stub
    final GL2 gl = gLDrawable.getGL().getGL2();

    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(-1.5f, 0.0f, -6.0f);
    gl.glColor3f(1.0f, 1.0f, 0.0f);

    gl.glBegin(GL2.GL_TRIANGLES);       
    gl.glVertex3f(0.0f, 1.0f, 0.0f);    
    gl.glVertex3f(-1.0f, -1.0f, 0.0f);  
    gl.glVertex3f(1.0f, -1.0f, 0.0f);   
    gl.glEnd();             
    gl.glTranslatef(3.0f, 0.0f, 0.0f);
    gl.glBegin(GL2.GL_QUADS);               
    gl.glVertex3f(-1.0f, 1.0f, 0.0f);   
    gl.glVertex3f(1.0f, 1.0f, 0.0f);    
    gl.glVertex3f(1.0f, -1.0f, 0.0f);   
    gl.glVertex3f(-1.0f, -1.0f, 0.0f);  
    gl.glEnd();             
    gl.glFlush();
}

@Override
public void dispose(GLAutoDrawable arg0) {
    // TODO Auto-generated method stub

}

@Override
public void init(GLAutoDrawable arg0) {
    // TODO Auto-generated method stub
    System.out.println("init() called");
    GL2 gl = arg0.getGL().getGL2();
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glShadeModel(GL2.GL_FLAT);
}

@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
    // TODO Auto-generated method stub

}

}

这是我打电话来创建窗口的部分,

testMain.java

   package test;

   import java.awt.Graphics;

   import javax.swing.JFrame;

   import com.jogamp.opengl.GLAutoDrawable;
   import com.jogamp.opengl.GLCapabilities;
   import com.jogamp.opengl.GLProfile;
   import com.jogamp.opengl.awt.GLCanvas;

   import f8fGLbase.f8fGLLine;
   import f8fGLbase.f8fGLQuad;
   import f8fGLbase.f8fGLRenderer;

 public class testMain {
JFrame mFrame= null;
Graphics mGraphics=null;

GLProfile mProfile= null;
GLCapabilities mCapabilities= null;
GLCanvas mCanvas= null;
f8fGLLine mLine=null;
public testMain()
{
    start();
}

public void start()
{
    initFrame();

}
private void initFrame()
{
    GLProfile profile = GLProfile.get(GLProfile.GL2);
    GLCapabilities capabilities = new GLCapabilities(profile);

    // The canvas is the widget that's drawn in the JFrame
    mCanvas = new GLCanvas(capabilities);
    mCanvas.addGLEventListener(new f8fGLRenderer());
    mCanvas.setSize( 300, 300 );

    JFrame frame = new JFrame( "Hello World" );
    frame.getContentPane().add( mCanvas);

    frame.setSize( frame.getContentPane().getPreferredSize() );
    frame.setVisible( true );


}

}

main.java       包裹证明;

  import com.jogamp.opengl.awt.GLCanvas;

  import test.testMain;

  public class Main {

   public static void main(String[] args) {
    // TODO Auto-generated method stub

      new testMain();


}

}

0 个答案:

没有答案