Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Standard Game Loops for lwjgl?  (Read 3880 times)
0 Members and 1 Guest are viewing this topic.
Offline SirSoltex

JGO Coder


Medals: 33
Exp: 1 year


Pixel-man, Programmer. Lover of the pancreas


« Posted 2015-10-08 08:10:46 »

In beginning my first lwjgl game project today i realized that up until now i had been using a standard while loop for all my game loops (most of my stuff was up until now has just been simple test code to learn the ropes of lwjgl). But after i programmed the loop it i got an error: "Function is not supported" and turns out after doing a bit of googling that OpenGL calls (from one GL context) can only run on one thread. And up until now all my game loops i've made/used run on a separate thread to the main one.

My question is, does anyone have any examples of game loops that work well with lwjgl?

Here's the code if your interested: https://gist.github.com/anonymous/ab50c60a57eca465242e

Are you humans? I don't know.
Offline KaiHH

JGO Kernel


Medals: 446



« Reply #1 - Posted 2015-10-08 08:22:26 »

You can render in any thread you want with OpenGL. Only the thread processing window messages is limited on some platforms. Here is an example of how to process window messages in the "main" thread and rendering in another spawned thread: https://github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/opengl/glfw/Multithreaded.java
This is with LWJGL3, though.

And here is a LWJGL forum entry stating how you can even switch between different render threads (also with LWJGL3): http://forum.lwjgl.org/index.php?topic=5965.msg31963#msg31963
Offline SirSoltex

JGO Coder


Medals: 33
Exp: 1 year


Pixel-man, Programmer. Lover of the pancreas


« Reply #2 - Posted 2015-10-08 22:06:50 »

i was more looking for examples of what people have done in actual projects. But thanks anyway Smiley

Are you humans? I don't know.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline unlight
« Reply #3 - Posted 2015-10-08 22:12:52 »

I am curious about this too actually, it felt a bit strange to just begin the game loop in the main thread because it is so heavily recommended against in Java2D. On top of that, I also believe that it is recommended that any time you wanted to create AWT/Swing components that you invoke it on the Event Dispatched thread (I get that LWJGL isn't associated with AWT/Swing).
Offline jonjava
« Reply #4 - Posted 2015-10-09 03:46:13 »

And up until now all my game loops i've made/used run on a separate thread to the main one.

Why?

There's generally no benefit/need to use more than one thread. Unless you know exactly why and what you're doing in which case you wouldn't be asking this question.

@mattdesl has some nice tutorials:
https://github.com/mattdesl/lwjgl-basics/wiki/Display#game-loop

Offline unlight
« Reply #5 - Posted 2015-10-09 06:19:33 »

I'm actually not exactly sure what the reason is, but every tutorial I had ever gone through had made a point of running your game on its own thread.

Unfortunately, I don't think that tutorial is really valid anymore for LWJGL 3. I believe that the display class is now deprecated??
Offline SirSoltex

JGO Coder


Medals: 33
Exp: 1 year


Pixel-man, Programmer. Lover of the pancreas


« Reply #6 - Posted 2015-10-10 03:48:07 »

Unfortunately, I don't think that tutorial is really valid anymore for LWJGL 3. I believe that the display class is now deprecated??
i don't think it is. All the tutorials/posts i've seen still use it.

Are you humans? I don't know.
Offline CopyableCougar4
« Reply #7 - Posted 2015-10-10 03:50:44 »

Correction: The Display class is no longer in LWJGL 3. People who do have a Display class simply wrap the GLFW functions in their own wrapper. IIRC SHC did this at one point.

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline SHC
« Reply #8 - Posted 2015-10-10 04:37:55 »

Correction: The Display class is no longer in LWJGL 3. People who do have a Display class simply wrap the GLFW functions in their own wrapper. IIRC SHC did this at one point.

I'm still using the Display class I wrote once in my SilenceEngine. However, I kept the GLFW functions in their own classes such as Window, Monitor, etc., and the Display supports switching windows (between fullscreen and normal mode).

Display.java
Window.java
Monitor.java
VideoMode.java
Rest of GLFW classes

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
Ecumene (56 views)
2017-09-30 02:57:34

theagentd (79 views)
2017-09-26 18:23:31

cybrmynd (187 views)
2017-08-02 12:28:51

cybrmynd (185 views)
2017-08-02 12:19:43

cybrmynd (192 views)
2017-08-02 12:18:09

Sralse (202 views)
2017-07-25 17:13:48

Archive (758 views)
2017-04-27 17:45:51

buddyBro (892 views)
2017-04-05 03:38:00

CopyableCougar4 (1441 views)
2017-03-24 15:39:42

theagentd (1324 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!