Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: LWJGL Rendering Loop -- Stuttery Performance! on: 2005-07-31 02:53:29
Thanks so much for your help anarchotron!
You really helped me clean up the loop -- I can now see how horribly inefficient it was before  Grin.
Now my animations move across the screen with much smoother graphics and the loop runs through much less often.

Thanks alot!!!
2  Game Development / Newbie & Debugging Questions / [Resolved] LWJGL Rendering Loop -- Stuttery Performance! on: 2005-07-30 01:36:36
Hiya everyone! I am new to using LWJGL and OpenGL, and I am having a problem with my time-based game loop.
When I run the program, the graphics just seem to stutter occasionally, and I have a bad feeling that it is some oversight in my code causing the problem.
If anyone could be nice enough to look over these portions of my code and tell me what my problem is, I would greatly appreciate it!

I will explain the system so maybe from my explanation you could find a flaw and not even have to look in the code:

I have two base classes, GameWindow and GameControl.  GameWindow contains the main() method.  Each class has a reference to the active instance of the other class.
GameWindow begins by intializing Display, setting the title, display modes and everything and initializes OpenGL. In then sets the boolean programRunning to true and begins the game loop, contained in GameControl.

GameControl's game loop works like this:

1. set variable beforeLoop to System.nanoTime()
2. Yield the thread
3. Poll the keyboard for input
4. run method programLifeTime, passing the value of variable delta, which is a method that keeps track of how long the program has been running.
5. run method renderGame, which limits the frame rate to a preset value, according to a calculated time period based off of the preset value.  For example, if the Desired FPS is 60, the period of time to wait before rendering again would be 16666666 ns.  It only renders a maximum of once per loop, then resets the time counter  (code example below).
6. run method updateGame, which then passes the delta value to the requisite areas for game updating.
7. Update the Display
8. calculate the delta value according to System.nanotime() - beforeLoop

OpenGL Initialization
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
private void initGL() {
      // enable textures since we're going to use these for our sprites
     GL11.glEnable(GL11.GL_TEXTURE_2D);
           GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
          GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
          GL11.glClearDepth(1.0); // Depth Buffer Setup
     // disable the OpenGL depth test since we're rendering 2D graphics
     GL11.glDisable(GL11.GL_DEPTH_TEST);
     
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
     
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
     
      GL11.glOrtho(0, windowWidth, windowHeight, 0, -1, 1);
   }


Game Loop
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  
public void gameLoop() {
     
      beforeLoop = System.nanoTime();
     
      Thread.yield();
      Keyboard.poll();
      processKeyboard();
     
      programLifeTime(delta);
      renderGame(delta);
      updateGame(delta);
     
      Display.update();
     
      delta = System.nanoTime() - beforeLoop;
     
   }

public void updateGame(long delta) {
      Display.setTitle(gameWindow.getWindowTitle() + " | Elapsed Time- " + lifeSpanMinutes + "m:" + lifeSpanSeconds + "s " + "FPS: " + currentFPS);
     
      for(int x = 0; x < 10; x++) {
         rect[x].updateEntity(delta);
      }
   }
   
   public void renderGame(long delta) {
      FPS_TIME_ELAPSED = FPS_TIME_ELAPSED + delta;
      fpsCounterTimer = fpsCounterTimer + delta;
      if(FPS_TIME_ELAPSED >= FPS_PERIOD) {
         FPS_TIME_ELAPSED = 0;
         try {
            // clear screen
           GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
            } catch(Exception e) {
               e.printStackTrace();
               System.exit(0);
            }
         render();

         fpsCounter++;
         if(fpsCounterTimer > 1000000000) {
            currentFPS = fpsCounter;
            fpsCounter = 0;
            fpsCounterTimer = 0;
         }
      }
   }


And here is my rendering code for rendering a quad (the code stutters even with just a single moving quad on the screen):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public void drawSprite(float x, float y) {
     
      // Set the color to draw geometry as
     GL11.glColor3f(1.0f, 0f, 0f);
     
      GL11.glBegin(GL11.GL_QUADS);
     
      // Upper-Left vertex
     GL11.glVertex2f(x - (width/2), y - (height/2));
      // Bottom-Left vertex
     GL11.glVertex2f(x - (width/2), y + (height/2));
      // Bottom-Right vertex
     GL11.glVertex2f(x + (width/2), y + (height/2));
      // Top-Right Vertex
     GL11.glVertex2f(x + (width/2), y - (height/2));
     
      GL11.glEnd();
     
   }



I know this is alot of code and a huge post to look over and maybe not even enough to find my problem, but if anyone could, I would be so happy!
I cannot figure out why my code stutters!
Thank you so much in advance!
3  Java Game APIs & Engines / OpenGL Development / Rendering Code -- Stuttering on: 2005-03-21 17:24:06
Hey everyone!
I am currently having a problem with my first LWJGL program (a Pong game based off of chman's awesome tutorials).

I set my main loop to look like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
                  // main game loop
                 while(gameState != GAME_STATE_FINISHED) {
                       
                        fpsControl.beforeLoop = System.nanoTime();
                        if(Display.isCloseRequested()) /* windows has been closed? */ {
                              System.exit(0);
                        }
                       
                        updateGame(fpsControl.completeLoopTime);
                       
                       
                        renderGame();
                       
                        fpsControl.afterLoop = System.nanoTime();
                        fpsControl.partialLoopTime = fpsControl.afterLoop - fpsControl.beforeLoop;
                       
                        gameSleep();
                        fpsControl.completeLoopTime = System.nanoTime() - fpsControl.beforeLoop;
                        fpsControl.getFPS();
                  }


Whenver updateGame() is run, it checks to see if the game should be updated this loop (based on the amount of time since the last loop).  The desired UPS is set at 60 for now.

The renderGame() code looks like this:
1  
2  
3  
4  
5  
6  
      public void renderGame() {
            if(fpsControl.gameUpdated) {
                  render();
                  Display.update();
            }
      }


Very simple, as you see.  If the game has been updated at all this loop (via a variable set in UpdateGame), then it renders and updates the display.

However, in practice, this method of rendering only when the game is updated produces a slight, continuous stutter, most noticeable for the ball as it is moving around.  Just enough to notice and be annoying.

With the if clause removed from renderGame(), the animation works fine and without stutter.

Could anyone please help me figure this one out?
I hope I have included enough information, but please do tell me if I left something important out Grin.

Thanks in advance,
Smarto
4  Game Development / Newbie & Debugging Questions / Re: Introduction to Java Flash Tutorials! on: 2005-02-12 14:56:52
Thanks for the support guys  Grin.

Elwiz:
I am actually running plain old WindowsXP with a special program called WindowsBlinds to get a new interface.

Or, you can just think of it as a super cool custom OS if you want.
5  Game Development / Newbie & Debugging Questions / Re: BufferedImage for fast display? on: 2005-02-06 22:23:23
Hi there gojira!

I don't quite understand your question, but I will try to help.

It seems like what you are trying to do is implement a form of double buffering, where instead of your graphics being drawn directly to the screen, it is drawn in your computer's memory and then simply "flipped" over or copied to your screen.

If you want to set up your sprites before drawing them, I suppose you could load them in your program's initialization phase, either the constructor if you are making an Application, or init() in an Applet.

Some other solutions to this:

1) If you are looking for a full-fledged animation loop, complete with double buffering, you might want to check out Chapter 1 of this book-in-progress:
http://fivedots.coe.psu.ac.th/~ad/jg/.
This chapter also covers totally ignoring paint() altogether so you can perform your own graphics drawing whenever and wherever.


2) There are a few sections on passive vs. active rendering here at the Java Tutorial:
http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html


Sorry if this isn't what you were looking for!
Smarto
6  Game Development / Newbie & Debugging Questions / Implementing Loading Screen on: 2005-02-06 22:15:45
Hiya everyone!
I am currently grappling with another conceptual problem having to do with Java.

I see all these great games containing loading screens so when the game finally starts, everything is ready to go.

After thinking a while on how to do this myself, I am stumped!

Could someone please tell me how to make a program display a string such as "Loading..." while the program is in its initialization stage, or while a certain operation is performing?

I can't seem to understand this no matter how hard I try!

Thanks very much in advance!
Smarto
7  Game Development / Newbie & Debugging Questions / Re: Introduction to Java Flash Tutorials! on: 2005-02-06 02:13:45
Hiya, thanks for responding.

Sorry about the loading problem, it seems you have to refresh the page to get it to be visible.  I am not quite sure why this is.

About the flash thing:
I think it is much easier to learn if you can watch and hear it happen.  Some people learn just fine by reading, and probably more quickly as well, but for others this is simply too hard.

Also, I want to get a few of my friends interested in Java programming, but they are intimidated by the complexity of most of the beginning Java tutorials out there so far, and constantly put it off.
8  Game Development / Newbie & Debugging Questions / Introduction to Java Flash Tutorials! on: 2005-02-06 00:49:20
Hey everyone,
just wanted to let you all know that I am starting a short series of Flash tutorials on how to get started in Java.

These are extremely basic tutorials, walking you through opening up Eclipse, creating a project, and making your first program, and that kind of thing.

Here is the link: http://knightsandwizards.com/content/?q=node/8

Please read the introduction first so you know what to download before you start, as well as Downloading Java and Setting Up Java.
Yes, the Downloading Java link is slightly out of date, but it covers the process fairly well still.

Currently there are only two out of four of the tutorials available, I am working on them as fast as I can and will release on at least once a week.
9  Java Game APIs & Engines / Java 2D / Re: Using Timing, Please Help! on: 2005-02-02 22:23:56
Hey I just got your reply!

Thanks so much for the information, Ive only briefly skimmed it so far but I am just about to go through the whole thing, very nice work!

Once again, thank you!
10  Java Game APIs & Engines / Java 2D / Using Timing, Please Help! on: 2005-02-02 20:19:31
Hiya everyone!

I have recently been incredibly frustrated with the idea of keeping a consistent rate of updates per second in a Java game.

I have read (or attempted to read) Kevin Glass' excellent space invaders tutorial as well as the ones about creating the Pong game on Sys-Con, but I think I am a little dumb because I just flat out don't understand the timing aspect of it.

Here is the basic scenario I am trying to figure out:

You are making a two-player Pong game, with the standard two paddles and a ball.

Every time a button is pressed to move a paddle, the keylistener picks it up and then adds, say the value of 5 or subtracts 5 to the variable paddleMove.

Then, in the next game update, the game logic moves the paddle's y position accordingly.

-----
This is what I have down so far in my mind, please correct me if its all wrong.
But the problem I am having figuring out is how to have the ball move consistently throughout the game.
The only thing I can think of now is to update the ball's position one time per loop, but with a drop off in frame rate the ball slows down as well.

I tried thinking about how to implement this where the game updates multiple times before rendering if the frame rate is lagging, but I couldn't figure it out.
I mean, if the ball would move 5 pixels per update, and the game updated 3 times before rendering, that would move the ball 15 pixels.
But how would the game know exactly how many times to update, or... I don't know, I am simply confounded.


If anyone could please maybe explain how to implement a standard update per second system in a Pong type game, please do!

I have been unable to grasp this concept since my first day in Java programming Sad

Thank you so very much in advance!
11  Game Development / Newbie & Debugging Questions / Re: another im lost thread? on: 2004-12-31 22:22:09
Hello qgpr!
Actually, I have been trying to learn all the concepts I need to know to create an online RPG myself.  I have pretty much all of these same questions, but I am a little clearer on some of them.

As for 3D graphics, many people choose the Xith3D Scenegraph/Rendering API over Java3D.
This is for a at least few reasons.
1.  Xith3D is targeted at game developers.
2.  Sun's support for Java3D appears to have faded away, while Xith3D is currently still in development (not by Sun, however).
3.  Xith3D is generally faster than Java3D and has less "quirks".

There is a downside to using Xith3D for your 3D graphics, and that is the lack of documentation.  The Getting Started  Guide is pretty good, but its a little rough learning the advanced topics.

As to sound, I would recommend JOAL even though I don't know much about it simply because it seems like it works, and well Smiley.

For networking, its really a toss-up between TCP and UDP.  Long debates have dragged on and on over this issue, some saying to have a TCP-like layer applied over UDP, others saying UDP's packets cause too much data loss.

One more thing,  and this is the most important of all.  Please, please, please, please PLEASE!  Do not try to "finish this game quickly".  You will only frustrate yourself heavily.  (Believe me, I wasted alot of time trying to hurry up and start up my game).

If you have any more questions please post them in this thread, or you can e-mail me here:
smarto@knightsandwizards.com
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

Riven (42 views)
2014-07-14 18:02:53

OpenGLShaders (29 views)
2014-07-14 16:23:47

Riven (29 views)
2014-07-14 11:51:35

quew8 (26 views)
2014-07-13 13:57:52

SHC (63 views)
2014-07-12 17:50:04
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!