Tag Archives: GLEventListener

Chapter 3: Animations – Learning Java Bindings for OpenGL (JOGL)

This book and the excerpts on this blog are from 2004. Obviously, the API has changed a bit since then. I provide the older information and book in the hope that it will be useful to some hobbyists.

Purchase Printed Book Learning Java Bindings for OpenGL (JOGL)

 

Table of Contents: Learning Java Bindings for OpenGL (JOGL)

This book describes JOGL which was approved as JSR 231 and will become the javax.media.opengl package.

-T. Gene Davis

 

 

copyright 2004 by Gene Davis of genedavissoftware.com

Chapter 3: Animations

Java Thread Review

Hopefully you’ve used threads before, but I’m going to give you a brief refresher course just in case it is dim in your memory. Threading in pretty much every language comes in two varieties.

One type of threading is to have a timer that acts like an alarm clock. You set it up to go off at some regular interval. In Java, this type of threading can be accomplished with the java.util.Timer class.

Here is a brief example of Timer’s use.

import java.util.*;

/**
 * This sample shows the creation of a Java
 * Timer object. Timers need a task and a
 * set time to wake up and do that task.
 */
public class TimerExample {

    public static void main (String args[]) {

        //our timer
        Timer alarm = new Timer();

        //our task (really a TimerTask object)
        TaskExample te = new TaskExample();

        //we schedule the Timer to wake up
        //and do 'te' ever 2000 milliseconds
        //(every two seconds)
        alarm.scheduleAtFixedRate(te, 0, 2000);
    }
}

Next we have the actual task to perform.

import java.util.*;

/**
 * Timers need a task to perform. Like we need
 * to go to school or work when our alarm
 * clock goes off, the program needs a task
 * to do when it is woken up.
 */
public class TaskExample extends TimerTask {
    /**
     * The task is placed in the run method
     * and performed whenever it is scheduled
     * to do something.
     */
    public void run(){
        System.out.println("Wake up!!!");
    }
}

The other type of thread is used to do something right away. It is created in Java by using the java.lang.Thread class.

Continue reading Chapter 3: Animations – Learning Java Bindings for OpenGL (JOGL)

Chapter 2: Using What We’ve Seen – Learning Java Bindings for OpenGL (JOGL)

This book and the excerpts on this blog are from 2004. Obviously, the API has changed a bit since then. I provide the older information and book in the hope that it will be useful to some hobbyists.

Purchase Printed Book Learning Java Bindings for OpenGL (JOGL)

 

Table of Contents: Learning Java Bindings for OpenGL (JOGL)

This book describes JOGL which was approved as JSR 231 and will become the javax.media.opengl package.

-T. Gene Davis

 

 

copyright 2004 by Gene Davis of genedavissoftware.com

Chapter 2: Using What We’ve Seen

Coordinate Systems

There is no sense in waiting until you know the best way to do things before using OpenGL. Sure you’re going to find out a few months later that there was a better way to do this or that, but you’ll never get to that point if you don’t use what you’ve learned. We’re going to take that principle to heart and start off showing you that you’ve already learned a lot.

Coordinate systems may be something that you’ve banished to the darker regions of your memory along with memories of Junior High School. It’s time to dust off those memories.

Do you remember the Cartesian coordinate system? It consists of two perpendicular axes [lines]. One is the y axis and the other is the x axis.

Here is a typical coordinate system with a point mapped out on it.

ch2_coordinate_system

 

You’ll notice that there are numbers all over the place. Usually, they’re not all written out, but they’re always there. All points on the coordinate system correspond to distances along the y axis or along the x axis away from the origin. The origin is where the two axes meet. We’ve marked the origin with an O.

So we’ve indicated the position of one point on the graph. It is (6, 10). The 6 corresponds to 6 on the x axis away from the origin. The 10 indicates the point is 10 from the origin on the y axis.

Notice some positions are negative and some are positive. It would get confusing if 2 left of the origin looked like 2 right of the origin when we mapped out points. If there wasn’t any negatives how would we be able to tell where the point (1, 2) was? It could be in four different places, however if negatives are used (-1, 2) is very easy to spot. Can you find it?

If you’re lost at this point, your in trouble. Find a good introduction to geometry or introduction to graphs and functions book and plan on reading some of it. I’d recommend checking out a college book store, or maybe a big general book store. If money’s an issue, check out the internet for tutorials. There are plenty out there.

You can continue reading either way, but plan on spending time on learning about graphs.

During this chapter we will be using the coordinate system extensively. We will also cover drawing lines and the old Trig. standbys — Sine, Cosine and Tangent. Eventually in your pursuit of graphics and JOGL, you will want to become thoroughly familiar with these, but that is then and now is now. I’ll explain briefly anything that matters, and you can always use this book for reference.

Continue reading Chapter 2: Using What We’ve Seen – Learning Java Bindings for OpenGL (JOGL)

Chapter 1: Hello JOGL – Learning Java Bindings for OpenGL (JOGL)

This book and the excerpts on this blog are from 2004. Obviously, the API has changed a bit since then. I provide the older information and book in the hope that it will be useful to some hobbyists.

Purchase Printed Book Learning Java Bindings for OpenGL (JOGL)

 

Table of Contents: Learning Java Bindings for OpenGL (JOGL)

This book describes JOGL which was approved as JSR 231 and will become the javax.media.opengl package.

-T. Gene Davis

 

 

copyright 2004 by Gene Davis of genedavissoftware.com

Chapter 1: Hello JOGL

First There Was OpenGL

For some years now, a programmer that wanted to create a graphics intensive program that could be sold to users of different Operating Systems had one choice — OpenGL. The GL stands for Graphics Library. OpenGL is a registered trademark of SGI. OpenGL manifests itself as a cross platform C programming API. In reality though, it is a hardware-independent specification for a programming interface.

Most of the reasons that people have given me over the years for the lack of a future for Java especially in the gaming industry was that you can’t use OpenGL in Java. They rightly pointed out that the fastest 2D and 3D applications use OpenGL.

OpenGL is for making graphics. It is fast. Most of the time it is hardware accelerated. It seems that OpenGL can do anything visually that you would want to do.

Unfortunately OpenGL is written for C. Let’s face it, C is not the most popular language for programming complex applications. One of the biggest drawbacks to OpenGL is that you can’t make it do anything without a window to put your graphics in, but OpenGL doesn’t provide a means for you to create windows. This makes OpenGL hard to learn for beginners.

Luckily GLUT was introduced and made dealling with windows, buttons and events generated by users easier to add to OpenGL heavy applications. Still learning OpenGL in C or even C++ can be painful for new programmers or programmers that want to use true Object Oriented Programming.

Continue reading Chapter 1: Hello JOGL – Learning Java Bindings for OpenGL (JOGL)