Last semester I did a subject on my university where I needed to do a project with OpenGL. Our professor asked us to program a 3D graphic modeler – a program capable of drawing 3D figures, set material properties and scale, move, rotate, group and copy them. We could not use high level libraries like Java3D, he wanted us to program OpenGL, only that. Things got complicated, but NetBeans made my life easier... again!
A OpenGL code may became quite complicated if you do not take care. There are too many settings, many variables, matrices, transformations... and a little detail can turn things horrible if you don't know what you are doing. On this point, working with a great IDE may help you a lot!
Another fact is that I liked the way of programming openGL with JAVA.
On the most other programming languages, you should use callback functions to do things on openGL, for example: you may create a function display() that will draw things on the screen, in python:
“Draw a triangle”
glColor3f (1.0, 1.0, 1.0)
glVertex3f(0.0, 1.0, 0.0);
glVertex3f(-1.0, -1.0, 0.0);
glVertex3f(1.0, -1.0, 0.0);
// Finished Drawing The Triangle
but then, you should say to openGL that display() is the one taking care of screen drawings, saying:
In JAVA there is no callback function, it's just Programming to an Interface style! It's really cool and make your code more comprehensive. My openGL project become more understandable having a Sphere class that extends Shape class and implements Drawable interface (you know, my sphere is actually a drawable shape!)! The openGL functions like display(), init(), reshape() can all be coded inside a class that implements the interface GLEventListener, just that... make more sense to me! In Java:
//Draw a triangle
public void display(GLAutoDrawable drawable)
GL gl = drawable.getGL();
// Clear the drawing area
gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top
gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
// Finished Drawing The Triangle
// Flush all drawing operations to the graphics card
This post is not about teaching OpenGL, it's just too complicated for a single post. But you may find your way through NetBeans6.0 OpenGl plugin and the following tutorial:
(and you may want to check the OpenGL red book too)
BUT LET'S START THIS GUIDE about turning JavaOpenGL ON at NetBeans6.0.1 and HAVE FUN!
The first step is to download the the cool JOGL plugin from NetBeans.org page:
The file downloaded from above is zipped, unzip all the nbm files (that are inside the zip) on a directory.
Note: This plugin is really nice: check it's features list:
\* Editor for the OpenGL Shading Language (GLSL) with compiler error annotation, code folding, syntax highlighting, auto completion and documentation.
\* Easy access to the GLSL compiler and linker of your graphics driver integrated in the editor
\* OpenGL Capabilities Viewer
\* Integration of JOGL GUI components into the Matisse GUI builder
\* JOGL project templates
\* Ready to run JOGL demos and examples of the OpenGL Programming Guide (also known as Red Book)
Ready to use it? Let's install it!
Open you NetBeans IDE. Go to Tools > Plugins
On the window, go to "Downloaded" tab (it may be empty). Press the "Add Plugins..." button. Go to the directory you unzipped the plugin's nbm files, select ALL of them and press OK. The plugin items will appear on the list on the left just like the picture above. Leave all of them selected and press Install button.
You will go through some installation steps; accept the terms of agreement and press Install. The installer may alert you that the plugin is not signed (or something like that), just ask to install it anyway. In the end, you will need to restart your IDE.
Done. The JOGL plugin is installed. After NetBeans restart, you can go through File > New Project and see the OpenGL project option on Categories list.
The Simple JOGL Application is the perfect place to start doing your openGL project, it's an almost empty openGL application that you may increase.
You may have a look at the Demos too (to have an idea about what you can do with OpenGL and JOGL). This plugin cames with many JOGL demos and Red Book demos. So, if you are studing OpenGL using the Red Book, you will find the examples there. You just need to expand OpenGL categories on the New Project window to see the Demos folders:
JOGL Infinite Shadow Volumes Demo:
A very interesting point of the plugin is that it does integrate the OpenGL Panel and OpenGL Canvas to the Matisse system, so you can create your GUI using Matisse and put OpenGL elements on it.
Developing GUI on NetBeans is incredibly easy, and now you can include OpenGL elements on your projects! Quite nice!
Thats all! Hope you enjoy developing OpenGL on NetBeans6.0.1