本文整理汇总了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);
}
示例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: 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
}
示例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);
}
示例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: 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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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);
}