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 9169423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:52:38+00:00 2026-06-17T15:52:38+00:00

Last question I asked was about how to draw different models in OpenGL. I

  • 0

Last question I asked was about how to draw different models in OpenGL. I got that covered, but now I’m stuck at doing textures. Once again I can easily get textures to work, as long as I only ever use one texture.

The class that loads the textures:

public class Textures
{

    public static int tex, tex2;

    public static void load() throws IOException
    {
        tex = glGenTextures();
        tex2 = glGenTextures();

        load(tex2, "moreModels/robot.jpg", "jpg");
        load(tex, "moreModels/sample.jpg", "jpg");
    }

    public static void load(int tex, String name, String type) throws IOException
    {
        glBindTexture(GL43.GL_TEXTURE_2D, tex);

        glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

        glGenerateMipmap(GL43.GL_TEXTURE_2D);

        glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);

        Texture texture = TextureLoader.getTexture(type, ResourceLoader.getResourceAsStream(name));

        byte[] pixels = texture.getTextureData();

        ByteBuffer buffer = BufferUtils.createByteBuffer(pixels.length);
        buffer.put(pixels);
        buffer.flip();
        glTexImage2D(GL43.GL_TEXTURE_2D, 0, GL_BGR, texture.getImageWidth(), texture.getImageHeight(), 0, GL_BGR, GL_BYTE, buffer);
    }
}

Now, I would think that simply calling glBindTexture(GL43.GL_TEXTURE_2D, textureID) will change the texture, but no. If I at any time call the glBindTexture method everything will be rendered black.

Is it the same as before, where I have to do the entire load method every time I need to change the texture? (Perhaps saving the Texture object, so I don’t have to load it over and over again). And if so, what’s the point of having glGenTextures() when it aparently forgets everything about it when changed?

  • 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-17T15:52:38+00:00Added an answer on June 17, 2026 at 3:52 pm

    I think you have a little bit wrong understanding of OpenGL texture.You must remember:every time you load a new image you have to create a new texture object using the routine you have shown in your question.Additionally , if you want just to update (replace the pixels) of the existing texture , you should use glTexSubImage2D .This way you don’t create new texture object but update the data in the existing one.

    Now , if you want to have several textures ,let’s say, one as a color map and another as normal map, then you have to create 2 textures from scratch which will be accessed by your fragment shader samplers.

    Based on your code it is hard to see how you do the whole setup (rendering loop ,shaders).If you supply more info then it will be possible to assist you further.

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

Sidebar

Related Questions

So I asked a question last year about having an add item button that'll
I previously asked a question about fetching the last 100 mentions for a person
Hi I asked a question today about How to insert different types of objects
I asked a question last week about Gui and Timers... well after lots of
This is related to another question I asked last week, but the current issue
I asked a question yesterday about a problem that Im having with a program
Last January I asked a question about sending string information between computers. Using the
This is a follow-up to a question I asked last year about setting up
I recently asked a question that got shot down for being too strongly worded.
I've asked a previous question last month, about whether an Entity should access a

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.