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


Java PNGDecoder.getWidth方法代码示例

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


在下文中一共展示了PNGDecoder.getWidth方法的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: 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

示例4: load

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private static int load(String path) {
	try (InputStream stream = TextureManager.class.getClassLoader().getResourceAsStream(path)) {
		PNGDecoder decoder = new PNGDecoder(stream);
		int w = decoder.getWidth(), h = decoder.getHeight();
		ByteBuffer data = BufferUtils.createByteBuffer(4 * w * h);
		decoder.decodeFlipped(data, 4 * w, PNGDecoder.Format.RGBA);
		data.flip();
		int texId = bufferTexture(w, h, data, GL11.GL_RGBA);
		idByPath.put(path, texId);
		infoById.put(texId, new TextureInfo(texId, w, h));
		return texId;
	} catch (IOException e) {
		Aargon.getLogger().warn("Errored loading texture: {}", path);
		e.printStackTrace();
	}
	return -1;
}
 
开发者ID:phantamanta44,项目名称:OpenAargon,代码行数:18,代码来源:TextureManager.java

示例5: 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

示例6: 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

示例7: 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

示例8: 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, PNGDecoder.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:gjkf,项目名称:seriousEngine,代码行数:37,代码来源:Texture.java

示例9: 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:lwjglgamedev,项目名称:lwjglbook,代码行数:37,代码来源:Texture.java

示例10: 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:lwjglgamedev,项目名称:lwjglbook,代码行数:46,代码来源:Terrain.java

示例11: Texture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public Texture(InputStream is) throws Exception {
    // 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);
}
 
开发者ID:lwjglgamedev,项目名称:lwjglbook,代码行数:29,代码来源:Texture.java

示例12: Texture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public Texture(String fileName) throws Exception {

        // Load Texture file
        PNGDecoder decoder = new PNGDecoder(Texture.class.getResourceAsStream(fileName));

        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 
        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);
        
        this.id = textureId;
    }
 
开发者ID:lwjglgamedev,项目名称:lwjglbook,代码行数:33,代码来源:Texture.java

示例13: loadPngTexture

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
private Texture loadPngTexture(String name) throws FileNotFoundException, IOException {
    InputStream is = vfs.open(name);
    try {
        PNGDecoder decoder = new PNGDecoder(is);
        int bpp;
        PNGDecoder.Format format;
        int pixelFormat;
        int texWidth = decoder.getWidth();
        int texHeight = decoder.getHeight();
        boolean hasAlpha = decoder.hasAlpha();
        if (hasAlpha) {
            bpp = 4;
            format = PNGDecoder.Format.RGBA;
            pixelFormat = GL11.GL_RGBA;
        } else {
            bpp = 3;
            format = PNGDecoder.Format.RGB;
            pixelFormat = GL11.GL_RGB;
        }

        int stride = bpp * texWidth;
        ByteBuffer buffer = ByteBuffer.allocateDirect(stride * texHeight);
        decoder.decode(buffer, stride, format);
        buffer.flip();
        Texture texture = new Texture(texWidth, texHeight, hasAlpha);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId());
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        LwjglHelper.setupGLTextureParams();
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, pixelFormat, texWidth,
                texHeight, 0, pixelFormat, GL11.GL_UNSIGNED_BYTE, buffer);
        return texture;
    } finally {
        is.close();
    }
}
 
开发者ID:devnewton,项目名称:jnuit,代码行数:36,代码来源:AssetsLoader.java

示例14: fromInputStream

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public static BufferedTexture fromInputStream(InputStream stream) throws IOException {
    // Link the PNG decoder to this stream
    PNGDecoder decoder = new PNGDecoder(stream);

    // Decode the PNG file in a ByteBuffer
    ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
    decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
    buf.flip();
    return new BufferedTexture(buf, decoder.getWidth(), decoder.getHeight());
}
 
开发者ID:TechShroom,项目名称:EmergencyLanding,代码行数:11,代码来源:BufferedTexture.java

示例15: HeightMapMesh

import de.matthiasmann.twl.utils.PNGDecoder; //导入方法依赖的package包/类
public HeightMapMesh(float minY, float maxY, String heightMapFile, String textureFile, int textInc) throws Exception {
  this.minY = minY;
  this.maxY = maxY;

  PNGDecoder decoder = new PNGDecoder(this.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();
  Texture texture = new Texture(textureFile);

  float incx = getXLength() / (width - 1);
  float incz = getZLength() / (height - 1);

  List<Float> positions = new ArrayList<>();
  List<Float> textCoords = new ArrayList<>();
  List<Integer> indices = new ArrayList<>();

  for (int row = 0; row < height; row++) {
    for (int col = 0; col < width; col++) {
      // Create vertex for current position
      positions.add(STARTX + col * incx); // x
      positions.add(getHeight(col, row, width, buf)); //y
      positions.add(STARTZ + row * incz); //z

      // Set texture coordinates
      textCoords.add((float) textInc * (float) col / (float) width);
      textCoords.add((float) textInc * (float) row / (float) height);

      // Create indices
      if (col < width - 1 && row < height - 1) {
        int leftTop = row * width + col;
        int leftBottom = (row + 1) * width + col;
        int rightBottom = (row + 1) * width + col + 1;
        int rightTop = row * width + col + 1;

        indices.add(leftTop);
        indices.add(leftBottom);
        indices.add(rightTop);

        indices.add(rightTop);
        indices.add(leftBottom);
        indices.add(rightBottom);
      }
    }
  }

  float[] posArr = Util.listToArray(positions);
  int[] indicesArr = indices.stream().mapToInt(i -> i).toArray();
  float[] textCoordsArr = Util.listToArray(textCoords);
  float[] normalsArr = calcNormals(posArr, width, height);
  this.mesh = new Mesh(posArr, textCoordsArr, indicesArr, texture);
  //Material material = new Material(texture, 0.0f);
  //mesh.setMaterial(material);
}
 
开发者ID:adamegyed,项目名称:endless-hiker,代码行数:58,代码来源:HeightMapMesh.java


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