Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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  
  Opengl application stops responding  (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
Offline Zerali

Senior Newbie





« Posted 2012-07-20 20:55:24 »

Hey, I was trying to split up the game loop into an update loop and render loop. I finished but for some reason the application stops responding and can't figure out why. Wondering if anyone might have an idea as to why and how to fix it. I put all the code and put it into pastebin http://pastebin.java-gaming.org/f6427305b13
-Thanks
Zerali
Offline davedes
« Reply #1 - Posted 2012-07-20 21:03:46 »

What was the idea behind doing this every frameHuh
1  
2  
3  
4  
5  
6  
7  
8  
               try {
                  Display.releaseContext();
               } catch (LWJGLException e) {
                  e.printStackTrace();
               }
               
               Game game = new Game();
               game.play();


Why are you using threads?! Why would you create them every frame?! Why would you use a separate thread for updating and rendering?
Why do you have a game loop within your game loop?!?!!?! Why are you repeating all that code!?

Your code baffles me...

I think you'll have a hard time learning OpenGL and LWJGL if you have no idea how to program in Java. Stare

Offline Zerali

Senior Newbie





« Reply #2 - Posted 2012-07-20 22:13:22 »

Well the idea was to have a menu and then create the game object which would then in turn start the two threads once the person has chosen to play the game. Then the code should wait until the two threads complete and join back in with the main thread.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void play () {
      render.start();
      update.start();
     
      try {
         render.join();
         update.join();
      }
      catch(InterruptedException e) { }
     
   }


So I was releasing the opengl context from the main thread and then making it current to the render loop thread.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
public void run(){

      try {
         Display.makeCurrent();
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
     
      lastFPS = getTime(); // call before loop to initialise fps timer
     startTime = lastFPS;
     
      while (!Display.isCloseRequested()) {
         int delta = getDelta();
         
         System.out.println("Render Loop");
               
         // Clear The Screen Buffer
        glClear(GL_COLOR_BUFFER_BIT);
         
         glColor3f(0.5f, 0.5f, 0.5f);
         glRectf(0, 0, windowWidth, windowHeight);
     
         
         Display.update();
         Display.sync(60); // cap fps to 60fps
        //updateFPS();
     }
   }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-07-20 22:41:08 »

Display.makeCurrent and releaseContext hasn't got anything to do with threads. It's more useful if you have PBuffers or multiple GL contexts.

You shouldn't be using threads for this... it sounds like you don't really understand what they do. Generally rendering and updating should all be done in the same (GL) thread.

I'd suggest taking a look at the LWJGL wiki if you are still lost, or a higher level library like Slick2D or LibGDX to ease you into Java programming.

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (28 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!