private void run() { int frames = 0; double nsPerFrame = 1000000000.0 / 60.0; double unProcessed = 0; long lastFrameTime = System.nanoTime(); long currentFrameTime = System.currentTimeMillis(); while (running) { long now = System.nanoTime(); unProcessed += (now - lastFrameTime) / nsPerFrame; lastFrameTime = now; if (Display.isCloseRequested()) running = false; while (unProcessed > 1) { unProcessed -= 1; tick(); display.render(); } frames++; if (System.currentTimeMillis() - currentFrameTime > 1000) { currentFrameTime += 1000; // Print.line(frames + " fps"); Display.setTitle(frames + " fps"); frames = 0; } Display.sync(60); Display.update(); } Display.destroy(); }
public void run() { init(); engine = new Engine(); long lastTime = System.nanoTime(); double delta = 0.0; // Amout of nanoseconds in 1/60th of a second double ns = 1000000000.0 / 60.0; long timer = System.currentTimeMillis(); int updates = 0; int frames = 0; while (running) { long now = System.nanoTime(); delta += (now - lastTime) / ns; lastTime = now; // if delta >= than one then the amount of time >= 1/60th of a second if (delta >= 1.0) { update(); updates++; delta--; } render(); frames++; // If a second has passed, we print the stats if (System.currentTimeMillis() - timer > 1000) { timer += 1000; System.out.println(updates + " ups, " + frames + " fps"); updates = 0; frames = 0; } if (glfwWindowShouldClose(window) == GL_TRUE) running = false; } engine.CleanUp(); keyCallback.release(); sizeCallback.release(); mouseCallback.release(); focusCallback.release(); glfwDestroyWindow(window); glfwTerminate(); }
void renderLoop() { long startTime = System.currentTimeMillis() + 5000; long fps = 0; while (glfwWindowShouldClose(window.handle) == GLFW_FALSE) { Runnable event; while ((event = events.poll()) != null) event.run(); try { display(); } catch (Exception e) { e.printStackTrace(); break; } glfwSwapBuffers(window.handle); if (startTime > System.currentTimeMillis()) { fps++; } else { long timeUsed = 5000 + (startTime - System.currentTimeMillis()); startTime = System.currentTimeMillis() + 5000; log( String.format( "%s: %d frames in 5 seconds = %.2f", getPlatformInfoStringUTF8(platform, CL_PLATFORM_VENDOR), fps, fps / (timeUsed / 1000f))); fps = 0; } } cleanup(); window.signal.countDown(); }
public void drawScreen(int mouseX, int mouseY, float p_22243_3_) { this.mouseX = mouseX; this.mouseY = mouseY; this.drawBackground(); int listLength = this.getSize(); int scrollBarXStart = this.left + this.listWidth - 6; int scrollBarXEnd = scrollBarXStart + 6; int boxLeft = this.left; int boxRight = scrollBarXStart - 1; int var10; int var11; int var13; int var19; if (Mouse.isButtonDown(0)) { if (this.initialMouseClickY == -1.0F) { boolean var7 = true; if (mouseY >= this.top && mouseY <= this.bottom) { var10 = mouseY - this.top - this.field_27261_r + (int) this.scrollDistance - 4; var11 = var10 / this.slotHeight; if (mouseX >= boxLeft && mouseX <= boxRight && var11 >= 0 && var10 >= 0 && var11 < listLength) { boolean var12 = var11 == this.selectedIndex && System.currentTimeMillis() - this.lastClickTime < 250L; this.elementClicked(var11, var12); this.selectedIndex = var11; this.lastClickTime = System.currentTimeMillis(); } else if (mouseX >= boxLeft && mouseX <= boxRight && var10 < 0) { this.func_27255_a(mouseX - boxLeft, mouseY - this.top + (int) this.scrollDistance - 4); var7 = false; } if (mouseX >= scrollBarXStart && mouseX <= scrollBarXEnd) { this.scrollFactor = -1.0F; var19 = this.getContentHeight() - (this.bottom - this.top - 4); if (var19 < 1) { var19 = 1; } var13 = (int) ((float) ((this.bottom - this.top) * (this.bottom - this.top)) / (float) this.getContentHeight()); if (var13 < 32) { var13 = 32; } if (var13 > this.bottom - this.top - 8) { var13 = this.bottom - this.top - 8; } this.scrollFactor /= (float) (this.bottom - this.top - var13) / (float) var19; } else { this.scrollFactor = 1.0F; } if (var7) { this.initialMouseClickY = mouseY; } else { this.initialMouseClickY = -2.0F; } } else { this.initialMouseClickY = -2.0F; } } else if (this.initialMouseClickY >= 0.0F) { this.scrollDistance -= (mouseY - this.initialMouseClickY) * this.scrollFactor; this.initialMouseClickY = mouseY; } } else { while (Mouse.next()) { int var16 = Mouse.getEventDWheel(); if (var16 != 0) { if (var16 > 0) { var16 = -1; } else if (var16 < 0) { var16 = 1; } this.scrollDistance += var16 * this.slotHeight / 2; } } this.initialMouseClickY = -1.0F; } this.applyScrollLimits(); this.enableClipping(this.top, this.bottom); glDisable(GL_LIGHTING); glDisable(GL_FOG); Tessellator var18 = Tessellator.instance; // glBindTexture(GL_TEXTURE_2D, // this.client.renderEngine.getTexture("/gui/background.png")); glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glColor4f(0.0F, 0.0F, 0.0F, 0.5F); float var17 = 32.0F; var18.startDrawingQuads(); // var18.setColorOpaque_I(2105376); var18.addVertexWithUV( this.left, this.bottom, 0.0D, this.left / var17, (this.bottom + (int) this.scrollDistance) / var17); var18.addVertexWithUV( this.right, this.bottom, 0.0D, this.right / var17, (this.bottom + (int) this.scrollDistance) / var17); var18.addVertexWithUV( this.right, this.top, 0.0D, this.right / var17, (this.top + (int) this.scrollDistance) / var17); var18.addVertexWithUV( this.left, this.top, 0.0D, this.left / var17, (this.top + (int) this.scrollDistance) / var17); var18.draw(); glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); var10 = this.top + 4 - (int) this.scrollDistance; if (this.field_27262_q) { this.func_27260_a(boxRight, var10, var18); } int var14; for (var11 = 0; var11 < listLength; ++var11) { var19 = var10 + var11 * this.slotHeight + this.field_27261_r; var13 = this.slotHeight - 4; if (var19 <= this.bottom && var19 + var13 >= this.top) { if (this.field_25123_p && this.isSelected(var11)) { var14 = boxLeft; int var15 = boxRight; glColor4f(1.0F, 1.0F, 1.0F, 1.0F); glDisable(GL_TEXTURE_2D); var18.startDrawingQuads(); var18.setColorOpaque_I(8421504); var18.addVertexWithUV(var14, var19 + var13 + 2, 0.0D, 0.0D, 1.0D); var18.addVertexWithUV(var15, var19 + var13 + 2, 0.0D, 1.0D, 1.0D); var18.addVertexWithUV(var15, var19 - 2, 0.0D, 1.0D, 0.0D); var18.addVertexWithUV(var14, var19 - 2, 0.0D, 0.0D, 0.0D); var18.setColorOpaque_I(0); var18.addVertexWithUV(var14 + 1, var19 + var13 + 1, 0.0D, 0.0D, 1.0D); var18.addVertexWithUV(var15 - 1, var19 + var13 + 1, 0.0D, 1.0D, 1.0D); var18.addVertexWithUV(var15 - 1, var19 - 1, 0.0D, 1.0D, 0.0D); var18.addVertexWithUV(var14 + 1, var19 - 1, 0.0D, 0.0D, 0.0D); var18.draw(); glEnable(GL_TEXTURE_2D); } this.drawSlot(var11, boxRight, var19, var13, var18); } } glDisable(GL_DEPTH_TEST); byte var20 = 4; // this.overlayBackground(0, this.top, 255, 255); // this.overlayBackground(this.bottom, this.listHeight, 255, 255); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_ALPHA_TEST); glShadeModel(GL_SMOOTH); glDisable(GL_TEXTURE_2D); var18.startDrawingQuads(); var18.setColorRGBA_I(0, 0); var18.addVertexWithUV(this.left, this.top + var20, 0.0D, 0.0D, 1.0D); var18.addVertexWithUV(this.right, this.top + var20, 0.0D, 1.0D, 1.0D); var18.setColorRGBA_I(0, 255); var18.addVertexWithUV(this.right, this.top, 0.0D, 1.0D, 0.0D); var18.addVertexWithUV(this.left, this.top, 0.0D, 0.0D, 0.0D); var18.draw(); var18.startDrawingQuads(); var18.setColorRGBA_I(0, 255); var18.addVertexWithUV(this.left, this.bottom, 0.0D, 0.0D, 1.0D); var18.addVertexWithUV(this.right, this.bottom, 0.0D, 1.0D, 1.0D); var18.setColorRGBA_I(0, 0); var18.addVertexWithUV(this.right, this.bottom - var20, 0.0D, 1.0D, 0.0D); var18.addVertexWithUV(this.left, this.bottom - var20, 0.0D, 0.0D, 0.0D); var18.draw(); var19 = this.getContentHeight() - (this.bottom - this.top - 4); if (var19 > 0) { var13 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight(); if (var13 < 32) { var13 = 32; } if (var13 > this.bottom - this.top - 8) { var13 = this.bottom - this.top - 8; } var14 = (int) this.scrollDistance * (this.bottom - this.top - var13) / var19 + this.top; if (var14 < this.top) { var14 = this.top; } var18.startDrawingQuads(); var18.setColorRGBA_I(0, 255); var18.addVertexWithUV(scrollBarXStart, this.bottom, 0.0D, 0.0D, 1.0D); var18.addVertexWithUV(scrollBarXEnd, this.bottom, 0.0D, 1.0D, 1.0D); var18.addVertexWithUV(scrollBarXEnd, this.top, 0.0D, 1.0D, 0.0D); var18.addVertexWithUV(scrollBarXStart, this.top, 0.0D, 0.0D, 0.0D); var18.draw(); var18.startDrawingQuads(); var18.setColorRGBA_I(8421504, 255); var18.addVertexWithUV(scrollBarXStart, var14 + var13, 0.0D, 0.0D, 1.0D); var18.addVertexWithUV(scrollBarXEnd, var14 + var13, 0.0D, 1.0D, 1.0D); var18.addVertexWithUV(scrollBarXEnd, var14, 0.0D, 1.0D, 0.0D); var18.addVertexWithUV(scrollBarXStart, var14, 0.0D, 0.0D, 0.0D); var18.draw(); var18.startDrawingQuads(); var18.setColorRGBA_I(12632256, 255); var18.addVertexWithUV(scrollBarXStart, var14 + var13 - 1, 0.0D, 0.0D, 1.0D); var18.addVertexWithUV(scrollBarXEnd - 1, var14 + var13 - 1, 0.0D, 1.0D, 1.0D); var18.addVertexWithUV(scrollBarXEnd - 1, var14, 0.0D, 1.0D, 0.0D); var18.addVertexWithUV(scrollBarXStart, var14, 0.0D, 0.0D, 0.0D); var18.draw(); } this.func_27257_b(mouseX, mouseY); glEnable(GL_TEXTURE_2D); glShadeModel(GL_FLAT); glEnable(GL_ALPHA_TEST); glDisable(GL_BLEND); this.disableClipping(); }
private void handleInput() { while (Keyboard.next()) { if (Keyboard.isRepeatEvent()) { continue; } if (!Keyboard.getEventKeyState()) { continue; } if (Keyboard.getEventKey() == Keyboard.KEY_A) { broadcastController.requestAuthToken(username, password); } else if (Keyboard.getEventKey() == Keyboard.KEY_S) { broadcastController.setStreamInfo(username, "Java Game", "Fun times"); } else if (Keyboard.getEventKey() == Keyboard.KEY_P) { if (broadcastController.getIsPaused()) { broadcastController.resumeBroadcasting(); } else { broadcastController.pauseBroadcasting(); } } else if (Keyboard.getEventKey() == Keyboard.KEY_SPACE) { if (broadcastController.getIsBroadcasting()) { broadcastController.stopBroadcasting(); } else { VideoParams videoParams = broadcastController.getRecommendedVideoParams( Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), broadcastFramesPerSecond); videoParams.verticalFlip = true; broadcastController.startBroadcasting(videoParams); } } else if (Keyboard.getEventKey() == Keyboard.KEY_R) { broadcastController.runCommercial(); } else if (Keyboard.getEventKey() == Keyboard.KEY_I) { if (ingestTester != null) { broadcastController.cancelIngestTest(); ingestTester = null; } else { ingestTester = broadcastController.startIngestTest(); ingestTester.setListener(this); } } else if (Keyboard.getEventKey() == Keyboard.KEY_G) { broadcastController.requestGameNameList("final"); } else if (Keyboard.getEventKey() == Keyboard.KEY_1) { broadcastController.sendActionMetaData( "TestAction", broadcastController.getCurrentBroadcastTime(), "Something cool happened", "{ \"MyValue\" : \"42\" }"); } else if (Keyboard.getEventKey() == Keyboard.KEY_2) { if (metaDataSpanSequenceId == -1) { metaDataSpanSequenceId = broadcastController.startSpanMetaData( "TestSpan", broadcastController.getCurrentBroadcastTime(), "Something cool just started happening", "{ \"MyValue\" : \"42\" }"); } else { broadcastController.endSpanMetaData( "TestSpan", broadcastController.getCurrentBroadcastTime(), metaDataSpanSequenceId, "Something cool just stopped happening", "{ \"MyValue\" : \"42\" }"); metaDataSpanSequenceId = -1; } } else if (Keyboard.getEventKey() == Keyboard.KEY_C) { if (chatController != null) { if (chatController.getIsConnected()) { chatController.disconnect(); } else { chatController.connect(username); } } } else if (Keyboard.getEventKey() == Keyboard.KEY_V) { if (chatController != null) { if (chatController.getIsConnected()) { chatController.disconnect(); } else { chatController.connectAnonymous(username); } } } else if (Keyboard.getEventKey() == Keyboard.KEY_M) { if (chatController != null) { if (chatController.getIsConnected()) { chatController.sendChatMessage("Test chat message: " + System.currentTimeMillis()); } } } } }
public static void main(String[] args) { /* Setup window */ DisplayManager.createDisplay(); /* Setup renderer and shaders */ StaticShaderProgram shader = new StaticShaderProgram(); Renderer renderer = new Renderer(); /* Load model */ Loader loader = new Loader(); ArrayList<Entity> entities = new ArrayList<Entity>(); Entity armadillo = loader.loadEntity("armadillo"); entities.add(armadillo); Entity e = new Entity(armadillo.getModel()); entities.add(e); // e = new Entity(armadillo.getModel()); entities.add(e); e = new Entity(armadillo.getModel()); entities.add(e); e = new Entity(armadillo.getModel()); entities.add(e); e = new Entity(armadillo.getModel()); entities.add(e); e = new Entity(armadillo.getModel()); entities.add(e); e = new Entity(armadillo.getModel()); entities.add(e); /* * TODO: F�gen Sie die ben�tigte Anzahl von Armadillos in die * Entities-Liste ein. So k�nnen sie weitere Instanzen des Models * erzeugen: Entity entity = new Entity(armadillo.getModel()); */ long lastFrameStart = 0; while (glfwWindowShouldClose(DisplayManager.getWindow()) == GL_FALSE) { long currentTime = System.currentTimeMillis(); long delta = lastFrameStart == 0 ? 0 : currentTime - lastFrameStart; lastFrameStart = currentTime; /* Clear framebuffer */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Animate all Entities in List */ renderer.animate(entities, delta); renderer.render(entities, shader); DisplayManager.updateDisplay(); } shader.cleanUp(); loader.cleanUp(); DisplayManager.closeDisplay(); }
void blink() { blink = (((System.currentTimeMillis() - start) % 700) / 350) == 1; }
/** Created by IntelliJ IDEA. User: SW Date: 29.05.11 Time: 10:40 */ public class TextEditor extends GLBaza { String[] FONT_NAMES = {"141.gif", "056.gif", "034.gif"}; String[][] FONT_MAPS = { {"abcdef", "ghijkl", "mnopqr", "stuvwx", "yz()-0", "123456", "789.:,", "'\"?!`_"}, {"abcdefgh", "ijklmnop", "qrstuvwx", "yz:.!,-\"", " '?)(;"}, {"abcdef", "ghijkl", "mnopqr", "stuvwx", "yz1234", "56789.", ",-:! ", "() ?0 "} }; Font[] fonts = new Font[Math.min(FONT_NAMES.length, FONT_MAPS.length)]; @Override protected void init() { glClearColor(0, 0, 0, 0); glPixelZoom(1, -1); try { for (int i = 0; i < fonts.length; ++i) { fonts[i] = new Font(new File(FONT_NAMES[i]), FONT_MAPS[i], width, height); } } catch (Exception e) { e.printStackTrace(); System.exit(1); } } StringBuilder text = new StringBuilder("To jest edytor\ntekstu! :)\nF1 zmienia czcionke|"); @Override protected void input() { while (Keyboard.next()) { if (Keyboard.getEventKeyState()) { if (Keyboard.getEventKey() == Keyboard.KEY_F1) { font = (font + 1) % fonts.length; } else if (Keyboard.getEventKey() == Keyboard.KEY_BACK && text.length() > 1) { text.deleteCharAt(text.length() - 2); } else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) { text.insert(text.length() - 1, '\n'); } else if (activeFont() .getAvailableChars() .contains(Character.toLowerCase(Keyboard.getEventCharacter()))) { text.insert(text.length() - 1, Keyboard.getEventCharacter()); } } } } int font = 2; long start = System.currentTimeMillis(); boolean blink = true; void blink() { blink = (((System.currentTimeMillis() - start) % 700) / 350) == 1; } Font activeFont() { return fonts[font]; } @Override protected void render() { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); blink(); activeFont().draw(0, 0, text.substring(0, text.length() - (blink ? 1 : 0))); glRasterPos2f(0, 0); glPopMatrix(); } @Override protected void logic() { Utils.sleep60Hz(); } public static void main(String[] args) { new TextEditor().start(); } }