Reputation: 1359
I have a Problem on an other PC (not that one im always working on) with the following Code:
public void run(){
initStuff();
initWindow();
initGl();
initTextures();
initParticles();
long lastFrame = System.currentTimeMillis();
long thisFrame;
long delta;
long time;
while(true){
glPushMatrix();
thisFrame = System.currentTimeMillis();
delta = thisFrame - lastFrame;
lastFrame = thisFrame;
System.out.println("[start loop] (last loop took " + delta + " ms)");
time = System.currentTimeMillis();
System.out.println("---clearing");
time = System.currentTimeMillis();
glClear(GL_COLOR_BUFFER_BIT);
System.out.println("------myupdating (clearing took " + (System.currentTimeMillis() - time) + " ms)");
time = System.currentTimeMillis();
myupdate();
System.out.println("---------painting (mydating took " + (System.currentTimeMillis() - time) + " ms)");
time = System.currentTimeMillis();
draw();
System.out.println("------------syncing (painting took " + (System.currentTimeMillis() - time) + " ms)");
time = System.currentTimeMillis();
Display.sync(60);
System.out.println("---------------disp updating (syncing took " + (System.currentTimeMillis() - time) + " ms)");
time = System.currentTimeMillis();
Display.update();
System.out.println("------------------[end loop] (updating took " + (System.currentTimeMillis() - time) + " ms)");
glPopMatrix();
}
// Display.destroy();
}
private void myupdate(){
}
private void draw(){
background.use();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2d(0, 0);
glTexCoord2f(1, 0);
glVertex2d(800, 0);
glTexCoord2f(1, 1);
glVertex2d(800, 600);
glTexCoord2f(0, 1);
glVertex2d(0, 600);
glEnd();
for(Particle p: particles){
p.getTexture().use();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2d(p.getX(), p.getY());
glTexCoord2f(1, 0);
glVertex2d(p.getX() + p.getWidth(), p.getY());
glTexCoord2f(1, 1);
glVertex2d(p.getX() + p.getWidth(), p.getY() + p.getHeight());
glTexCoord2f(0, 1);
glVertex2d(p.getX(), p.getY() + p.getHeight());
glEnd();
p.setX(p.getX() + 1);
}
So, I added all the time outputs to look where it slows down like this - the Answer is Display.update(). Following output:
[start loop] (last loop took 340 ms)
---clearing
------myupdating (clearing took 0 ms)
---------painting (mydating took 0 ms)
------------syncing (painting took 11 ms)
---------------disp updating (syncing took 0 ms)
------------------[end loop] (updating took 330 ms)
[start loop] (last loop took 341 ms)
---clearing
------myupdating (clearing took 0 ms)
---------painting (mydating took 0 ms)
------------syncing (painting took 12 ms)
---------------disp updating (syncing took 0 ms)
------------------[end loop] (updating took 332 ms)
[start loop] (last loop took 345 ms)
---clearing
------myupdating (clearing took 0 ms)
---------painting (mydating took 0 ms)
------------syncing (painting took 12 ms)
---------------disp updating (syncing took 0 ms)
------------------[end loop] (updating took 331 ms)
[start loop] (last loop took 343 ms)
---clearing
------myupdating (clearing took 0 ms)
---------painting (mydating took 0 ms)
------------syncing (painting took 12 ms)
---------------disp updating (syncing took 0 ms)
So, you see theres something wrong. But what? Contains my Code bad mistakes? I have no idea... Thank you!
Upvotes: 0
Views: 717
Reputation: 14259
Besides that you use heavily outdated OpenGL functionality, you set the frame-rate to 60 FPS. This will cause Display.update()
to block while waiting for the vertical retrace (vsync) during full-screen, which is "working as intended".
In addition many OpenGL functions are "cached" and not immediately executed as one would expect, but internally optimized by the driver and executed at a convenient point (latest at Display.update()
). This usually improves performance and throughput, but as well means that measuring the time of a single OpenGL function becomes close to impossible.
Upvotes: 1