0
votes

I'm just starting out using lwjgl, and have a texture drawn to the screen However, I want to regularly change the pixel data in this texture

I currently do this by changing my BufferedImage, and then converting this into a texture and redrawing it in openGL

I'm using an example texture loader at the moment: http://lwjgl.org/wiki/index.php?title=Examples:SpaceInvaders_TextureLoader

I feel like I shouldn't have to constantly reload the texture, though, and am afraid I'm wasting resources by calling the convertImageData function in the game loop How do I avoid this?

EDIT: Alright, I made myself a bit happier by storing the ByteBuffer as well and simply modifying it, followed by:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 800, 600, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

Instead of doing the whole conversion. I think this is fine

2

2 Answers

0
votes

You can render to a Texture by using FBO (Frame Buffer Object).

have a look at the LWJGL wiki and this example.

0
votes

It seems to me that you want to animate a texture. This can be easily done using a spritesheet; draw out all your animation stages onto a texture, linearly if possible, and then modulate your texture coordinates based on which animation of the sprite you want to use.