Dynamic textures

Started by Endolf, September 07, 2005, 11:22:49

Previous topic - Next topic

Endolf

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

tomb

You can use glTexSubImage2D to modify an already existing texture. But first you need to learn some OpenGL. Maybe read the read book and go threw some of the nehe tutorials.

Fool Running

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:
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Endolf

Hi

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

Endolf

tomb

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.

elias4444

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.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

bgilb

you could also have a texture set in one image and just change the tex coords to correspond to the next texture

darkprophet

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

Orangy Tang

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.

Endolf

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

darkprophet

Quote
glTexSubImage2D doesn't cost fillrate, just memory bandwidth. But yes, this is the way to do it.

Sorry, got confused there