Final Demos
For this last week of the semester, I've been busy putting all of my demos together. The final
group is:
- Materials Demo
- Environment-mapping Demo
- Mipmapping Demo
- Shadows Demo
Materials Demo 3.0

A significant change has been made to the Materials Demo. It now allows the lights to be moved in every possible plane, not just in the X and Y plane. Also, to help the user distinguish what way they can move the objects, I added a transparent representation of the plane that the object is being moved on. I did this by stretching out a glutSolidCube and using alpha-blending to make it transparent. Depending if the user holds down the Shift key, the object will either be moved in the XY plane or the XZ plane. The transparent plane will adjust accordingly to show the user this. Also, it will help them better understand where the object will be moving if the user rotates the lights using the right mouse button.
I also decided to add one more button, that turns on or off the directional "universal" light that has always been in the demo. This allows further manipulation of the overall scene and produces more options for seeing the effect of light and materials.
MipMapping Demo 1.0

I decided to split up the MipMapping portion of the Textures demo into its own demo. I did this because switching between the two "scenes" within one app got a little tricky. I could either have a very large display function that contained both scenes, and a flag that chose which one to render.
Another option, which I actually tried, was to swap the GLEventListeners. My demos are all composed of the main JFrame class and then a renderer class that implements GLEventListener.
From within the main JFrame class, in this case, the class TexturesDemo.java, I could switch which GLEventListener the JOGL canvas used: the environment mapping one or the mipmapping one. But the problem is in the nature of OpenGL: it is a state machine. Therefore, all of the possible states within one scene would be carried over to the next scene when the listeners were swapped. I would have to explicitly set every state for each scene, which would be quite cumbersome.
By relegating the mipmapping scene as its own "demo", this problem is avoided. Each scene is its own renderer with a JFrame class that uses it. I also made available through combo boxes the options to choose which minification/magnification filters are used. Depending on what angle/distance the texture-mapped object is viewed at, the filters can make a big difference in the quality of the overall image.
Texture Mapping demo 2.0

For the Texture Mapping demo(aka Environment mapping demo), I added little thumbnails in the combo boxes to show the user a preview of the texture they will be applying. This was a little tricky, but not too hard to do. It required using a class called ComboBoxRender that implements ListCellRenderer...basically a custom render that I could have more control over. I found a nice example of this from Java's Swing tutorial pages and base my code around their example.
Also, I improved the way that the user can control the rotation, selection, moving, and sizing of the objects. I also added the same ability as in the Materials Demo where objects can be moved in more than one plane.
Shadows demo 1.0

I felt I wanted to get another topic in quickly in this last week, so I decided to go for shadows. I started out using one of the tutorials from Nehe, but I never fully got to get into it and understand it at its lowest level.
I got the basic idea of what was going on, and then added selection and options to control the color and opacity of the shadow. There's also some very basic collision detection going on; the user can't move the objects outside of the "room" in which the scene is contained.
To each demo I added a little help-->controls menu item, listing what commands do what. For the most part the commands remain consistent, i.e., left-click is always selection, except in the Mipmapping demo.
I decided to package all my demos into one executable jar, which has a simple intro screen that allows the user to choose which demo they wish to view. This was a bit tricky... some of my demos required demos not written by me, therefore they were not necessarily coded to be used within a jar. This is only really a problem when loading media or reading files is involved. I took care of the image loading using
this.getClass().getClassLoader().getResource(imagepath)
But one of the classes I was using, Object3D.java, was reading data from a text file.
This was accomplished through a FileReader object as such:
try{
file = new FileReader(st);
while ((info = file.read()) != -1)
data += (char)info;
file.close();
}
I got around this by doing the following:
try {
InputStream is = getClass().getResourceAsStream(st);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while ((thisChar = br.read()) != -1) {
data += (char)thisChar;
}
}
I also notice that about 10% of the time when I click a button for a demo, the Frame will seem to start to load, but won't get beyond a flat gray rectangle. This only happens rarely, and I can't seem to consistently replicate it, so it may just be my system.
Besides these issues, Eclipse made it extremely easy to JAR everything together. The source code is included in the JAR, naturally. Also, I left main methods in each of the demos so that they can be run on their own if desired.
Here is the link to the JAR:
GraphicsDemos.jar
Of course, in order to run this, a user needs to set up their environment for JOGL.
Here's a simple, easy to follow guide for doing so:
Using JOGL
Final Paper:
CMSI499.tex
CMSI499.bib
CMSI499.dvi
CMSI499.pdf


0 Comments:
Post a Comment
<< Home