Author Topic: background video  (Read 3103 times)

Offline arash

  • byte
  • *
  • Posts: 8
    • View Profile
background video
« on: January 20, 2014, 07:49:33 am »
Hi,

I am trying to add a video to my game background. I tried FrameBuffer.blit method and changed the background texture on every frame but this is very slow and maxes out my memory pretty soon.

Is there any other way to display a video on the background?

Cheers

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: background video
« Reply #1 on: January 20, 2014, 08:23:05 am »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: background video
« Reply #2 on: January 24, 2014, 03:13:18 pm »
you can use a SurfaceTexture.

SurfaceTexture can redirect MediaPlayer's output to a GL texture and can display that in GLSurfaceView. jPCT happily draws on top if it without any complains.

this is far more faster than modifying texture manually and uploading to GPU.

Offline arash

  • byte
  • *
  • Posts: 8
    • View Profile
Re: background video
« Reply #3 on: February 20, 2014, 01:03:04 pm »
Thanks guys for your replies.

I tried overrideTexelData with ByteBuffer first but could not get very far.

Then I tried SurfaceTexture and managed to get some progress. Now I have Audio playing but the video does not play.

so to test this, as a proof of concept, basically in the onSurfaceCreated of my GLSurfaceView.Renderer I create the media player and surface texture like this:

Code: [Select]
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
int[] texture = new int[1];

        GLES20.glGenTextures(1,texture, 0);
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texture[0]);
        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR);       
        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

int mTextureID = texture[0];

mSurface = new SurfaceTexture(mTextureID);
mSurface.setOnFrameAvailableListener(new videoTexture());

try {
AssetFileDescriptor afd = getAssets().openFd("test7.mp4");
MediaPlayer player = new MediaPlayer();
    player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
    player.setSurface(new Surface(mSurface));
    player.prepare();
    player.start();
    player.setLooping(true);

} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

and then I have this class:
Code: [Select]
class videoTexture implements SurfaceTexture.OnFrameAvailableListener {
@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
updateSurface = true;
mGLView.requestRender();
}
}

and finally in my onDrawFrame method I have:
Code: [Select]
if (updateSurface) {
                mSurface.updateTexImage();
                updateSurface = false;
            }

I really appreciate your input  :)
« Last Edit: February 20, 2014, 01:06:37 pm by arash »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: background video
« Reply #4 on: February 20, 2014, 01:24:40 pm »
in your code, i dont see anything to render the contents of SurfaceTexture to screen. you are just updating its content but it's not rendered.

This class works fine for me. do the same thing but also call TextureRender.drawFrame in your onDrawFrame method