Animated Texture

I'm getting troubles trying to create an animated texture from a camera source. I'm getting a byte buffer from the camera and i wanna put it as the texture of a Quad.

I haven't got it.

I've tried next things:

  • Create a BufferedImage from java.awt.image and update its Raster's DataBuffer in the simpleUpdate() and loadTexture(Image…) from TextureManager, but it doesn't work.

  • Create a jme Image using the data buffer got from the camera and creating a java.nio.ByteBuffer for that image. that ByteBuffer is also updated in the simpleUpdate() method.

See the LWJGLImageGraphics class or code from this thread for examples on how to update textures (currently still requires direct use of LWJGL).

You could however use the actual ImageGraphics class to do this.

I tried with LWJGLImageGraphics, but it paint the image once and the screen get totally black and the framerate goes down.

I tried with the link you gave me, but i couldn't understand it, i don't know so much opengl. The most I worked before was Java3D and I'm migrating to jME.

Look, I need either put the camera stream in a backgroud Quad or directly in the screen background.

I saw how to do it with JOGL but I don't know if a can access in that way with jME






gl.glOrtho(-0.5f, (float)xsize - 0.5f, -0.5f, (float)ysize - 0.5f, 0.0f, 1.0f);

float zoomx = (float)xsize / (float)picwidth;

float zoomy = (float)ysize / (float)picheight;

gl.glPixelZoom(zoomx, zoomy);

gl.glRasterPos2i(0, 0);


gl.glDrawPixels(picwidth, picheight, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, dataArray);





The source in that thread shows how to acces the texture directly through OpenGL (LWJGL instead of JOGL in this case)… just look inside the JMFVideoImage class in that thread.

escp the

GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId());

         // TODO: use this.dataformat

         GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, videowidth, videoheight,pixelformat,

               GL11.GL_UNSIGNED_BYTE, buffer);

bit. You'll have to read up a bit on OpenGL to understand what it does of course.

That said, if you're properly painting on the ImageGraphics class, that should also work. I think there's something wrong missing in your code there, because many others have used this class, and in jME it's also used to draw entire Swing windows on it. In fact, if you really can't get it to work you can always try building a regular Swing panel that does your cam stuff and use that with JMEDesktop :slight_smile:

Look this.

protected void simpleInitGame() {

      f = new Quad("q1", 20, 20);

      mg = ImageGraphics.createInstance(256, 256, 0);

      bi = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);

      Graphics2D g = (Graphics2D)bi.getGraphics();

      g.clearRect(0, 0, 256, 256);
      g.fillRect(50, 50, 150, 150);

protected void simpleRender() {

      mg.create().drawString("##############", 200, 200);
      mg.drawString("##############", 500, 200);
      mg.drawImage(bi, 0, 0, null);

This code is just for testing ImageGraphics but it doesnt do anything it just render the Quad.

Am I doing anything bad ?????  :(

Ahmmmm when i told you that the framerate went down, that was for a mistake that i was doing. That doesn't happen anymore.

I cann't use JMF for getting video stream. I'm using a C library and I cannot change to JMF.

The C library has a java binding call FrameGrabber, it return a int[] each grabFrame() call.

I havn't undestood FOB code really much, is there any simple way to paint the pixels in the int[] array to the screen background ???

I'm really sorry for being so bother with you. But you don't know the difficult that is for me either undestand and write English because I talk Spanish.


I wasn't suggesting you change to JMF, I was just pointing out that it shows how to access a texture.

I don't get your example though… you create an  ImageGraphics, but you don't use it anywhere!? You have to create a texture that uses the ImageGraphics. Maybe you should start with some of the jME tutorials to get the basics of what a scenegraph is, and how jME works.