Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  A bad case of the jitters  (Read 958 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Devvie


Medals: 1
Projects: 3


slow and steady...


« Posted 2012-07-03 00:38:00 »

So usually during gameplay, through every run of the game loop I draw loads of new stuff onto the screen
However, I just implemented a pause feature
It's exactly what you expect: press "P", the screen darkens, and it says "Game Paused". Press "P" again and the game play resumes. Nothing special.
All I did was encapsulate the rendering/updating block in an "if(paused){...}" and make a basic method to update whether "paused" should be true or not. You get the idea

Now, here's the weird part. I only draw the pause screen ONCE, when the game is initially paused, not every step. It seems like a bit of a waste to draw the same thing over and over again when it's not changing.

The drawing works, but the screen jitters a lot. What I mean is that, if the player character is moving while "P" is pressed, through the darkened screen you can see the game world jolt back and forth very quickly.
Also, the "pause screen" (which is the darkened screen and the text) flickers on and off very quickly.

Now, why should this happen? I'm 100% sure that there's no rendering code that escaped the "if(paused){...}" and I only draw the paused screen ONCE (when the played initially hits "P")

So why is this happening? Is this a peculiarity of OpenGL? How can it be fixed?

Thanks
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2012-07-03 00:46:52 »

There are two buffers in OpenGL: the one that is displayed and the one that you draw into.

When you stop drawing into the 'draw buffer', and you call Display.update(), you keep switching between which buffer is visible. One of your buffers is darkened, the other shows the last buffer that you rendered your 'game' into.

To fix it: either make sure both buffers are black or stop calling Display.update() when you pause the game.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Sickan

Senior Devvie


Medals: 9



« Reply #2 - Posted 2012-07-03 00:50:09 »

There are two buffers in OpenGL: the one that is displayed and the one that you draw into.

When you stop drawing into the 'draw buffer', and you call Display.update(), you keep switching between which buffer is visible. One of your buffers is darkened, the other shows the last buffer that you rendered your 'game' into.

To fix it: either make sure both buffers are black or stop calling Display.update() when you pause the game.
You would probably have to call Display.processMessages() instead to keep it responding to things like closing the window.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nhmllr

Senior Devvie


Medals: 1
Projects: 3


slow and steady...


« Reply #3 - Posted 2012-07-03 00:55:50 »

There are two buffers in OpenGL: the one that is displayed and the one that you draw into.

When you stop drawing into the 'draw buffer', and you call Display.update(), you keep switching between which buffer is visible. One of your buffers is darkened, the other shows the last buffer that you rendered your 'game' into.

To fix it: either make sure both buffers are black or stop calling Display.update() when you pause the game.

Right, but here's the thing: the "if(paused){...}" contains both the regular rendering code and the regular updating code (as in updating the positions of objects and what not). It seemed like I was killing two birds with one stone.

(Also, when I say I "darken" the screen, I do this: I have a 1x1 sprite of a translucent black pixel, and I draw it over the regular display such that it covers everything. It's nothing special)

Now, you say that I should make sure both buffers are black, but how can I manipulate the buffer that I'm not using?

Thanks
Offline sproingie

JGO Kernel


Medals: 202



« Reply #4 - Posted 2012-07-03 00:58:46 »

It's pretty much SOP in OpenGL to just always re-draw the current frame.  I doubt a static pause screen is going to chew up much CPU, but if you're really concerned about it, render to a FBO then refresh that using a lower framerate like 5fps.
Offline Sickan

Senior Devvie


Medals: 9



« Reply #5 - Posted 2012-07-03 00:59:04 »

There are two buffers in OpenGL: the one that is displayed and the one that you draw into.

When you stop drawing into the 'draw buffer', and you call Display.update(), you keep switching between which buffer is visible. One of your buffers is darkened, the other shows the last buffer that you rendered your 'game' into.

To fix it: either make sure both buffers are black or stop calling Display.update() when you pause the game.
(Also, when I say I "darken" the screen, I do this: I have a 1x1 sprite of a translucent black pixel, and I draw it over the regular display such that it covers everything. It's nothing special)
Thanks
Why don't you just set the GL color and draw a rectf over the whole display?
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2012-07-03 01:00:45 »

It's pretty much SOP in OpenGL to just always re-draw the current frame.  I doubt a static pause screen is going to chew up much CPU, but if you're really concerned about it, render to a FBO then refresh that using a lower framerate like 5fps.
Newbie walks in, is advised to use FBOs and is never seen again Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline nhmllr

Senior Devvie


Medals: 1
Projects: 3


slow and steady...


« Reply #7 - Posted 2012-07-03 01:14:15 »

It's pretty much SOP in OpenGL to just always re-draw the current frame.  I doubt a static pause screen is going to chew up much CPU, but if you're really concerned about it, render to a FBO then refresh that using a lower framerate like 5fps.
Newbie walks in, is advised to use FBOs and is never seen again Smiley

yeah.... This is my first Java game and it's mostly so I can learn the language. Also, I think the way I'm doing it should work.
The other thing about my "draw once" method is that it simplifies a lot of code for a different problem: textboxes. I left that out in my initial post because it seemed extraneous, but I have the same problem for when I draw rpg-esque textboxes (and want the game to stop). So for the sake of my sanity, I'm going to ignore FBOs for now but keep them tucked in the back of my head. Thanks, though

NOW: I was looking at the Display API and I found the "swapBuffer()" method, so I'm gonna see if I can make this all work using that and come back here later with a progress report

(As to why I'm doing the 1 pixel over the screen approach, I was planning on doing something more elegant later once I get this up and running)
Offline nhmllr

Senior Devvie


Medals: 1
Projects: 3


slow and steady...


« Reply #8 - Posted 2012-07-03 02:35:22 »

Okay cool. I read the API more and figured out that what you guys suggested was the best (put Display.update() into the block and call Display.processMessages() otherwise)

It works!

Thanks to everybody!
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.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (53 views)
2014-12-09 22:41:13

BurntPizza (86 views)
2014-12-08 04:46:31

JscottyBieshaar (48 views)
2014-12-05 12:39:02

SHC (62 views)
2014-12-03 16:27:13

CopyableCougar4 (64 views)
2014-11-29 21:32:03

toopeicgaming1999 (126 views)
2014-11-26 15:22:04

toopeicgaming1999 (117 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!