First of all, explain how the structure consists of a program written in Java using JOGL libraries. As most of you know, a program written in Java is made only for a minimum of five parts:
- The main class of our program. The
- variables used by the class.
- The constructor of the class. The
- methods that use the class.
- The main method (main) starting the implementation of our program.
So simple program in Java be written about as follows:
/ / We import the packages that we will need
import java.awt. * ; / / For example
/ / Main class public
class MyClass {
/ / Variable 1
/ / Variable 2
/ /. . .
/ / Variable n
/ / Constructor
public MyClass () {
/ * Here we initialize the variables 1, 2,. . ., N
* declared above * /}
/ / Methods that use the class "MyClass"
metodo_1 public void ()
{} public int
metodo_2 () {}
/ /. . .
metodo_n public double () {}
/ / main method
public static void main (String [] args) {
/ * Instantiation of objects of class "MyClass"
* begin code execution * /}
} / / End of class "MyClass"
But as work with OpenGL graphics be necessary to implement the interface known to GLEventListener further that, because we must mount graphics somewhere, we have to extend the class JFrame or JPanel .
GLEventListener interface declares events which are used by client code to handle OpenGL rendering to travez of GLAutodrawable .
To have a clearer idea, something similar happens when you implement the interface ActionListener to hear the events of the buttons which are handled by client code via ActionEvent.
interface GLEventListener uses four main methods which need to be stated within the structure of our program to make it work.
1-public void init (GLAutodrawable drawable)
This method is called by drawable immediately after the OpenGL context (procedure conducted by a GLCanvas object) is initialized. can be used for initializing the OpenGL graphics used GLCanvas such as background color, color of objects to be drawn, lights to be managed, etc..
2 - public void reshape (GLAutodrawable drawable, int x, int y, int width, int height)
This method is called by drawable during the first repaint (repaint) and after the component is resized (Resize). The client can update the view (viewport) graphics properly.
3 - public void display (drawable GLAutodrawable)
This method is called by the drawable to initiate OpenGL rendering at your request. Within this method include graphics that draw GLCanvas and will be called whenever requested, or when all GLEventListeners have been notified that an event occurred.
4 - public void displayChanged (GLAutodrawable, ModeChanged boolean, boolean deviceChanged)
This method drawable is called for when there is a change in the display (screen) associated with GLAutoDrawable . The two boolean parameters indicate the type of change that has occurred.
To have a clearer idea about the changes that may occur in the display (screen) are two examples:
- Change screen mode (display mode changed). This occurs when, for example, the quality of color change (say, 32-bit to 16-bit) on a monitor where GLAutoDrawable is being drawn.
- Change display (display device changed). This occurs when, for example, the user drag a window containing a GLAutoDrawable from one monitor to another in a configuration of multiple monitors with different resolutions.
/ / We import the Java packages that we will need
import java . awt. * ; / / For example
/ / We import the JOGL libraries that we will need
javax.media.opengl import. * ; / / For example
/ / Main class that extends JFrame and implements
/ / interface GLEventListener
public class MyClass extends JFrame implements GLEventListener
{
/ / Variable 1
/ / Variable 2
/ /. . .
/ / Variable n
/ / GL interface will allow access to all
/ / methods used by OpenGL
static GL gl;
/ * GLCanvas class provides support for
* rendering OpenGL graphics, ie within this
* object is drawn graphics
* created. * / Static
GLCanvas canvas;
/ / Constructor
public MyClass () {
/ * Here we initialize Variables 1, 2,. . ., N
* previously declared and
* all variables of the JOGL libraries * /}
/ / Methods that use the class "MyClass"
public metodo_1 void ()
{} public int
metodo_2 () {}
/ /. . .
metodo_n public double () {
}
/ * Here we add the methods that use the
GLEventListener * interface * /
public void init ( GLAutoDrawable drawable) {
/ * This method is the initialized
* OpenGL graphics GLCanvas used,
* to call OpenGL functions
* use the gl object
* previous instance. * /}
public void reshape ( GLAutoDrawable drawable,
int x, int and int width, int height) {
/ * This method, as explained, is used to
* the user can modify the "viewport" of
graphics * properly * /}
public void display ( GLAutoDrawable drawable) {
/ * This method is used to create all
graphics * to be drawn into the
GLCanvas * object * /
} public void
displayChanged ( GLAutoDrawable drawable, boolean
ModeChanged, boolean
deviceChanged)
{/ * Method to handle change events
* display. * /}
/ / main method
public static void main (String [] args) {
/ * Instantiation of objects of class "MyClass"
* begin code execution * /}
} / / End of class "MyClass" far
we have created some code that produces a result, the above was simply an example of the look you should have a program written in Java using OpenGL libraries . In the next entry in this blog show the example, now, a program that will display something on the screen.
0 comments:
Post a Comment