Examples of PNGDecoder


Examples of cc.plural.utils.PNGDecoder

        try {
            // Open the PNG file as an InputStream
            //URL file = ClassLoader.class.getResource(path);

            // Link the PNG decoder to this stream
            PNGDecoder decoder = new PNGDecoder(url.openStream());

            // Get the width and height of the texture
            textureWidth = decoder.getWidth();
            textureHeight = decoder.getHeight();

            // Decode the PNG file in a ByteBuffer
            imageBuffer = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
            decoder.decode(imageBuffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
            imageBuffer.flip();
        } catch (IOException e) {
            throw new RuntimeException("Clean this up:" + e);
        }
    }
View Full Code Here

Examples of cc.plural.utils.PNGDecoder

        try {
            // Open the PNG file as an InputStream
            URL file = ClassLoader.class.getResource(fileName);

            // Link the PNG decoder to this stream
            PNGDecoder decoder = new PNGDecoder(file.openStream());

            // Get the width and height of the texture
            tWidth = decoder.getWidth();
            tHeight = decoder.getHeight();


            // Decode the PNG file in a ByteBuffer
            buf = ByteBuffer.allocateDirect(
                    4 * decoder.getWidth() * decoder.getHeight());
            decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
            buf.flip();

        } catch(IOException e) {
            throw new RuntimeException("Clean this up:" + e);
        }
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

            // Create an input stream for the 'lookup texture', a texture that will used by the fragment shader to
            // determine which colour matches which height on the heightmap
            FileInputStream heightmapLookupInputStream = new FileInputStream("res/images/heightmap_lookup.png");
            // Create a class that will give us information about the image file (width and height) and give us the
            // texture data in an OpenGL-friendly manner
            PNGDecoder decoder = new PNGDecoder(heightmapLookupInputStream);
            // Create a ByteBuffer in which to store the contents of the texture. Its size is the width multiplied by
            // the height and 4, which stands for the amount of bytes a float is in Java.
            ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
            // 'Decode' the texture and store its data in the buffer we just created
            decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
            // Make the contents of the ByteBuffer readable to OpenGL (and unreadable to us)
            buffer.flip();
            // Close the input stream for the heightmap 'lookup texture'
            heightmapLookupInputStream.close();
            // Generate a texture handle for the 'lookup texture'
            lookupTexture = glGenTextures();
            glBindTexture(GL_TEXTURE_2D, lookupTexture);
            // Hand the texture data to OpenGL
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA,
                    GL_UNSIGNED_BYTE, buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Use the GL_NEAREST texture filter so that the sampled texel (texture pixel) is not smoothed out. Usually
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

    private static void setUpDisplay() {
        Display.setTitle("Custom Icon");
        try {
            Display.setDisplayMode(new DisplayMode(640, 480));
            PNGDecoder imageDecoder = new PNGDecoder(new FileInputStream("res/images/logo128.png"));
            if (!imageDecoder.hasAlpha() && imageDecoder.getHeight() != 128 && imageDecoder.getHeight() != 128) {
                System.err.println("Icon does not have transparency info and cannot serve as an icon for the application.");
            }
            Display.create();
            ByteBuffer imageData = BufferUtils.createByteBuffer(4 * imageDecoder.getWidth() * imageDecoder.getHeight());
            imageDecoder.decode(imageData, imageDecoder.getWidth() * 4, PNGDecoder.Format.RGBA);
            imageData.flip();
            System.out.println(Display.setIcon(new ByteBuffer[]{imageData}));
        } catch (LWJGLException e) {
            e.printStackTrace();
        } catch (IOException e) {
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

                for (int x = 0; x < data[z].length; x++) {
                    data[z][x] = ((heightmapImage.getRGB(z, x) >> 16) & 0xff);
                }
            }
            FileInputStream heightmapinfoInputStream = new FileInputStream("res/images/heightmap_lookup.png");
            PNGDecoder decoder = new PNGDecoder(heightmapinfoInputStream);
            ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
            decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
            heightmapinfoInputStream.close();
            buffer.flip();
            glBindTexture(GL_TEXTURE_2D, lookupTexture);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA,
                    GL_UNSIGNED_BYTE, buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        glActiveTexture(GL_TEXTURE0);
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
        {
            InputStream in = null;
            try {
                in = new FileInputStream(location);
                PNGDecoder decoder = new PNGDecoder(in);
                ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
                decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
                buffer.flip();
                glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
                glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0,
                        GL_RGBA, GL_UNSIGNED_BYTE, buffer);
                glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
                System.err.println("Failed to find the texture file.");
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

        int texture = glGenTextures();
        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
        InputStream in = null;
        try {
            in = new FileInputStream(location);
            PNGDecoder decoder = new PNGDecoder(in);
            ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
            decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
            buffer.flip();
            glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA,
                    GL_UNSIGNED_BYTE, buffer);
        } catch (FileNotFoundException e) {
            System.err.println("Texture file could not be found.");
            return -1;
        } catch (IOException e) {
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

        int texture = glGenTextures();
        glBindTexture(GL_TEXTURE_2D, texture);
        InputStream in = null;
        try {
            in = new FileInputStream(location);
            PNGDecoder decoder = new PNGDecoder(in);
            ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
            decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
            buffer.flip();
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA,
                    GL_UNSIGNED_BYTE, buffer);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return -1;
        } catch (IOException e) {
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

        // Create a new texture for the bitmap font.
        fontTexture = glGenTextures();
        // Bind the texture object to the GL_TEXTURE_2D target, specifying that it will be a 2D texture.
        glBindTexture(GL_TEXTURE_2D, fontTexture);
        // Use TWL's utility classes to load the png file.
        PNGDecoder decoder = new PNGDecoder(new FileInputStream("res/images/font.png"));
        ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
        buffer.flip();
        // Load the previously loaded texture data into the texture object.
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
                buffer);
        // Unbind the texture.
        glBindTexture(GL_TEXTURE_2D, 0);
    }
View Full Code Here

Examples of de.matthiasmann.twl.utils.PNGDecoder

        // Create an input stream for the 'lookup texture', a texture that will used by the fragment shader to
        // determine which colour matches which height on the heightmap
        FileInputStream inputStream = new FileInputStream(path);
        // Create a class that will give us information about the image file (width and height) and give us the
        // texture data in an OpenGL-friendly manner
        PNGDecoder decoder = new PNGDecoder(inputStream);
        // Create a ByteBuffer in which to store the contents of the texture. Its size is the width multiplied by
        // the height and 4, which stands for the amount of bytes a float is in Java.
        ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
        // 'Decode' the texture and store its data in the buffer we just created
        decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
        // Make the contents of the ByteBuffer readable to OpenGL (and unreadable to us)
        buffer.flip();
        // Close the input stream for the heightmap 'lookup texture'
        inputStream.close();
        // Generate a texture handle for the 'lookup texture'
        int texture = glGenTextures();
        glBindTexture(GL_TEXTURE_2D, texture);
        // Hand the texture data to OpenGL
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA,
                GL_UNSIGNED_BYTE, buffer);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glBindTexture(GL_TEXTURE_2D, 0);
        return texture;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.