Hi
I've been playing with some other techs, and it looks like they all have problems, so I'm considering using LWJGL and doing things at a lower level. One of the things I want to be able to do is create dynamic textures. Probably using awt to update them unless someone can come up with an alternative. I've had a hund around the forums and the wiki but can't come up with any examples of this being done, but I would have thought it was fairly streight forwards. Does anyone have any examples or pointers that I can look at that would get me to the point where I can create say a buffered image, draw on it, use it as a texture, update it and have the updates effect the scene?
The creating and updating the buffered image I can do (and have done), it's the using it in gl and making sure what I update the data the texture in the scene changes that I'm unsure of.
Thanks
Endolf
You can use glTexSubImage2D to modify an already existing texture. But first you need to learn some OpenGL. Maybe read the read book (http://www.opengl.org/documentation/red_book_1.0/) and go threw some of the nehe tutorials.
http://nehe.gamedev.net/ - The website for the Nehe tutorials (written in C++)
EDIT: Changing the texture with the BufferedImage approach would be way too slow for realtime rendering. :wink:
Hi
I've done GL before, just not dynamic textures.
Endolf
Well, then the code will be very similar to your current texture loader. But instead of creating a new, you update an existing with glTexSubImage2D.
Using a BufferedImage might work well, but you'll need to minimize the number of times the image data is copied. There will be atleast one as the data need to be put in a Buffer.
Depending on how dynamic your textures need to be, you could possibly load a series of textures into memory and then simply flip through them for your animation.
you could also have a texture set in one image and just change the tex coords to correspond to the next texture
elias4x4 and bgilb, I dont think your techniques are viable for dynamic textures because he needs to edit those textures at runtime. elias4x4, that would work fine for animation, and bgilb, if you had one big image with all the animations on them, you would do that too.
What endolf wants (i think) is to be able to modify the texture, upload it to the graphics card and display that modified texture, and thats what glTexSubImage2D does. It allows you to modify on a certain area of the texture and reupload it to the gfx card. glTexImage2D uploads an entire texture and would use alot of bandwidth, but if you know that only a few pixels were touched, glTexSubImage2D would be better in reducing the fill rate.
DP
Quote from: "darkprophet"
but if you know that only a few pixels were touched, glTexSubImage2D would be better in reducing the fill rate.
glTexSubImage2D doesn't cost fillrate, just memory bandwidth. But yes, this is the way to do it.
You may be able to do it all with render-to-texture shenanigans. Easiest would be to create your texture by rendering to the framebuffer, then glCopyTexSubImage2D to copy into a texture. Then clear your framebuffer and use the texture in your actual scene. Good if generating the dynamic texture can be easily done with GL drawing commands.
Hi
Yeah, it's not animation i'm after, it's totally dynamic, so yeah, it looks like glTexSubImage2D is what I'm after
Thanks
Endolf
Quote
glTexSubImage2D doesn't cost fillrate, just memory bandwidth. But yes, this is the way to do it.
Sorry, got confused there