Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
LWJGL Assimp: Loading Textures

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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!