java - LWJGL Assimp : Loading Textures

标签 java lwjgl assimp

我正在使用 assimp 的 LWJGL 3 版本,并且我在加载模型时遇到了困难。我遇到的问题是加载纹理的实际像素数据。使用AIMaterial对象加载这些纹理的过程是怎样的?

最佳答案

当我进行快速演示测试时,我只使用了 Java 中的常规图像 IO。它并不那么花哨,但它确实有效,并且可能会让您继续前进:

   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;
   }

图像作为另一个例程的一部分加载的位置:

    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);

关于java - LWJGL Assimp : Loading Textures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43690732/

相关文章:

java - 在您的 java 项目中使用自定义 .jar

java - LUCENE:如何通过 docNr 获取给定文档的所有术语,而不存储数据或术语 vector (LUKE 能够显示这一点,如何?)

java - "lwjgl-util.jar"属于哪里?

java - LWJGL glTranslatef 不渲染深度

cmake - 构建 assimp 3.2 不再工作

java - JAssimp - 找不到依赖库

java - 使用变量参数在没有 ArrayList 的情况下查找数字的乘积?

java - Android 上的 Dagger 2。存储和访问 @Singleton 组件的不同方式

java - 2D 是否需要 GL_DEPTH_TEST 和 GL_DEPTH_BUFFER_BIT?

c++ - 如何使用 assimp 在 C++ 中旋转蒙皮模型的骨骼?