JOGL Tutorial
JOGL Basic Templates
JOGL Graphical Shapes
JOGL Effects & Transformation
JOGL 3D Graphics
JOGL Useful Resources
Selected Reading
JOGL Basic Templates
- JOGL - GLJPanel Class
- JOGL - Canvas with Swing
- JOGL - Canvas with AWT
- JOGL - API for Basic Templates
JOGL Graphical Shapes
JOGL Effects & Transformation
JOGL 3D Graphics
JOGL Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
JOGL - GLJPanel Class
JOGL - GLJPanel Class
This chapter explains you how to draw a JOGL basic frame using GLJpanel class. It is a pghtweight Swing component which provides OpenGL rendering support. It is provided for compatibipty with Swing. In here we will instantiate a JFrame and add the GLJpanel object to the instance of JFrame using the add() method.
The following program generates a basic frame using GLJPanel with Swing window −
import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabipties; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; pubpc class BasicFrame implements GLEventListener { @Override pubpc void display(GLAutoDrawable arg0) { // method body } @Override pubpc void dispose(GLAutoDrawable arg0) { //method body } @Override pubpc void init(GLAutoDrawable arg0) { // method body } @Override pubpc void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { // method body } pubpc static void main(String[] args) { //getting the capabipties object of GL2 profile final GLProfile profile = GLProfile.get(GLProfile.GL2); GLCapabipties capabipties = new GLCapabipties(profile); // The GLJpanel class GLJPanel gljpanel = new GLJPanel( glcapabipties ); 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
If you compile and execute the above program, the following output is generated. It shows a basic frame formed when we use GLJPanel with swing window −
Advertisements