updateTextureSubImage - need to convert java.awt.Image to com.jme.image.Image


Hi,

I'm having trouble updating a texture with a video feed from the webcam.

I'm currently using:

BufferedImage image = _videoFeedImage.getSubimage(104,0,512,512 ) ;

_backgroundTexture = TextureManager.loadTexture(image,
        Texture.MinificationFilter.NearestNeighborNoMipMaps,
        Texture.MagnificationFilter.NearestNeighbor, true);

Which works, but is running at a slow framerate. I'd like to use:

    renderer.updateTextureSubImage(_backgroundTexture,0,0,image,0,0, 512, 512);

Except updateTextureSubImage wants com.jme.image.Image instead of java.awt.Image. Can anyone advise me on how to convert?

Thanks





UPDATE: I am now trying a slightly different method, using the raw pixel data:



        ByteBuffer byteBuffer = ByteBuffer.wrap(_pixels);
        System.out.println("ByteBuffer: " + byteBuffer );

        com.jme.image.Image newImage = new com.jme.image.Image(com.jme.image.Image.Format.RGB8 , 512, 512, byteBuffer );

        DisplaySystem.getDisplaySystem().getRenderer().updateTextureSubImage(_backgroundTexture,0,0, newImage ,0,0, 512, 512);



...but I consistently get this error:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1337)
        at com.jme.renderer.lwjgl.LWJGLRenderer.updateTextureSubImage(LWJGLRenderer.java:1776)



This post offers some clues:


http://www.jmonkeyengine.com/forum/index.php?topic=5585.msg44492#msg44492


It sounds like I need to update the textureSubImage in the OpenGL thread, and I'm looking into how to do that now.

This is a very urgent, eve-of-deadline situation, so if anyone has any helpful tips I will probably die of gratitude. Thanks!

You can execute code in the GL thread via GameTaskManager.getManager().render/update (if I remember correctly).

Hi, thanks for the response.



In the end I moved my project over to use ARMonkeyKit:



http://armonkeykit.wordpress.com/



It uses a much better video implementation for webcam video capture, and made my efforts redundant.