flickering problem

Started by Uli, November 30, 2003, 20:24:24

Previous topic - Next topic

Uli

Could someone please tell why this code results in a flickering window?

import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.Window;

public final class FlickerTestApp {

	// Globale Variablen
	private static boolean running;
	private static long timeToWait;
	private static float colorValue;
	private static float colorStep;
	
	// Constructor, wird nicht verwendet
	private FlickerTestApp() {
	}

	// Main Methode
	public static void main(String args[]) {
		try {
			init();
			
			while (running) {
				update();
				render();
				Window.update();
				Window.paint();
			}
		} catch (Throwable t) {
			t.printStackTrace();
		} finally {
			cleanup();
		}
	}

	// Initialisierung
	private final static void init() throws Exception {
		Window.create("FlickerTest", 0, 0, 640, 480, 16, 0, 8, 0);
		Window.setVSyncEnabled(true);
		System.out.println("VSync: " + Window.isVSyncEnabled());
		Keyboard.create();

		GL.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
		GL.glClearDepth(1.0f);

		GL.glViewport(0, 0, Window.getWidth(), Window.getHeight());
		GL.glMatrixMode(GL.GL_PROJECTION);
		GL.glLoadIdentity();
		GL.glOrtho(0f,Window.getWidth(), 0f, Window.getHeight(), 0.0, -100.0);
		GL.glMatrixMode(GL.GL_MODELVIEW);
		GL.glLoadIdentity();

		GL.glDepthFunc(GL.GL_LEQUAL);
		GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
		GL.glShadeModel(GL.GL_SMOOTH);
		
		timeToWait = Sys.getTimerResolution() / 15;
		Sys.setTime(0);
		colorValue = 0f;
		colorStep = 0.05f;
		running = true;
	}

	private final static void update() {
		Keyboard.poll();
		if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
			running = false;
		}
	}

	
	// Render-Schleife
	private final static void render() {
		if(Sys.getTime() >= timeToWait) {
			Sys.setTime(0);
			colorValue += colorStep;
			if(colorValue >1.0f) {
				colorValue = 1.0f;
				colorStep = -colorStep;
			}
			if(colorValue < 0f) {
				colorValue = 0f;
				colorStep = -colorStep;
			}
			GL.glColor4f(colorValue,colorValue,colorValue,255.0f);
			GL.glBegin(GL.GL_TRIANGLE_STRIP);
				GL.glVertex2i(0, 480);
				GL.glVertex2i(0, 0);
				GL.glVertex2i(640, 480);
				GL.glVertex2i(640, 0);
			GL.glEnd(); 
		}
	}
	
	// Aufräumen
	private final static void cleanup() {
	}
}
[/code]

WiESi

hi uli!

bei mir geht das seltsamerweise. auch wenn ich vsync deaktiviere. vielleicht liegts an deiner graka.

mfg
wiesi

Uli

hi wiesi!

I've got an ATI Radeon 9000. VSync definitly doesn't work, I see "horizontal lines" while redrawing randomly apearing on the screen where the color changes. I never saw this effect with Alien Flux or with one of the NeHe examples.
Maybe I have to write some special initialization code for the Radeon, like Cas did with the NVidiaInitilalizer in SPGL?

princec

No, I've got a Radeon too, and the issue is actually in the drivers. Go into your Desktop properties and muck around with the ATI OpenGL settings. They are probably set to "Performance" rather than "Quality" which disables vsync (pointlessly).

Cas :)

Uli

No, that's not the problem, vsync is enabled in the settings. I got the following output from the program, maybe that gives a hint:

NOTICE: GL_EXT_vertex_shader disabled because of missing driver symbols
NOTICE: OpenGL13 disabled because of missing driver symbols

Numknuf

By doing this:

timeToWait = Sys.getTimerResolution() / 15;

if(Sys.getTime() >= timeToWait)

You're limiting yourself to 15 frames per second, maybe that is your problem?

Uli

seems like flickering only happens in windowed mode....

Mojomonkey

QuoteNOTICE: GL_EXT_vertex_shader disabled because of missing driver symbols

I have a Radeon 9700 Pro and I also get this message after closing the app. Which is strange because Vertex Shader works just fine in non-LWJGL OpenGL apps. 3D Mark uses Vertex Shaders for one test, and it runs fine.
ever send a man to do a monkey's work.

princec

Here's the rub: if anyone using C++ tried to call that function they'd get an instant application crash. It's part of the spec but it's missing from the ATI drivers (not the Nvidia ones).

We, being Java programmers, are more concerned with reliability than C programmers, so we disable the whole extension as it is not correctly implemented in ATI. I suggest writing to ATI and asking them to fix it.

Cas :)

Mojomonkey

Is 3DMark using something else for it's Vertex Shader test then? It runs fine with my 9700 Pro. Maybe they are using an ATI extension?
ever send a man to do a monkey's work.

princec

It's not the whole extension that's missing, just one function which is supposed to be there and which isn't. What are we supposed to do? allow you to call it and crash the JVM? It's not our fault really :/

Cas :)

elias

Well, as far as I know, GL_EXT_vertex_shader _is_ the ATI version. The platform neutral version would be GL_ARB_vertex_program.

Now, 3DMark is a DirectX program, much different from OpenGL.

- elias

Mojomonkey

QuoteNow, 3DMark is a DirectX program, much different from OpenGL.

Doh! Good point. Forgot that.  :oops:
ever send a man to do a monkey's work.