Managing dynamic textures

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Managing dynamic textures

morello
I have several places were I create textures dynamically (not just the HUD I mentioned in a previous post).

Most of the examples of textures I have seen involve loading an image into a texture at init() time, and never changing it.

How do you manage a texture which can change from one frame to the next, and is dynamically created using buffered image?

I tried creating a texture in the draw method, then removing it (glDeleteTextures) at the end of the draw method, but that causes a crash in the native OpenGL. If I don't delete, I run out of memory pretty quick!

Any examples of how to do this?
Reply | Threaded
Open this post in threaded view
|

Re: Managing dynamic textures

Worker
You must drawing you (texture) buffers draw with dynamic draw not static
and change it in your runtime environment.
Reply | Threaded
Open this post in threaded view
|

Re: Managing dynamic textures

morello
Sorry, I don't really understand, I am still learning Jogl/OpenGL.

I don't understand what you mean by static or dynamic drawing?

One idea I considered was to keep a bunch of textures, but update the image content each time it changes (rather than destroy and recreate the texture). Is that feasible?
Reply | Threaded
Open this post in threaded view
|

Re: Managing dynamic textures

Demoscene Passivist
Administrator
Try using com.jogamp.opengl.util.awt.TextureRenderer. Its the easiest way to intermix Java2D and OpenGL and/or draw dynamically into an OpenGL texture.

"Provides the ability to render into an OpenGL Texture using the Java 2D APIs. This renderer class uses an internal Java 2D image (of unspecified type) for its backing store and flushes portions of that image to an OpenGL texture on demand. The resulting OpenGL texture can then be mapped on to a polygon for display."
Reply | Threaded
Open this post in threaded view
|

Re: Managing dynamic textures

morello
I don't remember exactly where I downloaded JOGL, but the utils are under the com.sun package rather than com.jogamp, which is why I couldn't find them.

TextureRenderer works well, thanks.

The main problem I was having was a strange bug with scaling, I couldn't get the textured rectangle to exactly fill the screen (either with my code or TextureRenderer). The problem was that I was setting the frustrum size to match the aspect ratio of the window, which made my prespective 3D objects look OK, but created problems in orthographic mode.

Fixed now, anyway.
Reply | Threaded
Open this post in threaded view
|

Re: Managing dynamic textures

Demoscene Passivist
Administrator
>I don't remember exactly where I downloaded JOGL, but the utils are under
>the com.sun package rather than com.jogamp, which is why I couldn't find them.

Seems u are using the old JOGL 1.1.1a wich is "deprecated". Try switching to JOGL2.