how to get the GL object outside the callback functions, such as display, init..

I need to do some operations when the users input something( Key pressed or Mouse Clicked). However I can’t get the GL object in the functions of keyPressed or mousePressed. How can I get the GL object in these functions?

I can’t do these operations in the display function, because it takes long time (1 second).

Thank you very much!

wallr1985@gmail.com

What operations are these?

If they actually perform gl calls, you’ll have to use them in the display function. If they’re taking 1 sec, you might want to optimize it heavily, especially because your solution to put that code in the key pressed or mousePressed functions would be very bad for user experience. Those methods run on the awt event thread which controls user interaction, so callbacks are recommended to be quick executing, otherwise the interface appears to block.

THe operations are generating the new view lists(glNewList). I want to generate the new lists in the background. When it finishs, I use the new lists to replace the old one. I think the user experience will be better. Are there some solutions? Generally, how do you generate new lists in the run time?

Thank you very much~

you could just set a flag and other necessary variables in the UI-listeners. then in the next frame you could process these flags. that way you dont have to switch the GL context to another thread and you wouldnt block the UI thread.

I can’t think of a reliable way to make this work while remain rendering the old list. Best I can think of is using VBOs instead and split the recalculation of it’s content in smaller chunks that can be spread over multiple display calls.