assign a GL texture to an Object3D

Started by raft, January 23, 2014, 03:20:53 PM

Previous topic - Next topic

PaniX

Just a small question... Did you were able to get LenseFlare to work?
Any idea how I could use the function in the StereoRenderer?

Just interested, no need to hack something together for a noob like me :)

raft


ginopeloso

#47
I'm trying to follow this post to play a video as a texture over an Object3D. Is it necessary to create my own shader?
In other OpenGL projects I already played a video as a texture, here I'm having problems.

I do these steps:


        // create a new texture
        int[] textureIdVector = new int[1];
        GLES20.glGenTextures(1, textureIdVector, 0);
        textureId = textureIdVector[0];
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

        // create an external texture
        Texture externalTexture = new Texture(32, 32);
        externalTexture.setExternalId(textureId, GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
        TextureManager.getInstance().addTexture("video", externalTexture);

        // create the SurfaceTexture, the Surface and the MediaPlayer
        surfaceTexture = new SurfaceTexture(textureId);
        Surface surface = new Surface(surfaceTexture);
        mediaPlayer.setSurface(surface);
        surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
            @Override
            public void onFrameAvailable(SurfaceTexture surfaceTexture) {
                // in the onDrawFrame method I call "surfaceTexture.updateTexImage()"
                updateVideoTexture = true;
            }
        });

        // tv is my Object3D on which I want to apply the video texture
        tv.setTexture("video");

        mediaPlayer.setLooping(true);
        mediaPlayer.start();


If I try with an image as texture it works good, since I don't have an external texture but just a jpct's Texture object. This way, instead, I see nothing. The video correctly starts, because I hear its sound but I can't see it over the object.

Another thing, when I create the SurfaceTexture passing the OpenGL's texture id I see this message in logs:
W/Adreno-EGL: <qeglDrvAPI_eglQueryContext:4370>: EGL_BAD_ATTRIBUTE

Can someone say where is the problem in all this code?

EgonOlsen

Have you tried to disable mip-mapping on the texture like


externalTexture.setMipmap(false);


?

ginopeloso


EgonOlsen

Where are you doing these steps? You have to do them in the thread that executes the onDrawFrame() method, not in some other (setup-)thread.

ginopeloso

Yes, I'm doing those exactly there.


        public void onDrawFrame(GL10 gl) {
            if (textureId < 0) {
                startPlayer();  // this method contains the SurfaceTexture initialization (the previous post's code)
            }

            if (updateVideoTexture) {
                surfaceTexture.updateTexImage();
                updateVideoTexture = false;
            }

            ...
        }

EgonOlsen

Ok...So, when exactly does this error message appear?

ginopeloso

Actually I just tried with an image and the message appears too, but the image is correctly shown as texture (the image has been applied with a JPCT Texture), so the problem is not that error but something else related to the external texture.

raft

video not appearing part may also be related to a thread synchronization issue. in particular if you dont consume a video frame new update never arrives (as far as I remember)

ginopeloso

After setting mipmap, created the FrameBuffer without the GL10 param and calling mGLView.setEGLContextClientVersion(2); now I see a black texture rather than the video, but no errors... also added synchronization when updating the texture but still nothing. I feel I'm near!  :'(