LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: vilm on January 11, 2004, 17:29:55

Title: double image appearing
Post by: vilm on January 11, 2004, 17:29:55
Hi,
 I modified one of the Nehe examples to basically render a set of random points using GL_POINTS, to generate a starfield.  All good accept that the faster stars appear twice (i.e. some kind of flicker).  If I put a 1 second pause inbetween frames everything appears to be ok (i.e. it's not redrawing before it clears)...  Anyone any ideas?
I set Window.setVSyncEnabled(true); but this didn't seem to have any effect.  I assumed Window.update() and Window.paint() handle double buffering autmatically to prevent this kind of thing... help!
 I'm using a NVIDIA RIVA TNT2 on Windows XP btw.

Many thanks

- vilm
Title: double image appearing
Post by: cfmdobbie on January 12, 2004, 00:42:01
Are you sure the star really appears twice?  When something small is moving fast but in fixed increments, the eye can persist an image that isn't there anymore, and monitors will also leave an afterimage in the phosphor.

Basically, can you take a screenshot (PrtScr) and see the duplication on the generated static image?
Title: double image appearing
Post by: vilm on January 12, 2004, 09:41:41
if i slow the animation right down (e.g. put a 1 second pause between frames) i can see that at no point are the stars drawn twice in the same frame.  Therefore, this must be some kind of timing issue?  It looks really bad... i.e. every star appears exactly twice, but slightly flickering.  the redraw logic must be right cos it works when it's slowed down..  any suggestions welcome!

Thanks

- vilm
Title: double image appearing
Post by: cfmdobbie on January 12, 2004, 12:34:57
So what does the screenshot show you?
Title: double image appearing
Post by: vilm on January 12, 2004, 13:30:18
ok, i'll try that tonight - i'm guessing a screenshot will just show what's on the screen when it's slowed down - i.e. one copy of each star - i don't think at any point is the same star drawn twice on screen but that the effect is the result of a timing or synch issue.. but i will try the screenshot and post back

thanks

- vilm
Title: double image appearing
Post by: Matzon on January 12, 2004, 13:47:35
Perhaps you could post the source, or a binary - so that we ourselves can have a look
Title: double image appearing
Post by: vilm on January 12, 2004, 19:11:49
This is the complete code.  Much appreciated people looking at this as I'm sure it's either a) a schoolboy error on my part or b) something weird about my monitor or video card setup...  I took a screenshot btw and it just shows one copy of each star..

Thanks

- vilm


package com;

import org.lwjgl.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;

public final class StarfieldTest {

   private static Star stars[];
   private static int numberOfStars = 50;

   // GL context creation...
   static {
try {
   Window.create("Basic Window", 16, 0, 8, 0);
} catch (Exception e) {
   System.exit(1);
}
   }
   
   /** Global variable declaration */
   private static boolean finished;
   
   /**
    * Constructor (unused here)  
    */
   private StarfieldTest() {
   }
   
   /**
    * Main method
    */
   public static void main(String args[]) {
try {
   init(); // Init Opengl
   setup(); // create stars
   System.out.println(Window.isVSyncEnabled());
   Window.setVSyncEnabled(true);
   System.out.println(Window.isVSyncEnabled());
   
   while (!finished) {
Keyboard.poll();  // Poll The Keyboard
mainLoop();       // Launch The Main Loop

// Clear Screen And Depth Buffer
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

render();         // Render To Screen
Window.update();
Window.paint();      // Swap Opengl Buffers
   }
} catch (Throwable t) {
   t.printStackTrace();
} finally {
   cleanup();
}
   }
   
   /**
    * Init opengl
    */
   private final static void init() throws Exception {
Keyboard.create();    // Create The Keyboard

GL.glShadeModel(GL.GL_SMOOTH);            // Enable Smooth Shading
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);  // Black Background
GL.glClearDepth(1.0); // Depth Buffer Setup
GL.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing

GL.glViewport(0, 0, Display.getWidth(), Display.getHeight());
GL.glMatrixMode(GL.GL_PROJECTION);        // Select The Projection Matrix
GL.glLoadIdentity();                      // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(45.0f, (float) Display.getWidth() / (float) Display.getHeight(), 0.1f, 100.0f);

GL.glMatrixMode(GL.GL_MODELVIEW);         // Select The Modelview Matrix

GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
   }
   
   /**
    * Main loop
    */
   private final static void mainLoop() {
processKeyboard();  // Get Keyboard Events
processWindow();    // Get Window Events
   }
   
   /**
    * Rendering method
    */
   private final static void render() {
GL.glLoadIdentity();
GL.glColor3ub((byte) 255,(byte) 255,(byte) 255);

for (int i=0; i< numberOfStars; i++) {
   stars[i].sy -= stars[i].vy;
   if (stars[i].sy < -2 ) {
stars[i].sy=2;
   }
   stars[i].render();
}
   }
   
   /**
    * Process keyboard events
    */
   private final static void processKeyboard() {
   if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
finished = true;
   }
   
   /**
    * Process window events
    */
   private final static void processWindow() {
if(Window.isCloseRequested()) {
   finished = true;
}
   }
   
   /**
    * Cleanup
    */
   private final static void cleanup() {
Keyboard.destroy(); // Destroy The Keyboard
Window.destroy();      // Destroy The Opengl Context
   }

   private static void setup() {

stars = new Star[numberOfStars];

for (int i=0; i< numberOfStars ; i++) {
   stars[i] = new Star();
   stars[i].sx = -1 + new Double(Math.random() * 4).floatValue();
   stars[i].sy = -1 + new Double(Math.random() * 4).floatValue();
   stars[i].vx = 0;
   stars[i].vy = new Double(Math.random()).floatValue()/20;
}
   }

   private static final class Star {
public float sx;
public float sy;
public float vx;
public float vy;
public int size;

public Star() {
   size = new Double(Math.random()*14).intValue();
}

public void render() {
   GL.glPointSize(size);
   GL.glBegin(GL.GL_POINTS);
   GL.glVertex3f(sx, sy, -4.0f);
   GL.glEnd();
}
   }
}

Title: double image appearing
Post by: Matzon on January 12, 2004, 19:36:29
not seeing any issues at all - weird
Title: double image appearing
Post by: vilm on January 12, 2004, 20:19:26
doh! thanks for looking... the only other thing i can think of is that i have a fairly old monitor (ibm g74) which is running 1280x1024 at 60Hz..
 The program output does say that Vsync is on (after i set it)...  i've done some more tests and i get this with all fast moving objects...  going to download alien flux and gridrunner and see if they do the same...

cheers

- vilm
Title: double image appearing
Post by: vilm on January 12, 2004, 21:06:53
Whoah!! i noticed the problem with alien flux demo, but when i quit the demo it told me that i should switch to 16 bit colour (i was set to 32 bit on my desktop).  switched to 16 bit and the problem goes away!! weird school.  anyone know why this is?  can anyone reproduce, is it a bug or is it my card just runs slow or something in 32 bit mode?

thanks

- vilm
Title: double image appearing
Post by: princec on January 12, 2004, 22:07:27
Time for new drivers, methinks. And you might want to check AGP ram is enabled in your BIOS just to be sure.

AF asks to run in 16 bit when it thinks it's running too slowly, which I bet it is on a TNT2.

Cas :)
Title: double image appearing
Post by: vilm on January 13, 2004, 10:15:07
Thanks for the advice.  I updated the drivers last week, so I presume it's not that.  I'll have a look for BIOS settings to tweak.
 So, essentially, have I just got a crap video card!?  How much should I pay for a reasonable spec (I'm not interested in the mega top of the range cards)?  Or are there some standard BIOS changes I should set?

Cheers

- vilm

Quote from: "princec"Time for new drivers, methinks. And you might want to check AGP ram is enabled in your BIOS just to be sure.

AF asks to run in 16 bit when it thinks it's running too slowly, which I bet it is on a TNT2.

Cas :)
Title: double image appearing
Post by: Javapunk on January 13, 2004, 14:20:56
Anandtech still likes the Radon 9600 Pro for $85. One of the fastest cards out. There drivers stink though (Alien Flux would not play until I upgraded my dad's drivers for an earlier Radon) they tend to bluescreen. I personally just bought a GeForce FX 5700 for $150. Nice card, nice drivers (and works on linux  :D )