目录

JOGL - GLJPanel类( GLJPanel Class)

本章介绍如何使用GLJpanel类绘制JOGL基本框架。 它是一个轻量级的Swing组件,提供OpenGL渲染支持。 它提供与Swing的兼容性。 在这里,我们将实例化一个JFrame,并使用add()方法将GLJpanel对象添加到JFrame的实例中。

以下程序使用带有Swing窗口的GLJPanel生成基本框架 -

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
public class BasicFrame implements GLEventListener {
   @Override
   public void display(GLAutoDrawable arg0) {
      // method body
   }
   @Override
   public void dispose(GLAutoDrawable arg0) {
      //method body
   }
   @Override
   public void init(GLAutoDrawable arg0) {
      // method body
   }
   @Override
   public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
      // method body
   }
   public static void main(String[] args) {
      //getting the capabilities object of GL2 profile
      final GLProfile profile = GLProfile.get(GLProfile.GL2);
      GLCapabilities capabilities = new GLCapabilities(profile);
      // The GLJpanel class
      GLJPanel gljpanel = new GLJPanel( glcapabilities ); 
      BasicFrame b = new BasicFrame();
      gljpanel.addGLEventListener(b);
      gljpanel.setSize(400, 400);
      //creating frame
      final JFrame frame = new JFrame (" Basic Frame");
      //adding canvas to it
      frame.getContentPane().add( gljpanel);
      frame.setSize(frame.getContentPane().getPreferredSize());
      frame.setVisible(true);
   }//end of main
}//end of classimport

如果编译并执行上述程序,则会生成以下输出。 它显示了当我们使用带有摆动窗口的GLJPanel时形成的基本框架 -

基本框架
↑回到顶部↑
WIKI教程 @2018