/** * Start the game container * * @throws Exception Failure to create display */ public void start() throws Exception { Display.setParent(displayParent); Display.setVSyncEnabled(true); try { createDisplay(); } catch (LWJGLException e) { e.printStackTrace(); // failed to create Display, apply workaround (sleep for 1 second) and try again Thread.sleep(1000); createDisplay(); } initGL(); displayParent.requestFocus(); container.runloop(); }
/** * Indicate whether we want to be in fullscreen mode. Note that the current * display mode must be valid as a fullscreen mode for this to work * * @param fullscreen True if we want to be in fullscreen mode * @throws SlickException Indicates we failed to change the display mode */ public void setFullscreen(boolean fullscreen) throws SlickException { if (isFullscreen() == fullscreen) { return; } if (!fullscreen) { try { Display.setFullscreen(fullscreen); } catch (LWJGLException e) { throw new SlickException("Unable to set fullscreen="+fullscreen, e); } } else { setDisplayMode(width, height, fullscreen); } getDelta(); }
/** * Get a cursor based on a set of image data * * @param buf The image data (stored in RGBA) to load the cursor from * @param x The x-coordinate of the cursor hotspot (left -> right) * @param y The y-coordinate of the cursor hotspot (bottom -> top) * @param width The width of the image data provided * @param height The height of the image data provided * @return The create cursor * @throws IOException Indicates a failure to load the image * @throws LWJGLException Indicates a failure to create the hardware cursor */ public Cursor getCursor(ByteBuffer buf,int x,int y,int width,int height) throws IOException, LWJGLException { for (int i=0;i<buf.limit();i+=4) { byte red = buf.get(i); byte green = buf.get(i+1); byte blue = buf.get(i+2); byte alpha = buf.get(i+3); buf.put(i+2, red); buf.put(i+1, green); buf.put(i, blue); buf.put(i+3, alpha); } try { int yspot = height - y - 1; if (yspot < 0) { yspot = 0; } return new Cursor(width,height, x, yspot, 1, buf.asIntBuffer(), null); } catch (Throwable e) { Log.info("Chances are you cursor is too small for this platform"); throw new LWJGLException(e); } }
/** * Get a cursor based on a set of image data * * @param imageData The data from which the cursor can read it's contents * @param x The x-coordinate of the cursor hotspot (left -> right) * @param y The y-coordinate of the cursor hotspot (bottom -> top) * @return The create cursor * @throws IOException Indicates a failure to load the image * @throws LWJGLException Indicates a failure to create the hardware cursor */ public Cursor getCursor(ImageData imageData,int x,int y) throws IOException, LWJGLException { ByteBuffer buf = imageData.getImageBufferData(); for (int i=0;i<buf.limit();i+=4) { byte red = buf.get(i); byte green = buf.get(i+1); byte blue = buf.get(i+2); byte alpha = buf.get(i+3); buf.put(i+2, red); buf.put(i+1, green); buf.put(i, blue); buf.put(i+3, alpha); } try { int yspot = imageData.getHeight() - y - 1; if (yspot < 0) { yspot = 0; } return new Cursor(imageData.getTexWidth(), imageData.getTexHeight(), x, yspot, 1, buf.asIntBuffer(), null); } catch (Throwable e) { Log.info("Chances are you cursor is too small for this platform"); throw new LWJGLException(e); } }
/** * @see org.newdawn.slick.Graphics#disable() */ protected void disable() { // Bind the texture after rendering. GL11.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID()); GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 0, 0, image.getTexture().getTextureWidth(), image.getTexture().getTextureHeight(), 0); try { Display.makeCurrent(); } catch (LWJGLException e) { Log.error(e); } SlickCallable.leaveSafeBlock(); }
public static void createDisplay() { ContextAttribs attribs = new ContextAttribs(3, 2) .withForwardCompatible(true) .withProfileCore(true); try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.create(new PixelFormat(), attribs); Display.setTitle("MRCEngine"); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glViewport(0, 0, WIDTH, HEIGHT); lastFrameTime = getCurrentTime(); }
public static void main(String... args){ System.setProperty("org.lwjgl.librarypath", new File("native/"+(System.getProperties().getProperty("os.name").split(" ")[0]).toLowerCase()).getAbsolutePath()); FreeWorld.getFreeWorld(); try { Display.setTitle(FreeWorld.getFreeWorld().getTitle()); Display.setDisplayMode(new DisplayMode(720, 480)); Display.setResizable(true); Display.create(); }catch (LWJGLException e){ e.printStackTrace(); } //TODO: Provisoire glClearColor(0.2f, 0.7f, 0.7f, 1.0f); FreeWorld.getFreeWorld().start(); }
protected Window(Context context, WindowBuilder settings) { this.fpsCap = settings.getFpsCap(); try { getSuitableFullScreenModes(); DisplayMode resolution = getStartResolution(settings); Display.setInitialBackground(1, 1, 1); this.aspectRatio = (float) resolution.getWidth() / resolution.getHeight(); setResolution(resolution, settings.isFullScreen()); if (settings.hasIcon()) { Display.setIcon(settings.getIcon()); } Display.setVSyncEnabled(settings.isvSync()); Display.setTitle(settings.getTitle()); Display.create(new PixelFormat().withDepthBits(24).withSamples(4), context.getAttribs()); GL11.glViewport(0, 0, resolution.getWidth(), resolution.getHeight()); } catch (LWJGLException e) { e.printStackTrace(); } }
/** * Initialise OpenAL LWJGL styley */ public void init() { try { AL.create(); soundWorks = true; } catch (LWJGLException e) { System.err.println("Failed to initialise LWJGL OpenAL"); soundWorks = false; return; } if (soundWorks) { IntBuffer sources = BufferUtils.createIntBuffer(1); AL10.alGenSources(sources); if (AL10.alGetError() != AL10.AL_NO_ERROR) { System.err.println("Failed to create sources"); soundWorks = false; } else { source = sources.get(0); } } }
public static void BeginSession(){ Display.setTitle(TITLE); try { Display.setDisplayMode(new DisplayMode(WIDTH + MENU_WIDTH, HEIGHT)); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, WIDTH + MENU_WIDTH, HEIGHT, 0, 1, -1); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }
/** * @see org.newdawn.slick.Graphics#disable() */ protected void disable() { GL.flush(); // Bind the texture after rendering. GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID()); pbuffer.bindTexImage(Pbuffer.FRONT_LEFT_BUFFER); try { Display.makeCurrent(); } catch (LWJGLException e) { Log.error(e); } SlickCallable.leaveSafeBlock(); }
public static DisplayMode getDisplayMode(Dimension p_getDisplayMode_0_) throws LWJGLException { DisplayMode[] adisplaymode = Display.getAvailableDisplayModes(); for (int i = 0; i < adisplaymode.length; ++i) { DisplayMode displaymode = adisplaymode[i]; if (displaymode.getWidth() == p_getDisplayMode_0_.width && displaymode.getHeight() == p_getDisplayMode_0_.height && (desktopDisplayMode == null || displaymode.getBitsPerPixel() == desktopDisplayMode.getBitsPerPixel() && displaymode.getFrequency() == desktopDisplayMode.getFrequency())) { return displaymode; } } return desktopDisplayMode; }
private void createDisplay() throws LWJGLException { Display.setResizable(true); Display.setTitle("Minecraft 1.8.8"); try { Display.create((new PixelFormat()).withDepthBits(24)); } catch (LWJGLException lwjglexception) { logger.error((String) "Couldn\'t set pixel format", (Throwable) lwjglexception); try { Thread.sleep(1000L); } catch (InterruptedException var3) { ; } if (this.fullscreen) { this.updateDisplayMode(); } Display.create(); } }
public static void main(String[] args) { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setTitle("A Fresh New Display"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); Display.destroy(); System.exit(1); } while (!Display.isCloseRequested()) { // render code // input handling code // refresh display and poll input Display.update(); // Maintain a 60fps frame rate Display.sync(60); } Display.destroy(); System.exit(0); }
public static void createDisplay() { // OpenGL version used ContextAttribs attribs = new ContextAttribs(3, 2) .withForwardCompatible(true) .withProfileCore(true); try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.create(new PixelFormat(), attribs); Display.setTitle(TITLE); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glViewport(0, 0, WIDTH, HEIGHT); }
public static void main(String[] args) { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setTitle("Display Test"); Display.create(); // create() throws LWJGLException } catch (LWJGLException e) { System.err.println("Display wasn't initialized correctly."); // Throws an exit code of 1 System.exit(1); } // While nobody is trying to close the window while (!Display.isCloseRequested()) { Display.update(); // FPS is the parameter Display.sync(60); } }
protected Window(Context context, WindowBuilder settings) { this.fpsCap = settings.getFpsCap(); try { getSuitableFullScreenModes(); DisplayMode resolution = getStartResolution(settings); Display.setInitialBackground(0f, 0f, 0f); this.aspectRatio = (float) resolution.getWidth() / resolution.getHeight(); setResolution(resolution, settings.isFullScreen()); if (settings.hasIcon()) { Display.setIcon(settings.getIcon()); } Display.setVSyncEnabled(settings.isvSync()); Display.setTitle(settings.getTitle()); Display.create(new PixelFormat().withDepthBits(24).withSamples(4), context.getAttribs()); GL11.glViewport(0, 0, resolution.getWidth(), resolution.getHeight()); } catch (LWJGLException e) { e.printStackTrace(); } }
/** * @deprecated not a stable API, will break, don't use this yet */ @Deprecated public static void resume() { if(!enabled) return; checkThreadState(); pause = false; try { Display.getDrawable().releaseContext(); d.makeCurrent(); } catch (LWJGLException e) { e.printStackTrace(); throw new RuntimeException(e); } lock.unlock(); }
/** * Resizes the window and the Minecraft rendering if necessary. Set renderWidth and renderHeight first. */ private void resizeIfNeeded() { // resize the window if we need to int oldRenderWidth = Display.getWidth(); int oldRenderHeight = Display.getHeight(); if( this.renderWidth == oldRenderWidth && this.renderHeight == oldRenderHeight ) return; try { Display.setDisplayMode(new DisplayMode(this.renderWidth, this.renderHeight)); System.out.println("Resized the window"); } catch (LWJGLException e) { System.out.println("Failed to resize the window!"); e.printStackTrace(); } forceResize(this.renderWidth, this.renderHeight); }
@Override public void init() { if (!AL.isCreated()) { try { AL.create(); } catch (LWJGLException e) { e.printStackTrace(); } allSources = new IntArray(SIMULTANEOUS_SOURCES_COUNT); for (int i = 0; i < SIMULTANEOUS_SOURCES_COUNT; i++) { int sourceID = AL10.alGenSources(); if (AL10.alGetError() == AL10.AL_NO_ERROR) { allSources.add(sourceID); } } idleSources = new IntArray(allSources); recentSounds = new SoundPoolImpl[SIMULTANEOUS_SOURCES_COUNT]; AL10.alListener(AL10.AL_ORIENTATION, orientation); AL10.alListener(AL10.AL_VELOCITY, velocity); AL10.alListener(AL10.AL_POSITION, position); } }
/** * Enable shared OpenGL context. After calling this all containers created * will shared a single parent context * * @throws SlickException Indicates a failure to create the shared drawable */ public static void enableSharedContext() throws SlickException { try { SHARED_DRAWABLE = new Pbuffer(64, 64, new PixelFormat(8, 0, 0), null); } catch (LWJGLException e) { throw new SlickException("Unable to create the pbuffer used for shard context, buffers not supported", e); } }
/** * Try creating a display with the given format * * @param format The format to attempt * @throws LWJGLException Indicates a failure to support the given format */ private void tryCreateDisplay(PixelFormat format) throws LWJGLException { if (SHARED_DRAWABLE == null) { Display.create(format); } else { Display.create(format, SHARED_DRAWABLE); } }
/** * @see org.newdawn.slick.GameContainer#setDefaultMouseCursor() */ public void setDefaultMouseCursor() { try { Mouse.setNativeCursor(null); } catch (LWJGLException e) { Log.error("Failed to reset mouse cursor", e); } }
/** * Get a cursor based on a image reference on the classpath * * @param ref The reference to the image to be loaded * @param x The x-coordinate of the cursor hotspot (left -> right) * @param y The y-coordinate of the cursor hotspot (bottom -> top) * @return The create cursor * @throws IOException Indicates a failure to load the image * @throws LWJGLException Indicates a failure to create the hardware cursor */ public Cursor getCursor(String ref,int x,int y) throws IOException, LWJGLException { LoadableImageData imageData = null; imageData = ImageDataFactory.getImageDataFor(ref); imageData.configureEdging(false); ByteBuffer buf = imageData.loadImage(ResourceLoader.getResourceAsStream(ref), true, true, null); for (int i=0;i<buf.limit();i+=4) { byte red = buf.get(i); byte green = buf.get(i+1); byte blue = buf.get(i+2); byte alpha = buf.get(i+3); buf.put(i+2, red); buf.put(i+1, green); buf.put(i, blue); buf.put(i+3, alpha); } try { int yspot = imageData.getHeight() - y - 1; if (yspot < 0) { yspot = 0; } return new Cursor(imageData.getTexWidth(), imageData.getTexHeight(), x, yspot, 1, buf.asIntBuffer(), null); } catch (Throwable e) { Log.info("Chances are you cursor is too small for this platform"); throw new LWJGLException(e); } }
/** * Initialise the GL display * * @param width The width of the display * @param height The height of the display */ private void initGL(int width, int height) { try { Display.setDisplayMode(new DisplayMode(width,height)); Display.create(); Display.setVSyncEnabled(true); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0,0,width,height); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, width, height, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); }
private void loadScreen() throws LWJGLException { if(gameSettings.fullscreen) { toggleFullscreen(); } ScaledResolution scaledresolution = new ScaledResolution(gameSettings, displayWidth, displayHeight); GL11.glClear(16640); GL11.glMatrixMode(5889 /*GL_PROJECTION*/); GL11.glLoadIdentity(); GL11.glOrtho(0.0D, scaledresolution.field_25121_a, scaledresolution.field_25120_b, 0.0D, 1000D, 3000D); GL11.glMatrixMode(5888 /*GL_MODELVIEW0_ARB*/); GL11.glLoadIdentity(); GL11.glTranslatef(0.0F, 0.0F, -2000F); GL11.glViewport(0, 0, displayWidth, displayHeight); GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F); Tessellator tessellator = Tessellator.instance; GL11.glDisable(2896 /*GL_LIGHTING*/); GL11.glEnable(3553 /*GL_TEXTURE_2D*/); GL11.glDisable(2912 /*GL_FOG*/); GL11.glBindTexture(3553 /*GL_TEXTURE_2D*/, renderEngine.getTexture("/title/mojang.png")); tessellator.startDrawingQuads(); tessellator.setColorOpaque_I(0xffffff); tessellator.addVertexWithUV(0.0D, displayHeight, 0.0D, 0.0D, 0.0D); tessellator.addVertexWithUV(displayWidth, displayHeight, 0.0D, 0.0D, 0.0D); tessellator.addVertexWithUV(displayWidth, 0.0D, 0.0D, 0.0D, 0.0D); tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D); tessellator.draw(); char c = '\u0100'; char c1 = '\u0100'; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); tessellator.setColorOpaque_I(0xffffff); func_6274_a((scaledresolution.getScaledWidth() - c) / 2, (scaledresolution.getScaledHeight() - c1) / 2, 0, 0, c, c1); GL11.glDisable(2896 /*GL_LIGHTING*/); GL11.glDisable(2912 /*GL_FOG*/); GL11.glEnable(3008 /*GL_ALPHA_TEST*/); GL11.glAlphaFunc(516, 0.1F); Display.swapBuffers(); }
public static DisplayManager createDisplay(){ try { Display.setDisplayMode(new DisplayMode(WIDTH,HEIGHT)); Display.create(new PixelFormat().withDepthBits(24).withSamples(4)); Display.setTitle(TITLE); GL11.glEnable(GL13.GL_MULTISAMPLE); } catch (LWJGLException e) { e.printStackTrace(); System.err.println("Couldn't create display!"); System.exit(-1); } GL11.glViewport(0,0, WIDTH, HEIGHT); return new DisplayManager(); }