本文整理汇总了Java中de.matthiasmann.twl.utils.PNGDecoder.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java PNGDecoder.getHeight方法的具体用法?Java PNGDecoder.getHeight怎么用?Java PNGDecoder.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.matthiasmann.twl.utils.PNGDecoder
的用法示例。
在下文中一共展示了PNGDecoder.getHeight方法的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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例6: 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);
}
}
}
示例7: 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);
}
}
}
示例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, 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();
}
}
}
示例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, 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();
}
}
}
示例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);
}
}
}
示例11: 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();
}
}
}
示例12: 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);
}
示例13: 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;
}
示例14: 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();
}
}
示例15: 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());
}