public static void main(String[] args) { /* UNCOMMENT TO GENERATE JAR: */ // System.setProperty("org.lwjgl.librarypath",System.getProperty("user.dir") + "/native"); // Loading JDE icon try { String OS = System.getProperty("os.name").toUpperCase(); if (OS.contains("WIN")) { Display.setIcon(new ByteBuffer[] { new ImageIOImageData().imageToByteBuffer(ImageIO .read(new File("res/logo/jde-icon16.png")), false, false, null), new ImageIOImageData().imageToByteBuffer(ImageIO .read(new File("res/logo/jde-icon32.png")), false, false, null) }); } else if (OS.contains("MAC")) { Display.setIcon(new ByteBuffer[] { new ImageIOImageData() .imageToByteBuffer(ImageIO.read(new File( "res/logo/jde-icon128.png")), false, false, null) }); } else { Display.setIcon(new ByteBuffer[] { new ImageIOImageData().imageToByteBuffer( ImageIO.read(new File("res/logo/jde-icon32.png")), false, false, null) }); } } catch (IOException e1) { e1.printStackTrace(); } // Launching JDE Launcher.launch(); }
/** * Load a texture into OpenGL from a BufferedImage * * @param resourceName * The location of the resource to load * @param resourceimage * The BufferedImage we are converting * @param target * The GL target to load the texture against * @param dstPixelFormat * The pixel format of the screen * @param minFilter * The minimising filter * @param magFilter * The magnification filter * @return The loaded texture * @throws IOException * Indicates a failure to access the resource */ public static Texture getTexture(String resourceName, BufferedImage resourceimage, int target, int dstPixelFormat, int minFilter, int magFilter) throws IOException { ImageIOImageData data = new ImageIOImageData();int srcPixelFormat = 0; // create the texture ID for this texture int textureID = InternalTextureLoader.createTextureID(); TextureImpl texture = new TextureImpl(resourceName, target, textureID); // Enable texturing Renderer.get().glEnable(SGL.GL_TEXTURE_2D); // bind this texture Renderer.get().glBindTexture(target, textureID); BufferedImage bufferedImage = resourceimage; texture.setWidth(bufferedImage.getWidth()); texture.setHeight(bufferedImage.getHeight()); if (bufferedImage.getColorModel().hasAlpha()) { srcPixelFormat = SGL.GL_RGBA; } else { srcPixelFormat = SGL.GL_RGB; } // convert that image into a byte buffer of texture data ByteBuffer textureBuffer = data.imageToByteBuffer(bufferedImage, false, false, null); texture.setTextureHeight(data.getTexHeight()); texture.setTextureWidth(data.getTexWidth()); texture.setAlpha(data.getDepth() == 32); if (target == SGL.GL_TEXTURE_2D) { Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter); Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter); if (Renderer.get().canTextureMirrorClamp()) { Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT); Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT); } else { Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP); Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP); } } Renderer.get().glTexImage2D(target, 0, dstPixelFormat, texture.getTextureWidth(), texture.getTextureHeight(), 0, srcPixelFormat, SGL.GL_UNSIGNED_BYTE, textureBuffer); return texture; }
private static void createLWJGL() { try { final JumboLaunchConfig c = JumboSettings.launchConfig; // Dimension size = frame.getSize(); // frame.add(canvas); // canvas.setSize(size); // Display.setParent(canvas); // canvas.setMinimumSize(size); // canvas.setVisible(true); if (c.fullscreen) { Display.setFullscreen(true); Display.setDisplayMode(c.mode); } else { Display.setDisplayMode(c.mode); Display.setFullscreen(false); } Display.setTitle(c.title); Display.setResizable(c.resizable); if (c.icon != null) { final int iconnum = c.icon.length; final ByteBuffer[] list = new ByteBuffer[iconnum]; for (int i = 0; i < iconnum; i++) { list[i] = new ImageIOImageData().imageToByteBuffer(c.icon[i], false, false, null); } Display.setIcon(list); } if (c.fullscreen && c.vsync) { Display.setVSyncEnabled(true); } if (!Display.isCreated()) { final PixelFormat pixelFormat = new PixelFormat(); final ContextAttribs contextAtrributes = new ContextAttribs(3, 3).withProfileCompatibility(true); Display.create(pixelFormat, contextAtrributes); } if (!Mouse.isCreated()) { Mouse.create(); } if (!Keyboard.isCreated()) { Keyboard.create(); } } catch (LWJGLException e) { JumboErrorHandler.handle(e); } }