Using gl commands outside of display/reshape/init

I’m wondering if this is ‘normal’ that gl commands like gl.glEnable() seem to only work from the GLEventListener methods. One example is if I want to turn off lights, it doesn’t work unless I make the actual call to gl.glDisable(gl.GL_LIGHTING) in the display method, trying this in my keyboard listener for example just gets ignored. I’m assuming that this is to protect me from doing something stupid, but if that’s the case shouldn’t an exception be thrown of some sort indicating that I’m trying to do something with GL when it’s not available? It seems strange to me but I guess JOGL isn’t exactly your typical java api.

Not really. If you pass the GL, GLU contexts around you can call GL methods just about anywhere. It all depends on when your keyboard listener knows about the GL and GLU contexts. If you post the code to your rendering class I’m sure I can help you with that as I currently do all sorts of stuff with the function keys and it works just fine.

The GLEventListener and KeyListener were implemented in the same class using the same reference to GL. I’m not posting the full code now because well, I don’t have it (and it’d be wrong to allow someone the horror of seeing my learning code anyway), but this is the keyReleased method which is where I enabled and disabled things. I can gaurentee a few things, mainly that this method ‘worked’ in that the variable lights did get changed, that I wasn’t forcing the lights to be on or off in the display method (and therefore replacing the calls here), and that this same code worked fine when moved to the display method (I added another variable updated so that I only enabled or disabled after a key had been pressed when I moved it but otherwise no change was made). What I can’t be sure of, is if we are using the same version of jogl, I looked before posting earlier and there didn’t seem to be any new binaries up for grabs.

Hopefully the description of the problem is enough, I can reproduce the problem I’m sure since it was just a rotating cube with a light on it (based off nehe’s lighting and texture tutorial and the texturemanager classes originally posted in this forum). I have worked around this problem by moving the enable/disable calls to the display method but I’d definitely prefer to be able to enable/disable things in other sections of code (or do more common/practical things, things I still know nothing about hehe).

As you have found, it is only legal to call OpenGL routines from within your GLEventListener methods. If you install a DebugGL pipeline you should start seeing errors if you try to perform OpenGL calls from e.g. KeyListeners. Please read the documentation in doc/userguide and refer to the demos’ source code for some more description and examples of how to safely perform keyboard and mouse interaction.

http://www.realityflux.com/abba/JCD_WORK_Frame.zip

That’s my work frame, basically it answers most of your questions or at least the part that I think I understood. :wink:

Ah… you’re actually trying to use AWT events. I thought you were using JInput.

Err, yeah, I’m trying to limit myself to learning a few things at a time and haven’t looked at JInput yet, still just playing with JOGL and opengl, I have seen examples with the debug setup and didn’t realize what it was for, guess that could have made things very easy.

I feel like being told to RTFM is great advice, where do I find it, I have the API docs but I don’t seem to have this userguide and can’t figure out where it’s downloaded from. On the other hand I did find some cool stuff on the site while looking for it. I’d love to read the userguide though, if someone can help me find it.

[quote]I’d love to read the userguide though, if someone can help me find it.
[/quote]
It’s in the source tree, which can be browsed from the links to the source code on the JOGL web page. I’ve also just added a link to it to the “Useful Links” section of that page.

OK, I found it, and I have to say, that was WAY TOO HARD to find. There is no way I would have found that without being told specifically where to find it, and even then I almost didn’t, and that’s after you put in a helpful link to help me find it? Sure I’m glad I have it now, but besides me has anyone else not on the project ever seen that page? Couldn’t this be bundled with the API docs linked to possibly from the help-doc.html file and overview or something to make it easier to find it for dummies like myself (I think something like this should be almost impossible to miss, kind of like the accept/decline buttons you have to push to download anything from the sun site).