Friday, 27 June 2014

Simple JOGL program

Simple program using JOGL. This should show black screen which is openGL canvas .


import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     
        GLProfile glp=GLProfile.getDefault();
GLCapabilities caps=new GLCapabilities(glp);
GLCanvas canvas=new GLCanvas(caps);
Frame f=new Frame();
f.setSize(500,500);
f.add(canvas);
f.setTitle("Hello JOGL");
f.setVisible(true);
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}

}  );

}
 
    }
 

Thursday, 26 June 2014

Setting up Eclipse IDE and NetBeans IDE for OpenGL(JOGL)

Don't get panic by reading the title of this post and keep following simple steps. I tell you, it's really simple to setup Eclipse and NetBeans IDE for JOGL (Java binding for openGL).
Well, now you will be thinking what the heck is JOGL? The answer to this question is fairly simple. JOGL is an open source API for using OpenGL in your java programming. Well, readers learning JOGL is not as simple as this answer. I type too much so lets come to the main point " Setting up Eclipse and NetBeans with JOGL".  
BUT WAIT !!!! 
There  are some pre-requisites   
  • Your graphics card should support openGL. You can ensure this using openGL extention viewer software which can be downloaded for free by going this link. Mostly modern day graphic cards supports openGL so you can skip this step.
  • JDK  installed . JDK is required neatbeanshereully inst successftoall and eclipse IDEs. If you don't know how to install JDK , click  .
  • After downloading and installing JDK you can install any of the two IDEs. It's just a matter of choice that which IDE is better. For me both works just fine. Click here to install netbeans. For the beginners downloading JAVA SE editions works just fine. Click here if you want to install eclipse.For beginners downloading Standard Edition works just fine.
After successfully installing any IDE mentioned above you will have to download and extract JAR files ( java ARchieve) of JOGL by clicking here and then clicking "zip"on link as shown in screenshot below.

then click on " jogamp-all-platforms.7z "

When downloding is completed . Extract the downloded file by right click the selected file and click on extract here using Winrar/Winzip or 7zip. You will need to import 3 minimum files to your java project , how to import them is also discussed below. It's as simple as something that no body knows 
  1. jogl-awt(inside automic folder)
  2. jogl-all(inside jar folder)
  3. gluegen-rt(inside jar folder)

    First I am going to explain how to import it in your project using eclipse with the help of screen shots.

    Open Eclipse , goto file menu, click on new and select java project. Your window should look something like this
    Give desired project and click finish. Then go to project properties by right clicking on project and clicking 
    "properities". Then click on red highlighted.






    Give desired name to your library.








    That is all to set up eclipse with JOGL.

    Setting up Netbeans IDE for openGL(JOGL)

    Creating project is nearly the same as Eclipse so I won't explain it here to make things precise. After creating project. Right click on project and click on properties. Then follow steps in below screen shot.



    After this step all is nearly same as we did . You just need to add above mentioned 3 libraries. You can write below code to test if your OpenGL libraries are successfully added in your project by running the simple program which just shows OpenGL canvas. You can find code here  
    I hope this helps.