Don't use threads to repaint in test.applet.* tests
This commit is contained in:
parent
6d9aa21e96
commit
17e4a755de
|
@ -41,26 +41,18 @@ public class OpenGL extends AWTGLCanvas implements Test {
|
|||
float angle = 0;
|
||||
|
||||
public OpenGL() throws LWJGLException {
|
||||
Thread t = new Thread() {
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
if (isVisible())
|
||||
repaint();
|
||||
Display.sync(60);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void paintGL() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
public void initGL() {
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0, 640, 0, 480, 1, -1);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);
|
||||
setVSyncEnabled(true);
|
||||
}
|
||||
|
||||
public void paintGL() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(320, 240, 0.0f);
|
||||
|
@ -77,6 +69,8 @@ public class OpenGL extends AWTGLCanvas implements Test {
|
|||
|
||||
try {
|
||||
swapBuffers();
|
||||
if (isVisible())
|
||||
repaint();
|
||||
} catch (Exception e) {/*OK*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,37 +37,11 @@ import org.lwjgl.opengl.GL11;
|
|||
|
||||
public class Speed extends AWTGLCanvas implements Test {
|
||||
|
||||
float angle = 0;
|
||||
private float angle = 0;
|
||||
private long startTime = System.currentTimeMillis() + 5000;
|
||||
private long fps = 0;
|
||||
|
||||
public Speed() throws LWJGLException {
|
||||
Thread t = new Thread() {
|
||||
|
||||
public void run() {
|
||||
long startTime = System.currentTimeMillis() + 5000;
|
||||
long fps = 0;
|
||||
|
||||
while (true) {
|
||||
if (isVisible())
|
||||
repaint();
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException inte) {
|
||||
/* */
|
||||
}
|
||||
if (startTime > System.currentTimeMillis()) {
|
||||
fps++;
|
||||
} else {
|
||||
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
|
||||
startTime = System.currentTimeMillis() + 5000;
|
||||
System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = "
|
||||
+ (fps / (timeUsed / 1000f)));
|
||||
fps = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void paintGL() {
|
||||
|
@ -92,8 +66,19 @@ public class Speed extends AWTGLCanvas implements Test {
|
|||
|
||||
try {
|
||||
swapBuffers();
|
||||
if (isVisible())
|
||||
repaint();
|
||||
} catch (Exception e) {/*OK*/
|
||||
}
|
||||
if (startTime > System.currentTimeMillis()) {
|
||||
fps++;
|
||||
} else {
|
||||
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
|
||||
startTime = System.currentTimeMillis() + 5000;
|
||||
System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = "
|
||||
+ (fps / (timeUsed / 1000f)));
|
||||
fps = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
|
Loading…
Reference in New Issue