Author Topic: assign a GL texture to an Object3D  (Read 25661 times)

Offline PaniX

  • byte
  • *
  • Posts: 18
    • View Profile
Re: assign a GL texture to an Object3D
« Reply #45 on: May 24, 2015, 02:48:27 pm »
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 :)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: assign a GL texture to an Object3D
« Reply #46 on: May 25, 2015, 01:52:06 pm »
no, never tried it

Offline ginopeloso

  • byte
  • *
  • Posts: 13
    • View Profile
Re: assign a GL texture to an Object3D
« Reply #47 on: April 06, 2017, 11:18:06 am »
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:

Code: [Select]
        // 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:
Code: [Select]
W/Adreno-EGL: <qeglDrvAPI_eglQueryContext:4370>: EGL_BAD_ATTRIBUTE
Can someone say where is the problem in all this code?
« Last Edit: April 06, 2017, 12:05:49 pm by ginopeloso »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: assign a GL texture to an Object3D
« Reply #48 on: April 06, 2017, 12:29:09 pm »
Have you tried to disable mip-mapping on the texture like

Code: [Select]
externalTexture.setMipmap(false);

?

Offline ginopeloso

  • byte
  • *
  • Posts: 13
    • View Profile
Re: assign a GL texture to an Object3D
« Reply #49 on: April 06, 2017, 03:21:17 pm »
Just now, the result is the same  :-\

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: assign a GL texture to an Object3D
« Reply #50 on: April 06, 2017, 05:20:20 pm »
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.

Offline ginopeloso

  • byte
  • *
  • Posts: 13
    • View Profile
Re: assign a GL texture to an Object3D
« Reply #51 on: April 06, 2017, 05:23:28 pm »
Yes, I'm doing those exactly there.

Code: [Select]
        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;
            }

            ...
        }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: assign a GL texture to an Object3D
« Reply #52 on: April 06, 2017, 08:14:29 pm »
Ok...So, when exactly does this error message appear?

Offline ginopeloso

  • byte
  • *
  • Posts: 13
    • View Profile
Re: assign a GL texture to an Object3D
« Reply #53 on: April 07, 2017, 07:51:30 am »
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: assign a GL texture to an Object3D
« Reply #54 on: April 07, 2017, 04:07:47 pm »
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)

Offline ginopeloso

  • byte
  • *
  • Posts: 13
    • View Profile
Re: assign a GL texture to an Object3D
« Reply #55 on: April 07, 2017, 05:14:17 pm »
After setting mipmap, created the FrameBuffer without the GL10 param and calling
Code: [Select]
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!  :'(