Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Using gl commands outside of display/reshape/init  (Read 1373 times)
0 Members and 1 Guest are viewing this topic.
Offline DanK

Full Member
**

Posts: 229


Javver games rock yawel!


« on: 2003-08-11 15:13:28 »

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.

Offline gregorypierce

JGO Strike Force
***

Posts: 905


I come upon thee like the blue screen of death....


« Reply #1 on: 2003-08-11 16:04:55 »

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.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline DanK

Full Member
**

Posts: 229


Javver games rock yawel!


« Reply #2 on: 2003-08-11 17:13:12 »

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.
Quote

boolean lights = true;
public void keyReleased(KeyEvent e){
     char c = e.getKeyChar();
     if (c == 'l' || c == 'L') {
           lights = !lights;
           if (lights) {
                 gl.glEnable(GL.GL_LIGHTING);
           } else {
                 gl.glDisable(GL.GL_LIGHTING);
           }
           
     }
}

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).

Games published by our own members! Go get 'em!
Offline Ken Russell

JGO Kernel
*****

Posts: 3446
Medals: 3


Java games rock!


« Reply #3 on: 2003-08-11 20:29:59 »

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.
Offline Java Cool Dude

JGO Ninja
***

Posts: 680


Java forever


« Reply #4 on: 2003-08-11 20:43:55 »

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
Offline gregorypierce

JGO Strike Force
***

Posts: 905


I come upon thee like the blue screen of death....


« Reply #5 on: 2003-08-11 20:52:33 »

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

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline DanK

Full Member
**

Posts: 229


Javver games rock yawel!


« Reply #6 on: 2003-08-11 21:54:08 »

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.

Offline Ken Russell

JGO Kernel
*****

Posts: 3446
Medals: 3


Java games rock!


« Reply #7 on: 2003-08-11 22:18:04 »

Quote
I'd love to read the userguide though, if someone can help me find it.


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.
Offline DanK

Full Member
**

Posts: 229


Javver games rock yawel!


« Reply #8 on: 2003-08-12 14:19:21 »

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).

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.181 seconds with 21 queries.