Jump to content
  • Advertisement
Sign in to follow this  
Decrius

OpenGL Modify textures when they're loaded in OpenGL

This topic is 3770 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What the title says, would it be possible to modify textures when they're loaded in OpenGL? How do I access it and what format would it be? This is the code I use to add it to OpenGL:
glGenTextures(1, &id);
        glBindTexture(GL_TEXTURE_2D, id);

        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

        width = texture.get_width();
        height = texture.get_height();

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.get_pixels());
Should I keep a copy of the pixel data raw in memory or can I use the texture OpenGL has loaded to save on memory usage? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You would either use render to texture with FBO or use glTexSubImage2D which updates a part of the texture.

Share this post


Link to post
Share on other sites
Depends on what you want to do. Is it just a one-time modification? Or a frequent modification, e.g. hightmap for a deformable terrain?

For a one-time modification I'd just change the data you pass to OpenGL, for a frequent modification you could do what V-man proposes, i.e. depending on your needs use FBO, PBO or glTexSubImage.

You can also read back the texture data via glGetTexImage.

Share this post


Link to post
Share on other sites
No, the user himself can decide whenever he want's to modify it (it's a library, user = other developer). And I heard getting a texture from the buffer is fairly slow.

I just made it so it'll keep a copy on the RAM, and a function called clean_up() to remove it, when the user/developer is done wiht the texture.

Thanks though :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!