/** * Start the application. The window is opened and the main loop is entered. This call does not * return until the window is closed or an exception was caught. */ public void start() { try { Display.setDisplayMode(new DisplayMode(width, height)); Display.setTitle(title); if (multisampling) Display.create(new PixelFormat().withSamples(8)); else Display.create(); // Sync buffer swap with vertical sync. Results in 60 fps on my Mac // Book. Display.setSwapInterval(1); Display.setVSyncEnabled(true); input = new Input(); application.init(); while (!Display.isCloseRequested()) { input.update(); input.setWindowSize(width, height); application.simulate(time.elapsed(), input); application.display(width, height, input); Display.update(); } } catch (LWJGLException e) { e.printStackTrace(); } finally { Display.destroy(); } }
private void createMacWindow() throws LWJGLException { if (getRenderMode() == RenderMode.GL30) { if (MacOSXUtils.getOSXVersion() >= 7) { ContextAttribs ca = new ContextAttribs(3, 2).withProfileCore(true); Display.create(new PixelFormat(8, 24, 0), ca); } else { throw new UnsupportedOperationException("Cannot create a 3.0 context without OSX 10.7_"); } } else { Display.create(); } }
public static void createDisplay() throws LWJGLException { ImageIO.setUseCache( false); // Disable on-disc stream cache should speed up texture pack reloading. PixelFormat format = new PixelFormat().withDepthBits(24); try { // TODO: Figure out how to determine the max bits. Display.create(format.withStencilBits(8)); stencilBits = 8; } catch (LWJGLException e) { Display.create(format); stencilBits = 0; } }
// *************************************************************************** // initDisplay // *************************************************************************** private static void initDisplay(boolean fullscreen) { DisplayMode chosenMode = null; try { DisplayMode[] modes = Display.getAvailableDisplayModes(); for (int i = 0; i < modes.length; i++) { if ((modes[i].getWidth() == targetWidth) && (modes[i].getHeight() == targetHeight)) { chosenMode = modes[i]; break; } } } catch (LWJGLException e) { Sys.alert("Error", "Unable to determine display modes."); System.exit(0); } // at this point if we have no mode there was no appropriate, let the user know // and give up if (chosenMode == null) { Sys.alert("Error", "Unable to find appropriate display mode."); System.exit(0); } try { Display.setDisplayMode(chosenMode); Display.setFullscreen(fullscreen); Display.setTitle("OpenCraft"); Display.create(); } catch (LWJGLException e) { Sys.alert("Error", "Unable to create display."); System.exit(0); } }
public static void main(String[] args) throws InterruptedException { try { Display.setTitle("Simple Square"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } // draw the square glBegin(GL_LINE_LOOP); glVertex3f(-0.5f, -0.5f, 0f); glVertex3f(-0.5f, 0.5f, 0f); glVertex3f(0.5f, 0.5f, 0f); glVertex3f(0.5f, -0.5f, 0f); glEnd(); // flush any commands that are still hanging about. glFlush(); // update window. Display.update(); while (!Display.isCloseRequested()) { Thread.sleep(100); } Display.destroy(); }
public void start() { try { Display.setDisplayMode(new DisplayMode(800, 600)); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } initGL(); // init OpenGL getDelta(); // call once before loop to initialise lastFrame lastFPS = getTime(); // call before loop to initialise fps timer while (!Display.isCloseRequested()) { int delta = getDelta(); update(delta); renderGL(); Display.update(); Display.sync(60); // cap fps to 60fps } Display.destroy(); }
public void start() { System.out.println("SplitMan starting..."); try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.setResizable(false); Display.setVSyncEnabled(true); Display.setTitle("SplitMan"); Display.create(); } catch (Exception e) { e.printStackTrace(); Display.destroy(); System.exit(1); } WIDTH = Display.getWidth(); HEIGHT = Display.getHeight(); System.out.println("Display: " + WIDTH + " x " + HEIGHT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, WIDTH, HEIGHT, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); Resources.load(); setScreen(new GuiGame()); System.out.println("SplitMan started"); }
private void initialise() { DisplayMode mode = new DisplayMode(WIDTH, HEIGHT); Display.setTitle(TITLE); input = new InputHandler(); display = new CodeDisplay(input); try { Display.setDisplayMode(mode); Display.setResizable(false); Display.create(); if (!GLContext.getCapabilities().OpenGL33) System.err.printf("You must have at least OpenGL 3.3 to run this program\n"); } catch (LWJGLException e) { e.printStackTrace(); System.exit(-1); } // Set clear color glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); // Less than or equal glClearDepth(1.0); establishProjectionMatrix(); // glEnable(GL_LIGHTING); // glEnable(GL_LIGHT0); }
private void initGL() { try { Display.setDisplayMode(new DisplayMode(GS.FRAMEWIDTH, GS.FRAMEHEIGHT)); Display.setFullscreen(true); Display.create(); Display.setVSyncEnabled(true); } catch (LWJGLException e) { e.printStackTrace(); Display.destroy(); System.exit(1); } GL11.glEnable(GL11.GL_TEXTURE_2D); // GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1.0f); // GL11.glEnable(GL11.GL_DEPTH_TEST); // GL11.glDepthFunc(GL11.GL_ADD); //Wenn nicht auskommentiert führt es zu Exception GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glViewport(0, 0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT); GL11.glOrtho(0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT, 0, 0, 128); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // GL11.glBlendEquation( BLENDING_EQUATIONS[blendingEquationIndex]); GL11.glShadeModel(GL11.GL_FLAT); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glAlphaFunc(GL11.GL_GREATER, 0); GL11.glCullFace(GL11.GL_BACK); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); GL11.glLoadIdentity(); }
public void start() { try { Display.setDisplayMode(new DisplayMode(800, 600)); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } initGL(); // init OpenGL try { font = new Font("assets/text.png", "assets/text.txt", 6, 13); font.buildFont(2); // build the textures for text s = new Sprite("assets/pokemon_sprites/front/643.png"); } catch (IOException e) { e.printStackTrace(); System.exit(0); } getDelta(); // call once before loop to initialise lastFrame lastFPS = getTime(); // call before loop to initialise fps timer while (!Display.isCloseRequested() && !finished) { int delta = getDelta(); update(delta); renderGL(); Display.update(); Display.sync(60); // cap fps to 60fps } Display.destroy(); }
/** * Initialise the game * * @throws Exception if init fails */ private static void init() throws Exception { // Create a fullscreen window with 1:1 orthographic 2D projection, and with // mouse, keyboard, and gamepad inputs. Display.setTitle(GAME_TITLE); Display.setFullscreen(true); // Enable vsync if we can Display.setVSyncEnabled(true); Display.create(); // Start up the sound system AL.create(); // TODO: Load in your textures etc here // Put the window into orthographic projection mode with 1:1 pixel ratio. // We haven't used GLU here to do this to avoid an unnecessary dependency. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight()); }
private void init(boolean absolutePixels, boolean testModes) { // find out what the current bits per pixel of the desktop is int currentBpp = Display.getDisplayMode().getBitsPerPixel(); try { DisplayMode mode; if (testModes) mode = findDisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT, currentBpp); else mode = new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT); Display.setDisplayMode(mode); Display.setFullscreen(false); Display.setTitle("src"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } glMatrixMode(GL_PROJECTION); glLoadIdentity(); double aspectRatio = (double) WINDOW_WIDTH / WINDOW_HEIGHT; if (absolutePixels) { glOrtho(0.0d, WINDOW_WIDTH, 0.0d, WINDOW_HEIGHT, 1.0d, -1.0d); } else { glOrtho(aspectRatio, -aspectRatio, -1.0d, 1.0d, 1.0d, -1.0d); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
public void start() { // ウィンドウの生成 try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); // Display.setTitle("SimField"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } initGL(); // メインループ while (!Display.isCloseRequested()) { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); /** * for(Life l : lifeSet.getArray()){ l.renderLife(); } for(Life lr: lifeRedSet.getArray()){ * lr.renderLife(); } for(Life lb: lifeBlueSet.getArray()){ lb.renderLife(); } */ for (Life l : life) { l.renderLife(); } for (Life lr : lifeRed) { lr.renderLife(); } for (Life lb : lifeBlue) { lb.renderLife(); } status.updateFPS(); Display.update(); // オンスクリーンに反映 Display.sync(60); // FPSを60に固定 } }
/** * Create the OpenGL ES context with the given minimum parameters. If isFullscreen() is true or if * windowed context are not supported on the platform, the display mode will be switched to the * mode returned by getDisplayMode(), and a fullscreen context will be created. If isFullscreen() * is false, a windowed context will be created with the dimensions given in the mode returned by * getDisplayMode(). If a context can't be created with the given parameters, a LWJGLException * will be thrown. * * <p> * * <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with * GL coordinates. * * @param pixel_format Describes the minimum specifications the context must fulfill. Must be an * instance of org.lwjgl.opengles.PixelFormat. * @param attribs The ContextAttribs to use when creating the context. (optional, may be null) * @throws LWJGLException */ public static void create( PixelFormatLWJGL pixel_format, org.lwjgl.opengles.ContextAttribs attribs) throws LWJGLException { synchronized (GlobalLock.lock) { create(pixel_format, null, attribs); } }
/** * ************************************************************************************************************************************************************************************************* * Initialization stuff comes in here... * ************************************************************************************************************************************************************************************************ */ private void init() { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setVSyncEnabled(true); Display.setTitle("MS3D Loader [G36C]"); Display.create(); Keyboard.create(); } catch (LWJGLException e) { Sys.alert("Error", "Initialization failed!\n\n" + e.getMessage()); System.exit(0); } /* OpenGL */ int width = Display.getDisplayMode().getWidth(); int height = Display.getDisplayMode().getHeight(); GL11.glViewport(0, 0, width, height); // Reset The Current Viewport GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix GL11.glLoadIdentity(); // Reset The Projection Matrix GLU.gluPerspective( 45.0f, ((float) width / (float) height), 0.1f, 1000.0f); // Calculate The Aspect Ratio Of The Window GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix GL11.glLoadIdentity(); // Reset The Modelview Matrix GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Background color GL11.glClearDepth(1.0f); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); // Load model // g36c = new // MS3DModel(resourceLoader.loadResourceAsStream("models/gsg9.ms3d"),this.getClass().getResource("./data/textures").getPath()); g36c = new MS3DModel( resourceLoader.loadResourceAsStream("models/assassin.ms3d"), this.getClass().getResource("./data/textures").getPath()); // tdsLoader=new TDSLoader(); // try { // tdsLoader.load(resourceLoader.loadResourceAsStream("models/face.3ds")); // System.out.println(tdsLoader.getObjectSize()); // } catch (IOException e) { // e.printStackTrace(); // } // Load font font = new Font(resourceLoader.loadResourceAsStream("textures/font.bmp"), 12, width, height); // Init timer timer = new Timer(); }
public Render(Level level) { this.level = level; try { Display.setFullscreen(true); } catch (LWJGLException e) { e.printStackTrace(); } // Enable vsync if we can Display.setVSyncEnabled(true); try { Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } // Put the window into orthographic projection mode with 1:1 pixel // ratio. // We haven't used GLU here to do this to avoid an unnecessary // dependency. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight()); }
public static void main(String[] args) throws Exception { Display.setTitle("TWL Examples"); Display.setDisplayMode(new DisplayMode(800, 600)); Display.setVSyncEnabled(true); Display.create(); TwlTest twlTest = new TwlTest(); twlTest.run(); }
public Game(boolean host) { try { if (host) { System.out.println("Hosting..."); server = new ServerSocket(port, 4, InetAddress.getByName(serverIP)); System.out.println("Ready!\nAwaiting client..."); client = server.accept(); System.out.println("Client connected!\nBuffering..."); out = new ObjectOutputStream(client.getOutputStream()); in = new ObjectInputStream(client.getInputStream()); System.out.println("Buffered!\nPinging for 256 bytes..."); long start = System.currentTimeMillis(); byte[] ping = new byte[256]; in.read(ping); System.out.println("Latency: " + (System.currentTimeMillis() - start)); out.writeLong(start); out.flush(); System.out.println("Starting threads..."); new ThreadSend(world, out); new ThreadReceive(world, in); System.out.println("Started!\nCreating game world..."); } else { System.out.println("Connecting..."); socket = new Socket(connectIP, port); System.out.println("Connected!\nBuffering..."); in = new ObjectInputStream(socket.getInputStream()); out = new ObjectOutputStream(socket.getOutputStream()); byte[] ping = new byte[256]; new Random().nextBytes(ping); System.out.println("Buffered\nPinging for 256 bytes..."); out.write(ping); out.flush(); long latency = in.readLong(); System.out.println("Latency: " + (System.currentTimeMillis() - latency)); System.out.println("Starting threads..."); new ThreadReceive(world, in); new ThreadSend(world, out); System.out.println("Started!\nCreating game world..."); } } catch (Exception e) { e.printStackTrace(); } try { Display.setDisplayMode(new DisplayMode(width, height)); Display.create(); } catch (Exception e) { e.printStackTrace(); } world.init(); while (!Display.isCloseRequested()) { if (ended) break; world.update(); } Display.destroy(); }
public static void setWindowResolution(int width, int height) { Globals.windowWidth = width; Globals.windowHeight = height; Globals.aspectRatio = (float) Globals.windowWidth / (float) Globals.windowHeight; Globals.windowMatrix.set( 1 / Globals.aspectRatio, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); // for(IWindowChangeListener lis : Globals.windowChangeListener) // { // lis.onWindowResolutionChange(Globals.windowWidth, Globals.windowHeight); // } try { DisplayMode[] modes = Display.getAvailableDisplayModes(); DisplayMode finalMode = new DisplayMode(Globals.getWindowWidth(), Globals.getWindowHeight()); for (int i = 0; i < modes.length; i++) { DisplayMode current = modes[i]; if (current.getWidth() == Globals.getWindowWidth() && current.getHeight() == Globals.getWindowHeight() && current.getBitsPerPixel() == 32 && current.getFrequency() == 60) finalMode = current; } Display.setDisplayMode(finalMode); if (!Display.isCreated()) { PixelFormat pixelFormat = new PixelFormat(); ContextAttribs contextAtrributes = new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true); Display.create(pixelFormat, contextAtrributes); } GL11.glViewport(0, 0, Globals.getWindowWidth(), Globals.getWindowHeight()); } catch (LWJGLException e) { e.printStackTrace(); System.exit(-1); } Display.update(); }
public static void create() { try { Display.create(); Mouse.create(); Keyboard.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(1); } }
/** Setups the Display */ private void initDisplay() throws LWJGLException { Display.setDisplayMode(standartDisplayMode); Display.setResizable(true); Display.setVSyncEnabled(true); Display.setTitle("LLC - " + VERSION); Display.create(); Keyboard.create(); Mouse.create(); }
private static void setUpDisplay() { try { Display.setDisplayMode(new DisplayMode(WINDOW_DIMENSIONS[0], WINDOW_DIMENSIONS[1])); Display.setTitle(WINDOW_TITLE); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); cleanUp(true); } }
private void createWindow() { try { Display.setDisplayMode(DISPLAY_MODE); Display.setFullscreen(fullscreen); Display.setTitle(WINDOW_TITLE); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } }
private void setUpDisplay() { try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.setTitle("Pong"); Display.create(); } catch (LWJGLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void start() { try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.create(); Display.setFullscreen(true); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_ALPHA); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glClearAccum(0f, 0f, 0f, 1f); GL11.glClear(GL11.GL_ACCUM_BUFFER_BIT); while (!Display.isCloseRequested() && !finished) { if (System.currentTimeMillis() - time > 1000) { System.out.println(framecount + " FPS"); time = System.currentTimeMillis(); framecount = 0; } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GL11.glColor3f(1, 1, 1); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10); Manager.DrawBackground(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10); GL11.glTranslatef(-Camera.x, -Camera.y, 0); Display.sync(60); Manager.Draw(); Manager.Update(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10); Manager.DrawForeground(); Display.update(); framecount++; } }
private static void setUpDisplay() { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setVSyncEnabled(true); Display.setTitle("Core Lighting Demo"); Display.create(); } catch (LWJGLException e) { System.err.println("The display wasn't initialized correctly. :("); Display.destroy(); System.exit(1); } }
private void doRenderLoop() { try { while (!isDisplayable()) { Thread.sleep(50); } Display.setParent(this); Display.setVSyncEnabled(true); Display.create(); mMouseState = new boolean[Mouse.getButtonCount()]; for (int i = 0; i < mMouseState.length; i++) { mMouseState[i] = Mouse.isButtonDown(i); } // GL11.glsetSwapInterval(1); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // gl11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glClearDepth(1.0); GL11.glLineWidth(2); GL11.glEnable(GL11.GL_DEPTH_TEST); if (mScene.getAmbientLight() != null) { GL11.glEnable(GL11.GL_LIGHTING); GL11.glLightModel( GL11.GL_LIGHT_MODEL_AMBIENT, Color4fLogic.toFloatBuffer(mScene.getAmbientLight())); } if (mScene.getColorMaterialFace() != JGLColorMaterialFace.UNSET) { initMaterial(); } if (mScene.getFogMode() != JGLFogMode.UNSET) { initFog(); } Dimension newDim; while (!Display.isCloseRequested() && !mCloseRequested) { newDim = mNewCanvasSize.getAndSet(null); if (newDim != null) { GL11.glViewport(0, 0, newDim.width, newDim.height); syncViewportSize(); } doRender(); doMouse(); doKeys(); doEye(); Display.update(); } Display.destroy(); } catch (InterruptedException | LWJGLException e) { e.printStackTrace(); } }
private void initializeOpenGL() { // Open the program window try { PixelFormat pf = new PixelFormat(24, 8, 24, 0, 16); Display.setDisplayMode(new DisplayMode(boxWidth, boxHeight)); Display.setTitle("Particles"); Display.setVSyncEnabled(true); Display.create(pf); } catch (LWJGLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public Main() { try { Display.setDisplayMode(new DisplayMode(800, 600)); Display.create(); while (!Display.isCloseRequested()) { Display.update(); } Display.destroy(); } catch (LWJGLException e) { e.printStackTrace(); } }
private void createWindow() { try { Display.setDisplayMode(new DisplayMode((int) resolution.getX(), (int) resolution.getY())); if (MacOSXUtils.isMac()) { createMacWindow(); } else { if (getRenderMode() == RenderMode.GL11) { ContextAttribs ca = new ContextAttribs(1, 5); Display.create(new PixelFormat(8, 24, 0), ca); } else if (getRenderMode() == RenderMode.GL20) { ContextAttribs ca = new ContextAttribs(2, 1); Display.create(new PixelFormat(8, 24, 0), ca); } else if (getRenderMode() == RenderMode.GL30) { ContextAttribs ca = new ContextAttribs(3, 2).withForwardCompatible(false); Display.create(new PixelFormat(8, 24, 0), ca); } } Display.setTitle("Spout Client"); } catch (LWJGLException e) { e.printStackTrace(); } }