当前位置: 首页>>代码示例>>Java>>正文


Java PNGDecoder.decode方法代码示例

本文整理汇总了Java中de.matthiasmann.twl.utils.PNGDecoder.decode方法的典型用法代码示例。如果您正苦于以下问题:Java PNGDecoder.decode方法的具体用法?Java PNGDecoder.decode怎么用?Java PNGDecoder.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在de.matthiasmann.twl.utils.PNGDecoder的用法示例。


在下文中一共展示了PNGDecoder.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decodeTextureFile

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
protected static TextureData decodeTextureFile(MyFile file) {
	int width = 0;
	int height = 0;
	ByteBuffer buffer = null;
	try {
		InputStream in = file.getInputStream();
		PNGDecoder decoder = new PNGDecoder(in);
		width = decoder.getWidth();
		height = decoder.getHeight();
		buffer = ByteBuffer.allocateDirect(4 * width * height);
		decoder.decode(buffer, width * 4, Format.BGRA);
		buffer.flip();
		in.close();
	} catch (Exception e) {
		e.printStackTrace();
		System.err.println("Tried to load texture " + file.getName() + " , didn't work");
		System.exit(-1);
	}
	return new TextureData(buffer, width, height);
}
 
开发者ID:TheThinMatrix,项目名称:OpenGL-Animation,代码行数:21,代码来源:TextureUtils.java

示例2: decodeTextureFile

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private TextureData decodeTextureFile(String fileName) {
    int width = 0;
    int height = 0;
    ByteBuffer buffer = null;
    try {
        FileInputStream in = new FileInputStream(fileName);
        PNGDecoder decoder = new PNGDecoder(in);
        width = decoder.getWidth();
        height = decoder.getHeight();
        buffer = ByteBuffer.allocateDirect(4 * width * height);
        decoder.decode(buffer, width * 4, Format.RGBA);
        buffer.flip();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Tried to load texture " + fileName + ", didn't work");
        System.exit(-1);
    }
    return new TextureData(buffer, width, height);
}
 
开发者ID:MrManiacc,项目名称:3d-Engine,代码行数:21,代码来源:Loader.java

示例3: setUpTextures

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private void setUpTextures() throws IOException {
    fontTexture = glGenTextures(); // Create new texture for the bitmap font
    
    // 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(getClass().getResourceAsStream("/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);
    
    glBindTexture(GL_TEXTURE_2D, 0); // Unbind the texture
}
 
开发者ID:mattgd,项目名称:Laser-Amazer,代码行数:18,代码来源:GameFont.java

示例4: decodeTextureFile

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private TextureData decodeTextureFile(String fileName) {
	int width = 0;
	int height = 0;
	ByteBuffer buffer = null;
	try {
		PNGDecoder decoder = new PNGDecoder(net.gogo98901.util.Loader.getResourceAsStream(fileName));
		width = decoder.getWidth();
		height = decoder.getHeight();
		buffer = ByteBuffer.allocateDirect(4 * width * height);
		decoder.decode(buffer, width * 4, Format.RGBA);
		buffer.flip();
	} catch (Exception e) {
		Log.severe("Failed to load texture '" + fileName + "'");
		Log.stackTrace(Level.SEVERE, e);

		System.exit(0);
	}
	return new TextureData(buffer, width, height);
}
 
开发者ID:roryclaasen,项目名称:sandbox,代码行数:20,代码来源:Loader.java

示例5: decodeTextureFile

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private TextureData decodeTextureFile(String fileName) {
	int width = 0;
	int height = 0;
	ByteBuffer buffer = null;
	try {
		FileInputStream in = new FileInputStream(fileName);
		PNGDecoder decoder = new PNGDecoder(in);
		width = decoder.getWidth();
		height = decoder.getHeight();
		buffer = ByteBuffer.allocateDirect(4 * width * height);
		decoder.decode(buffer, width * 4, Format.RGBA);
		buffer.flip();
		in.close();
	} catch (Exception e) {
		e.printStackTrace();
		System.err.println("Tried to load texture " + fileName + ", didn't work");
		System.exit(-1);
	}
	return new TextureData(buffer, width, height);
}
 
开发者ID:Radseq,项目名称:Mystic-Bastion,代码行数:21,代码来源:Loader.java

示例6: createTextureFromStream

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public static int createTextureFromStream(InputStream stream) {
    try {
        PNGDecoder decoder = new PNGDecoder(stream);
        ByteBuffer buffer = BufferUtils.createByteBuffer(decoder.getWidth() * decoder.getHeight() * 4);
        decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
        buffer.flip();

        int handle = glGenTextures();
        glBindTexture(GL_TEXTURE_2D, handle);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
        glBindTexture(GL_TEXTURE_2D, 0);

        return handle;
    } catch (IOException ex) {
        ex.printStackTrace();
        System.err.println("Failed to load texture!");
        System.exit(-1);
    }

    return -1;
}
 
开发者ID:caseif,项目名称:Voxem,代码行数:26,代码来源:ImageUtil.java

示例7: loadTextureLinear

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public static int loadTextureLinear(String filename){
    int texture = glGenTextures();
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
    InputStream in;
    try {
        in = ResourceLoader.getResourceAsStream("res/textures/"+filename);
        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 (IOException e) {
        e.printStackTrace();
    }
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

    return texture;
}
 
开发者ID:Piratkopia13,项目名称:Pixel-Planet,代码行数:21,代码来源:GameResourceLoader.java

示例8: buildTexture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private void buildTexture(final BufferedImage imgTemp) throws IOException {
	textureId = GL11.glGenTextures();

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);

	final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
	ImageIO.write(imgTemp, "png", byteArrayOutputStream);
	final PNGDecoder decoder = new PNGDecoder(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
	final ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
	decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
	buffer.flip();

	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}
 
开发者ID:JanStrauss,项目名称:veya,代码行数:19,代码来源:TrueTypeFont.java

示例9: load

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public static int load(String path)
{
    try
    {
        InputStream inputStream = new FileInputStream(path);
        textureDecoder = new PNGDecoder(inputStream);
        textureData = BufferUtils.createByteBuffer(4 * textureDecoder.getWidth() * textureDecoder.getHeight());
        textureDecoder.decode(textureData, textureDecoder.getWidth() * 4, PNGDecoder.Format.RGBA);
        textureData.flip();
    } catch (IOException ex) {Logger.getLogger(Graphics.class.getName()).log(Level.SEVERE, null, ex);}
    
    textureID = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, textureID);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    
    glTexImage2D(GL_TEXTURE_2D, // Texture type (1D, 2D, 3D)
            0, // Level, always set this to zero
            GL_RGBA, // Internal format, RGBA works best
            textureDecoder.getWidth(), // Width of the texture in pixels
            textureDecoder.getHeight(), // Width of the texture in pixels
            0, // Border, always set this to zero
            GL_RGBA, // Texture format, in our case this is RGBA (you can dynamically find the texture type with PNGDecoder)
            GL_UNSIGNED_BYTE, // Type of the texture data, this is always unsigned byte (this should ring a bell with C/C++ programmers)
            textureData);
    // Unbind the texture, in our program this isn't strictly necessary because we have only one texture
    // But it's a good practice for when you have multiple textures
    glBindTexture(GL_TEXTURE_2D, 0);
    
    return textureID;
}
 
开发者ID:ChriguFizzzt,项目名称:Defender-Engine-V2,代码行数:33,代码来源:Graphics.java

示例10: PngTexture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public PngTexture(String filePath) {
    ByteBuffer buf = null;
    try {
        int width;
        int height;
        try (FileInputStream fin = new FileInputStream(filePath)) {
            PNGDecoder decoder = new PNGDecoder(fin);
            width = decoder.getWidth();
            height = decoder.getHeight();
            int picSize = 4 * width * height;
            buf = memAlloc(picSize);
            decoder.decode(buf, 4 * width, PNGDecoder.Format.RGBA);
        }
        buf.flip();

        texId = glGenTextures();
        glBindTexture(GL_TEXTURE_2D, texId);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
                0, GL_RGBA, GL_UNSIGNED_BYTE, buf);

        //glGenerateMipmap(GL_TEXTURE_2D);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (buf != null) {
            memFree(buf);
        }
    }
}
 
开发者ID:akarnokd,项目名称:space-4x-management-game,代码行数:34,代码来源:PngTexture.java

示例11: Terrain

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
/**
 * A Terrain is composed by blocks, each block is a GameItem constructed
 * from a HeightMap.
 *
 * @param terrainSize   The number of blocks will be terrainSize * terrainSize
 * @param scale         The scale to be applied to each terrain block
 * @param minY          The minimum y value, before scaling, of each terrain block
 * @param maxY          The maximum y value, before scaling, of each terrain block
 * @param heightMapFile
 * @param textureFile
 * @param textInc
 *
 * @throws Exception
 */
public Terrain(int terrainSize, float scale, float minY, float maxY, String heightMapFile, String textureFile,
               int textInc) throws Exception {
    this.terrainSize = terrainSize;
    gameItems = new GameItem[terrainSize * terrainSize];

    PNGDecoder decoder = new PNGDecoder(getClass().getResourceAsStream(heightMapFile));
    int height = decoder.getHeight();
    int width = decoder.getWidth();
    ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
    decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
    buf.flip();

    // The number of vertices per column and row
    verticesPerCol = width - 1;
    verticesPerRow = height - 1;

    heightMapMesh = new HeightMapMesh(minY, maxY, buf, width, height, textureFile, textInc);
    boundingBoxes = new Box2D[terrainSize][terrainSize];
    for (int row = 0; row < terrainSize; row++) {
        for (int col = 0; col < terrainSize; col++) {
            float xDisplacement =
                    (col - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getXLength();
            float zDisplacement =
                    (row - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getZLength();

            GameItem terrainBlock = new GameItem(heightMapMesh.getMesh());
            terrainBlock.setScale(scale);
            terrainBlock.setPosition(xDisplacement, 0, zDisplacement);
            gameItems[row * terrainSize + col] = terrainBlock;

            boundingBoxes[row][col] = getBoundingBox(terrainBlock);
        }
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:49,代码来源:Terrain.java

示例12: Texture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public Texture(InputStream is) throws Exception {
    try {
        // Load Texture file
        PNGDecoder decoder = new PNGDecoder(is);

        this.width = decoder.getWidth();
        this.height = decoder.getHeight();

        // Load texture contents into a byte buffer
        ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();

        // Create a new OpenGL texture 
        this.id = glGenTextures();
        // Bind the texture
        glBindTexture(GL_TEXTURE_2D, this.id);

        // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        // Upload the texture data
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
        // Generate Mip Map
        glGenerateMipmap(GL_TEXTURE_2D);

        is.close();
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:36,代码来源:Texture.java

示例13: loadTexture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private static int loadTexture(String fileName) throws Exception {
    // Load Texture file
    PNGDecoder decoder = new PNGDecoder(Texture.class.getResourceAsStream(fileName));

    // Load texture contents into a byte buffer
    ByteBuffer buf = ByteBuffer.allocateDirect(
            4 * decoder.getWidth() * decoder.getHeight());
    decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
    buf.flip();

    // Create a new OpenGL texture 
    int textureId = glGenTextures();
    // Bind the texture
    glBindTexture(GL_TEXTURE_2D, textureId);

    // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    // Upload the texture data
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0,
            GL_RGBA, GL_UNSIGNED_BYTE, buf);
    // Generate Mip Map
    glGenerateMipmap(GL_TEXTURE_2D);
    return textureId;
}
 
开发者ID:adamegyed,项目名称:endless-hiker,代码行数:29,代码来源:Texture.java

示例14: loadTexture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private static int loadTexture(String fileName) throws Exception {
    // Load Texture file
    PNGDecoder decoder = new PNGDecoder(Texture.class.getResourceAsStream(fileName));

    // Load texture contents into a byte buffer
    ByteBuffer buf = ByteBuffer.allocateDirect(
            4 * decoder.getWidth() * decoder.getHeight());
    decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
    buf.flip();

    // Create a new OpenGL texture
    int textureId = glGenTextures();
    // Bind the texture
    glBindTexture(GL_TEXTURE_2D, textureId);

    // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    // Upload the texture data
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0,
            GL_RGBA, GL_UNSIGNED_BYTE, buf);
    // Generate Mip Map
    glGenerateMipmap(GL_TEXTURE_2D);
    return textureId;
}
 
开发者ID:dwbrite,项目名称:polvo,代码行数:29,代码来源:Texture.java

示例15: createTextureArray

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private void createTextureArray() {
    int handle = glGenTextures();
    glBindTexture(GL_TEXTURE_2D_ARRAY, handle);

    glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, Texture.SIZE, Texture.SIZE, textures.size());

    try {
        int layer = 0;
        for (Texture tex : textures.values()) {
            PNGDecoder decoder = new PNGDecoder(ImageHelper.asInputStream(tex.getImage()));
            ByteBuffer buffer = BufferUtils.createByteBuffer(decoder.getWidth() * decoder.getHeight() * 4);
            decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
            buffer.flip();

            glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer, decoder.getWidth(), decoder.getHeight(), 1,
                    GL_RGBA, GL_UNSIGNED_BYTE, buffer);

            tex.setLayer(layer);

            layer++;
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        System.exit(-1);
    }

    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
 
开发者ID:caseif,项目名称:Cubic,代码行数:32,代码来源:TextureRegistry.java


注:本文中的de.matthiasmann.twl.utils.PNGDecoder.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。