private void submitFrame() { if (!broadcastController.getIsBroadcasting() || broadcastController.getIsPaused()) { return; } long curTime = System.nanoTime(); long nanoPerFrame = 1000000000 / broadcastFramesPerSecond; // If you send frames too quickly to the SDK (based on the broadcast FPS you configured) it will // not be able // to make use of them all. In that case, it will simply release buffers without using them // which means the // game wasted time doing the capture. To mitigate this, the app should pace the captures to // the broadcast FPS. long captureDelta = curTime - lastCaptureTime; boolean isTimeForNextCapture = captureDelta >= nanoPerFrame; if (!isTimeForNextCapture) { return; } FrameBuffer buffer = broadcastController.getNextFreeBuffer(); broadcastController.captureFrameBuffer_ReadPixels(buffer); broadcastController.submitFrame(buffer); lastCaptureTime = curTime; }
private void loop() { long lastFrameTime = 0; while (!Display.isCloseRequested()) { long now = System.nanoTime(); long renderFps = 30; long nanoPerFrame = 1000000000 / renderFps; // update the animation if (now - lastFrameTime >= nanoPerFrame) { lastFrameTime = now; angle += 2.0f; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); glRotatef(view_roty, 0.0f, 1.0f, 0.0f); glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(-3.0f, -2.0f, 0.0f); glRotatef(angle, 0.0f, 0.0f, 1.0f); glCallList(gear1); glPopMatrix(); glPushMatrix(); glTranslatef(3.1f, -2.0f, 0.0f); glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); glCallList(gear2); glPopMatrix(); glPushMatrix(); glTranslatef(-3.1f, 4.2f, 0.0f); glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); glCallList(gear3); glPopMatrix(); glPopMatrix(); Display.update(); } handleInput(); if (broadcastController != null) { submitFrame(); broadcastController.update(); } if (chatController != null) { chatController.update(); } } }