# Android: Sampling from movie texture does not work

**URL:** https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345
**Category:** Developing Cinder
**Created:** [October 23, 2016, 8:34pm UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345 "2016-10-23T20:34:52Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![eight\_io](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/eight_io/32/57_2.png) [@eight\_io](https://discourse.libcinder.org/u/eight_io)
#### Post date: [October 23, 2016, 8:34pm UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/1 "2016-10-23T20:34:52Z")

</div>

I am converting iOS app to Android. iOS version has a working displacement map texture rendering, in which the displacement map is a movie texture. On Android, however, sampling from a movie texture returns zeros.

Below I removed the displacement part and simply am drawing the movie texture using a primitive shader

```auto
    cinder::android::video::MovieGlRef mMovie;
   gl::TextureRef mDisplaceTexture;
...
//setup
        mMovie = cinder::android::video::MovieGl::create( moviePath );
        mMovie->play();
...
//update
       mDisplaceTexture = mMovie->getTexture();
...
//draw
                gl::ScopedColor col(Color::white());
                gl::ScopedModelMatrix modelScope;
                gl::ScopedTextureBind a (mDisplaceTexture, 0);
      
                gl::ScopedGlslProg shaderScp1( glsl );
                glsl->uniform("mDisplaceTexture", 0);
                 gl::drawSolidRect( Rectf(vec2(0),getWindowSize() ) );

```

The vert shader:

```auto
#version 100
uniform mat4 ciModelViewProjection;

attribute vec4 ciPosition;
attribute vec2 ciTexCoord0;
attribute vec4 ciColor;
varying vec2	Vertex;

void main( void )
{
    Vertex.xy = ciTexCoord0;
    gl_Position = ciModelViewProjection * ciPosition;
}

```

The fragment shader:

```auto
#version 100

//uniform sampler2D mCamTexture;
uniform sampler2D mDisplaceTexture;

varying highp vec2	Vertex;

void main( void )
{
   // highp float displace = dot(texture2D(mDisplaceTexture,vec2(Vertex.x, 1.0 - Vertex.y)).rgb, vec3(0.3, 0.6, 0.1))*0.5;
    //gl_FragColor = texture2D(mCamTexture, Vertex + vec2(displace));
    gl_FragColor = texture2D(mDisplaceTexture, Vertex);
}

```

This draws a black screen. No GlError thrown. The camera feed, asset pictures are displayed fine with this approach.

Playing displace texture as follows works too:

```auto
                gl::color(Color::white());
                gl::draw( mDisplaceTexture, Rectf(vec2(0),getWindowSize() ) );

```

What shall I look into?

Thanks.

–8

---

<div class="post-metadata">

### Author: ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)
#### Post date: [October 23, 2016, 9:15pm UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/2 "2016-10-23T21:15:00Z")

</div>

Try using `sampler2DRect` instead. This is required on Windows and OS X, so perhaps also on Android. Movies often use a `GL_TEXTURE_RECTANGLE` target that uses absolute texture coordinates instead of normalized ones.

---

<div class="post-metadata">

### Author: ![eight\_io](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/eight_io/32/57_2.png) [@eight\_io](https://discourse.libcinder.org/u/eight_io)
#### Post date: [October 23, 2016, 9:22pm UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/3 "2016-10-23T21:22:31Z")

</div>

Thanks Paul.

sampler2DRect breaks the shader with

```auto
10-23 17:18:29.667 12346-12391/ru.scriptum.augmentedtheatre A/cinder: |fatal | void cinder::app::AppBase::executeLaunch()[193] Uncaught exception, type: cinder::gl::GlslProgCompileExc, what: FRAGMENT: Fragment shader compilation failed.
                                                                      ERROR: 0:3: 'sampler2DRect' : Reserved word. 
                                                                      ERROR: 0:3: 'sampler2DRect' : Syntax error: syntax error
                                                                      ERROR: 2 compilation errors. No code generated.
                                                                      
                                                                      
                                                                       1: #version 100
                                                                       2: uniform sampler2DRect mCamTexture;
                                                                       3: uniform sampler2DRect mDisplaceTexture;
                                                                       4: varying highp vec2	Vertex;
                                                                       5: void main( void )
                                                                       6: {
                                                                       7: highp float displace = dot(texture2DRect(mDisplaceTexture,Vertex.yx).rgb, vec3(0.3, 0.6, 0.1))*0.5;
                                                                       8: gl_FragColor = texture2DRect(mCamTexture, Vertex + vec2(displace));    
                                                                       9: }
                                                                      10: 
                                                                      

```

–8

---

<div class="post-metadata">

### Author: ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)
#### Post date: [October 23, 2016, 10:04pm UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/4 "2016-10-23T22:04:31Z")

</div>

I have no experience with this, but here it shows that the texture target is `GL_TEXTURE_EXTERNAL_OES`, so I would try `uniform samplerExternalOES mCamTexture` instead.

[https://github.com/cinder/Cinder/blob/android\_linux/src/cinder/android/video/VideoPlayer.cpp#L70](https://github.com/cinder/Cinder/blob/android_linux/src/cinder/android/video/VideoPlayer.cpp#L70)

---

<div class="post-metadata">

### Author: ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)
#### Post date: [October 23, 2016, 10:45pm UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/5 "2016-10-23T22:45:43Z")

</div>

If that is the case, you may have to enable the [extension](https://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt):  
`#extension GL_OES_EGL_image_external`

---

<div class="post-metadata">

### Author: ![eight\_io](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/eight_io/32/57_2.png) [@eight\_io](https://discourse.libcinder.org/u/eight_io)
#### Post date: [October 24, 2016, 12:05am UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/6 "2016-10-24T00:05:27Z")

</div>

@gabor_papp and @paul.houx : Thanks, guys, but still no luck:

```auto
10-23 19:45:28.895 28622-28982/ru.scriptum.augmentedtheatre W/Adreno-ES20: <core_glFramebufferTexture2D:2561>: GL_INVALID_ENUM
10-23 19:45:28.895 28622-28982/ru.scriptum.augmentedtheatre A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 28982 (Thread-2390)

```

Shader:

```auto
#version 100
#extension GL_OES_EGL_image_external : enable
//uniform sampler2D mCamTexture;
uniform samplerExternalOES mDisplaceTexture;

varying highp vec2	Vertex;

void main( void )
{
    highp float displace = dot(texture2D(mDisplaceTexture,vec2(Vertex.x, 1.0 - Vertex.y)).rgb, vec3(0.3, 0.6, 0.1))*0.5;
    //gl_FragColor = texture2D(mCamTexture, Vertex + vec2(displace));
    gl_FragColor = texture2D(mDisplaceTexture, Vertex);
}

```

–8

---

<div class="post-metadata">

### Author: ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)
#### Post date: [October 24, 2016, 1:25am UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/7 "2016-10-24T01:25:49Z")

</div>

Are you rendering to an `Fbo` that has this texture bound as a target?

---

<div class="post-metadata">

### Author: ![eight\_io](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/eight_io/32/57_2.png) [@eight\_io](https://discourse.libcinder.org/u/eight_io)
#### Post date: [October 24, 2016, 1:38am UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/8 "2016-10-24T01:38:50Z")

</div>

No:

> [@eight\_io](#):
>
> mDisplaceTexture = mMovie-\>getTexture();  
> …  
> //draw  
> gl::ScopedColor col(Color::white());  
> gl::ScopedModelMatrix modelScope;  
> gl::ScopedTextureBind a (mDisplaceTexture, 0);
> 
> ```
> gl::ScopedGlslProg shaderScp1( glsl );
> glsl-&gt;uniform("mDisplaceTexture", 0);
> gl::drawSolidRect( Rectf(vec2(0),getWindowSize() ) );
> 
> ```

Also, just checked the GL\_OES\_EGL\_image\_external extension is available.

–8

---

<div class="post-metadata">

### Author: ![eight\_io](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/eight_io/32/57_2.png) [@eight\_io](https://discourse.libcinder.org/u/eight_io)
#### Post date: [October 24, 2016, 4:35am UTC](https://discourse.libcinder.org/t/android-sampling-from-movie-texture-does-not-work/345/9 "2016-10-24T04:35:36Z")

</div>

@paul.houx, @gabor_papp Actually, I am taking it back. While banging on this problem, I was trying to convert a texture into a surface into a texture, and that is what was causing this SIGABRT. I removed that craziness, and now everything works.

So, GL\_OES\_EGL\_image\_external all the way to the bank.

Thanks a lot.

–8
