[JOGL] How to set up a pretty basic game loop WITHOUT having to use any Animator

Hi there,

I am not new to Java nor am I new to OpenGL. It’s just that I have not done anything gaming related since my first few attempts some 2 years back…

As the last time I looked into Java and OpenGL I’ve been using LWJGL, I’ve been thinking I might now again try to look into the other implementation which I dropped last time as it looked too scary to me back then.

Said done I tried a few things, browsed through the few available tutorials on JOGL gaming that all cover the merest basics using the ‘FPSAnimator’ as a mean of driving the loop.

Now I am asking: Are there any non-FPSAnimator resp. Animator driven examples for a simple gaming loop with JOGL out there? It is not that I don’t appreciate the Animator, but it’s rather that I want to use JOGL really only as a wrapper, same as if I were working with OpenGL directly in a C-Language…

(Also the Animator kind of makes me back off when looking at the source code digging through classes extending classes implementing interfaces that extend other interfaces again, making me wonder even more why the FPSAnimator is based on an AnimatorBase, that bases on a GLAnimatorControl class thats based on an interface called FPSCounter…nvm)

I hope I did not offend anyone nor the forum rules by posing that question, otherwise please point me into the right direction, thanks.

Looking forward for constructive help :slight_smile:

EDIT: having changed the title in order not to insult anyone by accident…

Not sure if this is what you are looking for, but I find the GafferOnGames loops very good:

~

Well, actually looking for some JOGL related thing in that case. Although the link just wandered into my favourites, as it indeed looks quite nice (at least at first look)

For a basic game loop I use java.util.Timer.
Not sure if thats the wrong way to do it, but its always worked perfectly for me, as long as you understand proper thread saftey.

When I wanted to use my own implementation of Game Loops in JogAmp, I tried (and managed) to extend AnimatorBase. Believe me, it’s not too hard. I don’t know how to exactly use it only as an OpenGL wrapper, but that’s not what I’d suggest you to do, except if you have no other choice.

When extending AnimatorBase you have to add two simple classes:

A class extending “AnimatorBase”. It should store a GLAutoDrawable. In the constructor of this class call [icode]add(drawable);[/icode], if the drawable isn’t null.

Another class containing the actual game loop work itself. It should create another thread which runs the loop and is controlled (in terms of pausing and unpausing) from the AnimatorBase.

For the stuff about locking in the AnimatorBase you can simply try to copy whats inside the basic prebuild Animator from JogAmp.

That’s how I did it a long time ago, at least. I have just had a very small glimpse at my code for now, but it’s late for me and I hope this helps you :slight_smile:

Hi

The right place to post questions about JogAmp APIs including JOGL is the official JogAmp forum.

If you don’t want to use a GLEventListener, use GLAutoDrawable.invoke(boolean,GLRunnable) as I do in Ardor3D.

You can call GLAutoDrawable.display() wherever you want, for example in your own loop but we had some really good reasons to implement animators and OpenGL event listeners. JOGL is forced to be a bit more than just a plain OpenGL wrapper, it has to provide at least a few things to work with standard windowing tool kits. matheus23’s suggestion is very good, that’s the way to go if you need some more flexibility. Otherwise, you can use Animator instead of FPSAnimator and if you need to call a particular piece of code for each frame, just put it into GLEventListener.display(GLAutoDrawable) (even though it is not very smart especially if those operations don’t require a current OpenGL context).

Just keep in mind that if you don’t use any animator and a GLEventListener, you’ll have to treat some corner cases by yourself. When I used OpenGL in plain C, I used GLUT, it had similar mechanisms. I had to avoid using GLEventListener and Animator when I worked on the JOGL backend of Ardor3D, it’s doable for a very simple test case but when things become more elaborated, you have to manage the context by yourself and you may do some things that ruin your performance or cause crash on some machines. JOGL is flexible enough to let you do that at your own risk. You can even disable the automatic buffer swap and do it by yourself.

Edit.: Animators aren’t fancy. Please be kind.

that actually sounds pretty good to me. Gonna look into it this evening. Thanks for the hint.

also I’ll prolly gonna put more specific questions such as about the, as I perceive it to be, lack of proper javadoc on the jogamp forums as @gouessej recommended

also: @gouessej, I did not mean the term fancy as an insult or degradation of the class nor of the work the jogamp team does. As said I wanted to give JOGL another try now that I’ve been in the industry for some time and understand Java better

EDIT: the jogamp forums scared me off at first (and actually still do do) as they are kept pretty simple. E.g. No sub forum for stuff such as newbie questions (which I consider this one to be) additionally made me ask rather here than on the jogamp forums

Why not go with LWJGL? I mean it is opengl binding to make games with extra features such as keyboard, openal and some more.

because I don’t like the extra features being a compulsory part of the main distro. Wouldn’t mind if they were in optional jars.

EDIT: Also JOGL has NEWT. Which offers some imho quite amazing possibilities.

(I think it’s a fact that) JogAmp has much more features than LWJGL. Keyboard, Mouse, OpenCL and OpenAL are the minimum.

If I had to compare JogAmp to LWJGL then I’d say:
JogAmp is ‘more OOP’ (LWJGL 3 might change that :wink: ).
JogAmp has a richer / more Windowing Toolkit(s) (LWJGL 3 might change that, too :smiley: )
JogAmp especially has the wonderful idea of having classes / Objects for each GL version. So you have a GLCommon, GL2, GL3, … Class. And GL3 extends GL2 and so on :slight_smile: It also has a Debug version of the GL interface, which checks gl-errors after each gl call.

In the end JogAmp is a Wrapper that wraps the C OpenGL Api in a Object-Oriented way.
LWJGL is a ‘straight’ Wrapper from C OpenGL to Java. You can copy n’ paste parts of C OpenGL code and it would work syntactically.

Please don’t do that here. He asks for help, he doesn’t ask which library he should use. Moreover, both this library and JogAmp are (mainly) sets of Java bindings. JogAmp contains a binding for OpenGL (JOGL), another one for OpenAL (JOAL) and another one for OpenCL (JOCL). The library that you suggest and JogAmp both have their own windowing toolkits, both can be used with JInput, both supports keyboards, mices, both supports OpenALSoft, … Your remark is unfair and inappropriate. Please don’t turn this thread into yet another useless “JogAmp vs L*****” debate. You just show your ignorance.

dot_Sp0T, now you see the main reason why I encourage developers to ask for help on the official JogAmp forum, this is the same story, it was already like that in 2006. You ask for help and they suggest you to use their favorite library.

JogAmp APIs are heavily tested on embedded devices, several contributors own some Beagleboards, Pandaboards, ODroids, Raspberry Pi, … which helps us to support them much earlier than any of our competitors, especially thanks to Xerxes (xranby). Oversimplified APIs wil have to get less simple to support as much use cases as us which means that we did some great choices since Sun / Oracle abandoned us. Actually, JOGL, JOAL and JOCL work under Android for example. Yes NEWT rocks, and it will rock even more with NEWT Input API :slight_smile: You can even preserve OpenGL states when your application is paused (very useful for mobile games). JogAmp is modular, there are several granularities of packaging so that the newbies can just use the biggest JARs if they want something simple (jogl-all.jar, joal.jar, jocl.jar and gluegen-rt.jar) and others can use “atomic” smaller JARs to bundle only what they need.

Well, that is in the human nature. Being excited about something and asking other to check it out, promoting the features one likes most. After being 4 years in the industry working as a programmer for a bank I certainly know that :wink:

As in others things, I do not think people are being ignorant. As I get it, most of the programmers here, including main contributors to both ‘competitors’ are hobby programmers, they certainly will look at things differently than people who do their daily work in the field.

For now I sadly have to tell that I put my JOGL fascination into another hibernation as I see that I do not know all to much about OpenGL anymore. So I think I’ll do the learning the same way I did it back 2 years ago and go check out the delphiGL wiki and translate their stuff to java - probably starting with using lwjgl as it is almost C syntax, then switching implementations just for the fun of compariung.

Programming is fun and it should stay fun, so please people, don’t ruin it by fighting each other and defending yourselves against everything that maybe could be in some sort of way a mild spark of a questionable insult…

Also I would like to ask a MOD to CLOSE this thread as I have gotten the insights I’ve been looking for, thank ye all :slight_smile:

[quote=“dot_Sp0T,post:12,topic:47402”]
The way I’m learning OpenGL right now is by doing the ArcSynth tutorials. What may be useful for you are the very nice and clean Java implementations of these (and other) tutorials by forum member ra4king. Maybe its useful for you when translating stuff to Java. These happen to be in LWJGL, but I’m sure similar examples of JOGL should exist.

@gouessej: no offense, but you appear to be overreacting a bit here…

Am right now digging into SHCs tutorial series. Nice and small lessons, good to freshen up and look at specific things.

And just to say: LWJGL has the nasty habbit of being terribly time consuming to set up to run…
I can include the JOGL dependency into maven, do a clean install and I’ve got the libraries and can run my test app. For LWJGL I got to customize my build phase, introduce new environment variables and finally still got to change stuff in my IDE’s project config (that I bet my last shirt will be reset by maven everytime I do a eclipse:clean eclipse:eclipse)… So the point for user friendlieness goes to JOGL :slight_smile:

No offense, you appear to misunderstand the way JOGL has been “treated” the last 8 years (and the examples of the book “Learning Modern 3D Graphic Programming” have been ported to JOGL here). I will (try to) no longer argue.

I agree with dot_Sp0T, I would like a mod to close this thread.

Having a question answered is no ground for locking a thread. You’re free to make reading this thread a waste of time, if you’re so inclined. We’re old enough not to depend on a moderator to stop the bickering.