LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Endolf on September 07, 2005, 11:22:49

Title: Dynamic textures
Post by: Endolf on September 07, 2005, 11:22:49
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
Title: Dynamic textures
Post by: tomb on September 07, 2005, 14:00:51
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.
Title: hmmmmm...
Post by: Fool Running on September 07, 2005, 14:36:24
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:
Title: Dynamic textures
Post by: Endolf on September 07, 2005, 16:58:13
Hi

I've  done GL before, just not dynamic textures.

Endolf
Title: Dynamic textures
Post by: tomb on September 07, 2005, 21:32:38
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.
Title: Dynamic textures
Post by: elias4444 on September 08, 2005, 14:24:50
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.
Title: Dynamic textures
Post by: bgilb on September 10, 2005, 02:03:06
you could also have a texture set in one image and just change the tex coords to correspond to the next texture
Title: Dynamic textures
Post by: darkprophet on September 10, 2005, 10:38:52
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
Title: Dynamic textures
Post by: Orangy Tang on September 10, 2005, 10:56:22
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.
Title: Dynamic textures
Post by: Endolf on September 10, 2005, 11:14:44
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
Title: Dynamic textures
Post by: darkprophet on September 10, 2005, 11:27:24
Quote
glTexSubImage2D doesn't cost fillrate, just memory bandwidth. But yes, this is the way to do it.

Sorry, got confused there