Estoy usando la versión LWJGL 3 de assimp, y me tropecé al cargar un modelo. El problema con el que me encuentro es cargar datos de píxeles reales para texturas. ¿Cuál es el proceso de carga de estas texturas mediante el uso de un objeto AIMaterial?
Cuando hice esto para una prueba de demostración rápida, simplemente usé el Image IO normal de Java. No es tan elegante, pero funciona y podría ponerte en marcha:
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; }Donde la imagen fue cargada como parte de otra rutina:
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);