Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
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  
  Lwjgl Tearing with fullscreen and VSync  (Read 1890 times)
0 Members and 1 Guest are viewing this topic.
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Posted 2013-08-20 22:10:09 »

When programming in LWJGL, Display.setVsyncEnabled(true) seems to have no effect on tearing in fullscreen mode.  Here is my code where I create the Display

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
   /**
    * Loads OpenGL contexts and constructs Resources
    */

   public static void loadOpenGL(int width, int height, int fps)
   {
      if(!openGLLoaded)
      {
         // Passes in information
        Stage.width = width;
         Stage.height = height;
         Stage.fps = fps;
         
         try
         {
           
            DisplayMode[] modes = Display.getAvailableDisplayModes();
            for (int i=0;i<modes.length;i++)
            {
               DisplayMode current = modes[i];
               System.out.println(current.getWidth() + "x" + current.getHeight() + "x" +
               current.getBitsPerPixel() + " " + current.getFrequency() + "Hz");
            }
            // Creates window
           Display.setTitle(title);
            Display.setDisplayMode(new DisplayMode(Stage.width, Stage.height));
            Display.setDisplayMode(modes[19]);
            Display.setFullscreen(true);
            Display.setVSyncEnabled(true);
            Display.create();
         }
         catch(LWJGLException e)
         {
            e.printStackTrace();
         }
         
         // Initializes OpenGL.  What could it mean???
        GL11.glMatrixMode(GL11.GL_PROJECTION);
         GL11.glEnable(GL11.GL_TEXTURE_2D);      
         GL11.glLoadIdentity();
         GL11.glOrtho(0, Stage.width, Stage.height, 0, 1, -1);
         GL11.glMatrixMode(GL11.GL_MODELVIEW);
         GL11.glEnable(GL11.GL_BLEND);
         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
         GL11.glColor3f(1, 1, 1);
         
         // Initiliazes Resources
        Resources.init();
         
         // Turns off flag
        openGLLoaded = true;
      }
   }



Here is my update method

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
/**
    * Update loop
    */

   private static void run()
   {            
      // Makes root container for holding all visuals
     root = new ListContainer();
     
      // Fires up room
     Stage.room.enter(Stage.root);
     
      // Time
     long lastFrame;
     
      // Rendering loop
     while(!Display.isCloseRequested() && !isCloseRequested)
      {
         // Records last time
        lastFrame = getTime();
         int delta = fps * 1000;
         
         if(Display.isActive())
         {
            rendersNext = true;
           
            // Clear the screen and depth buffer
           if(clears)
               GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

            // Renders visuals
           root.render();
           
            // Updates room
           delta = (int)(getTime() - lastFrame);
            Stage.room.update(delta);

         }
                                   
         // Updates the display
        Display.update();
                 
         // Polls music (Which I was never told to do!!!)
        Music.poll(delta);
         
         // Polls sound
        SoundStore.get().poll(0);
      }              
     
      // Cleans up when done
     Display.destroy();
      AL.destroy();
   }



The application DOES go into fullscreen mode, but there is terrible tearing going on despite the fact that I've enabled VSync.    Am I missing something here?

Did you know that 90% of statistics are wrong?
Offline quew8

JGO Coder


Medals: 29



« Reply #1 - Posted 2013-08-21 00:22:52 »

I should say that LWJGL makes no guarantee that setVSyncEnabled will work and throws no kind of error if it doesn't.
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Reply #2 - Posted 2013-08-21 01:41:47 »

I should say that LWJGL makes no guarantee that setVSyncEnabled will work and throws no kind of error if it doesn't.

Yikes!  That's depressing...  Does this mean that games that use the OpenGL pipeline are doomed to tearing on some machines?

Did you know that 90% of statistics are wrong?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2013-08-21 09:43:10 »

Yes.

For what it's worth, on ATI and NVidia drivers at least, there's actually a setting which controls it in their respective control panels. Sometimes it's set to "always off", sometimes to "always on" - what it is most usefully set to is "Let the application decide". Even then it doesn't always work - I've never gotten RAGE to vsync on my Vista/NVidia system.

Cas Smiley

Offline sproingie

JGO Kernel


Medals: 201



« Reply #4 - Posted 2013-08-21 18:40:51 »

In my experience, the only platform that consistently fails to make vsync work is Linux, and usually then just for the desktop compositor.  On Windows I've found you sometimes need to force it at the driver level, which is doable with a per-app profile (and for most LWJGL games, that's going to be java.exe)
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Reply #5 - Posted 2013-08-21 22:32:38 »

Well, I guess it's still better to have my game be portable.  The overall framerate is fine, and I might just be nitpicking.  There isn't any tearing in windowed mode, although I get a little stuttering when I set the fps exactly to 60.

Did you know that 90% of statistics are wrong?
Offline Cero
« Reply #6 - Posted 2013-08-22 00:10:24 »

www.opengl.org/wiki/Swap_Interval check out adaptive vsync. Although im not sure if lwjgl already has support for this.  Its fairly new, lobbied by John Carmack

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.

pw (17 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!