Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7800103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:31:35+00:00 2026-06-02T00:31:35+00:00

I have fix the problem and following is how I did it, The binding

  • 0

I have fix the problem and following is how I did it,

The binding code in RenderEngine:

public int bindTexture(String location)
{
    BufferedImage texture;
    File il = new File(location);

    if(textureMap.containsKey(location))
    {
        glBindTexture(GL_TEXTURE_2D, textureMap.get(location));
        return textureMap.get(location);
    }

    try 
    {
        texture = ImageIO.read(il); 
    }
    catch(Exception e)
    {
        texture = missingTexture;
    }

    try
    {
        int i = glGenTextures();
        ByteBuffer buffer = BufferUtils.createByteBuffer(texture.getWidth() * texture.getHeight() * 4);
        Decoder.decodePNGFileToBuffer(buffer, texture);
        glBindTexture(GL_TEXTURE_2D, i);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.getWidth(), texture.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
        textureMap.put(location, i);
        return i;
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    return 0;
}

And the PNG decoder method:

public static void decodePNGFileToBuffer(ByteBuffer buffer, BufferedImage image)
{
    int[] pixels = new int[image.getWidth() * image.getHeight()];
    image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());

    for(int y = 0; y < image.getHeight(); y++)
    {
        for(int x = 0; x < image.getWidth(); x++)
        {
            int pixel = pixels[y * image.getWidth() + x];
            buffer.put((byte) ((pixel >> 16) & 0xFF));
            buffer.put((byte) ((pixel >> 8) & 0xFF));
            buffer.put((byte) (pixel & 0xFF)); 
            buffer.put((byte) ((pixel >> 24) & 0xFF));
        }
    }

    buffer.flip();
}

I hope this helps anybody with the same problem
P.S. textureMap is just a HashMap with String as the key and a Integer as the value

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:31:37+00:00Added an answer on June 2, 2026 at 12:31 am

    You’ve got the order completely wrong. You need to:

    1. Generate a texture name/ID with glGenTextures – store that ID in a variable
    2. Bind that ID using glBindTexture
    3. any only then you can upload the data with glTexImage

    In your drawing code you’re calling the whole texture load, which is inefficient, also you’re recreating a new texture name each time. Use a map to map texture filenames to an ID, and only if no ID has been assigned yet Gen/Bind/TexImage the texture. Otherwise, just Bind it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem in my code and I am not able to fix
Q: I have the following problem , and i don't know how to fix
The following code demonstrates a weird problem I have in a Turbo C++ Explorer
Can someone explain to me how I can fix this problem. I have two
I have a problem which I don't know how to fix. It has to
I have a strange problem which I can't fix: A field: private boolean[][][] gaps;
i have a small problem here which i cannot fix,This post goes through but
i have the following problem: Create a program where a particle will execute a
I was just wondering something. I have the following code: #include <iostream> using namespace
Consider following code: Dim S1 As String = a 'this is the string in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.