Ich versuche, die Frames pro Sekunde auf meinem HTML-Canvas anzuzeigen. Es macht mir nichts aus, wo es auf der Leinwand für jetzt platziert wird, da ich es zu späterer Zeit zwicken kann. Hier ist, was ich bisher:Wie kann ich FPS in WebGL aufzeichnen und anzeigen?
var updateAnimation = function() {
requestAnimFrame(updateAnimation);
var anim = global.animation;
var e = global.events;
//Set current time
anim.animationCurrentTime = Date.now();
//Set start time
if (anim.animationStartTime === undefined) {
anim.animationStartTime = anim.animationCurrentTime;
}
//Clear the animationStage
webgl.clear(webgl.COLOR_BUFFER_BIT | webgl.DEPTH_BUFFER_BIT);
//Draw scene
drawScene();
//Set previous time as current time to use in next frame
anim.animationLastTime = anim.animationCurrentTime;
}
global.document.animationStage = document.getElementById("animation-scene");
webgl = setupScene(global.document.animationStage);
setupShaders();
setupAllBuffers();
setupEvents();
setupLight();
setupTextures();
initScene();
}
<header>
<h1 style="text-align: center">Applied Computer Graphics and Vision</h1>
<p>Instructions<span>
<br />
<br />
Rotation - \t Click and drag in the direction of rotation <br />
Increase/Decrease Orbit Radius - Up and Down Keys <br />
Increase/Decrease Orbit Speed - Left and Right Keys <br />
Translation Of X - Shift plus mouse drag <br />
Translation Of Y - Alt plus mouse drag <br />
Translation Of Z - Mouse scroll
</span></p>
</header>
<canvas style="float:left" ; id="animation-scene"></canvas>
<canvas id="myCanvas" width="1400" height="800"></canvas>
<script>
\t /* Sets */
var area = document.getElementById('animation-scene');
area.setAttribute('height', window.innerHeight);
area.setAttribute('width', window.innerWidth);
</script>
</body>
</html>
Jede Hilfe oder Ratschläge wäre toll. Ich kenne die Grundidee, die Anzahl der gerenderten Frames zählen zu müssen, und sobald eine Sekunde vergangen ist, speichere das in der fps-Variablen, aber bin mir nicht sicher, wie ich das über meine Update-Animationsfunktion implementieren soll.
Ich habe auch Methoden, die die aktuelle/Startzeit für die Szene innerhalb der Update-Animation-Funktion setzt.
einen Blick auf https://github.com/mrdoob/stats.js/ – gaitat