The trick is to double buffer and use two image components, by-reference textures and y-up. Then you can update the buffered image attached to the backbuffer between frames and just set the texture's imagecomponent to the back buffer in one command. Here is a bunch of fairly relevent source:
class SubOverlay { private static final boolean debug = false; int lx,ly,ux,uy; // which part of the parent image does this represent int texWidth; // the width of the texture (power of 2) int texHeight; // the height of the texture (power of 2) int width; // width of the sub-overlay int height; // height of the sub-overlay BufferedImage a; // buffered image used for icA BufferedImage b; // buffered image used for icB ImageComponent2D icA; // one of the double buffers ImageComponent2D icB; // the other one of the double buffers Shape3D shape; // textured quad used to hold geometry Texture2D tex; // texture mapped to icA or icB Appearance ap; // appearance for this sub-overlay Overlay overlay; // the owner of this sub-overlay boolean frontBuffer; // true if icA is the current texture, false if its icB int transferBuffer[]; // used for transferring scan lines from main image to sub-image /** * Creates the sub overlay for the specified region. */ protected SubOverlay( Overlay overlay, int lx, int ly, int ux, int uy) { this.overlay = overlay; // save the screen location this.lx = lx; this.ly = ly; this.ux = ux; this.uy = uy; // caclulate the sub overlay size width = ux-lx+1; height = uy-ly+1; // now we need to calculate the texture size needed to contain this // size sub-overlay. Find the smallest power of two that works texWidth = smallestPower(width); texHeight = smallestPower(height); // create the two buffers boolean hasAlpha = (overlay.getBlendAlpha() || overlay.getClipAlpha()); if (hasAlpha) { a = CustomBufferedImage.getCustomRGBA(texWidth,texHeight); b = CustomBufferedImage.getCustomRGBA(texWidth,texHeight); } else { a = CustomBufferedImage.getCustomRGB(texWidth,texHeight); b = CustomBufferedImage.getCustomRGB(texWidth,texHeight); } // determine a compatible by-ref image type int icType; if (hasAlpha) icType = ImageComponent2D.FORMAT_RGBA; else icType = ImageComponent2D.FORMAT_RGB; // create two by-reference image components icA = new ImageComponent2D(icType,a,true,true); icB = new ImageComponent2D(icType,b,true,true); // create a transfer buffer for one scan line transferBuffer = new int[texWidth]; // create the shape buildShape(); // define the texture int texType; if (hasAlpha) texType = Texture.RGBA; else texType = Texture.RGB; if (debug) System.out.println("Sub-overlay : "+width+","+height+" -> "+texWidth+","+texHeight+ " : "+ lx+","+ly+" - "+ux+","+uy); tex = new Texture2D(Texture.BASE_LEVEL,texType,texWidth,texHeight); tex.setBoundaryModeS(Texture.CLAMP); tex.setBoundaryModeT(Texture.CLAMP); tex.setMagFilter(Texture.FASTEST); tex.setMinFilter(Texture.FASTEST); tex.setImage(0,icA); tex.setCapability(Texture.ALLOW_IMAGE_WRITE); ap.setTexture(tex); frontBuffer = true; } /** * Transfers the scan lines from the full image to the sub-image. The * scan lines are applied in reverse order so that it is compatible with * that silly Y-up thing (grrr). */ protected void updateBackBuffer( BufferedImage fullImage ) { BufferedImage backBuffer; if (frontBuffer) backBuffer = b; else backBuffer = a; /* Graphics g = backBuffer.getGraphics(); g.setColor(Color.pink); g.fillRect(0,0,texWidth-1,texHeight-1); g.dispose(); */ int w = fullImage.getWidth(); for (int i=0;i<height;i++) { int y = overlay.height-uy+i-1; fullImage.getRGB(lx,y,width,1,transferBuffer,0,w); backBuffer.setRGB(0,texHeight-i-1-(texHeight-height),width,1,transferBuffer, 0,texWidth); } /* Graphics g = backBuffer.getGraphics(); g.setColor(Color.pink); g.drawRect(0,0,width,height); g.dispose(); */ } /** * Swaps the buffers */ protected void swap() { if (frontBuffer) tex.setImage(0,icB); else tex.setImage(0,icA); frontBuffer = !frontBuffer; } ----- Original Message ----- From: Karsten Fries <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, January 21, 2002 1:43 PM Subject: Re: [JAVA3D] Dynamic Textures? Hi Joachim, actually I made some experience with updating texture content quite recently. The approach i finally came up with is quite similar to that one you described, but you don't have to recreate the Texture2D instance all the time. The texture is only created once, and during update you just replace the ImageComponent (which unfortunately must be created again and again from the BufferedImage, which is certainly rigid. The Texture capabilites must contain ALLOW_TEXTURE_WRITE to reset the image component (setImage( 0, imageComponent) ). This still doesn't help! The texture seems to be not updated and the results are kind of arbitrary, especially if you update the texture several times with many small changes. The final trick you need, and this is something the sun guys could check back, is that you should not just replace or modify the appearance associated with the texture shape, but set the appearance explicilty to null and than create a new texture appearance. The problem is (as it seems) that the system doesn't recognize the change the way the update was done. Hope this workaround works, Karsten PS: if you finally come up with a better solution (that especially is Java3D 1.2.1_3 compatible), you can do me a great favour in letting me know. Joachim Diepstraten wrote: > Hi Alex > > Hmm thanks for the answer and thanks for the source > but I'm not sure if that's actually the thing I'm > searching for, well I still will have a look on it. > Cause I'm not planing to do something with JMF but > rather my textures are textures coming from an > offScreen rendering pass. > > -- > Explore SRT with the help of Java3D > (http://wwwvis.informatik.uni-stuttgart.de/relativity/minkowski) > (http://www.antiflash.net/java3d/relativity (mirror) > > =========================================================================== > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff JAVA3D-INTEREST". For general help, send email to > [EMAIL PROTECTED] and include in the body of the message "help". =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".