I'm using the LWJGL 3 version of assimp, and I've stumbled my way through loading a model. The issue I'm running into is loading actual pixel data for textures. What is the process of loading these textures by use of a AIMaterial object?
When I did this for a quick demo test, I just used the regular Image IO from Java. It's not as fancy but it works and might get you going:
public static ByteBuffer decodePng( BufferedImage image )
throws IOException
{
int width = image.getWidth();
int height = image.getHeight();
// Load texture contents into a byte buffer
ByteBuffer buf = ByteBuffer.allocateDirect(
4 * width * height );
// decode image
// ARGB format to -> RGBA
for( int h = 0; h < height; h++ )
for( int w = 0; w < width; w++ ) {
int argb = image.getRGB( w, h );
buf.put( (byte) ( 0xFF & ( argb >> 16 ) ) );
buf.put( (byte) ( 0xFF & ( argb >> 8 ) ) );
buf.put( (byte) ( 0xFF & ( argb ) ) );
buf.put( (byte) ( 0xFF & ( argb >> 24 ) ) );
}
buf.flip();
return buf;
}
Where the image was loaded as part of another routine:
public Texture(InputStream is) throws Exception {
try {
// Load Texture file
BufferedImage image = ImageIO.read(is);
this.width = image.getWidth();
this.height = image.getHeight();
// Load texture contents into a byte buffer
ByteBuffer buf = xogl.utils.TextureUtils.decodePng(image);
// 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);