Note that there are some explanatory texts on larger screens.

plurals
  1. POGPUImage render to OpenGL ES texture does not work
    text
    copied!<p>I would like to render a video in an <code>OpenGL ES</code> texture so that I can apply this texture to a 3D surface in my iOS program. To do that I'm using <code>GPUImage</code>, but it does not work, no texture seems to be loaded in the output.</p> <p>Here is the .h code :</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;GLKit/GLKit.h&gt; #import "GPUImage.h" @interface ViewController : GLKViewController &lt;GPUImageTextureOutputDelegate&gt; { GLuint texture; GPUImageMovie* movie; GPUImageTextureOutput *output; GPUImagePixellateFilter* pixellateFilter; } @end </code></pre> <p>And here are parts of the.m file :</p> <p>Init</p> <pre><code>- (void)setupGL { [EAGLContext setCurrentContext:self.context]; [self loadShaders]; _vertexArrayBuff = generateSphere(0, 0, 0, 10, 20, 10, &amp;_arraySize); glEnable(GL_DEPTH_TEST); glGenVertexArraysOES(1, &amp;_vertexArray); glBindVertexArrayOES(_vertexArray); glGenBuffers(1, &amp;_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, _arraySize * sizeof(GLfloat), _vertexArrayBuff, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(0)); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(12)); glEnableVertexAttribArray(GLKVertexAttribTexCoord0); glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(24)); glBindVertexArrayOES(0); NSString* fileStr = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]; NSURL* fileUrl = [NSURL fileURLWithPath:fileStr]; movie = [[GPUImageMovie alloc] initWithURL:fileUrl]; output = [[GPUImageTextureOutput alloc] init]; output.delegate = self; pixellateFilter = [[GPUImagePixellateFilter alloc] init]; [movie addTarget:pixellateFilter]; [pixellateFilter addTarget:output]; [movie startProcessing]; } </code></pre> <p>Render</p> <pre><code>- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { glClearColor(0.65f, 0.65f, 0.65f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindVertexArrayOES(_vertexArray); // Render the object again with ES2 glUseProgram(_program); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m); glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m); glUniform1i(uniforms[UNIFORM_TEXTUTRE], 0); glDrawArrays(GL_TRIANGLES, 0, _arraySize / 8); } </code></pre> <p>Delegate</p> <pre><code>- (void)newFrameReadyFromTextureOutput:(GPUImageTextureOutput *)callbackTextureOutput; { dispatch_async(dispatch_get_main_queue(), ^{ texture = callbackTextureOutput.texture; }); } </code></pre> <p>I tried to manually load a texture and display it and it worked so the shaders and texture coordinates are not the issue.</p> <p>But when I try to set the texture with <code>GPUImage</code> it does not work any more, my texture is not displayed, instead I have a black surface.</p> <p>Does anyone know what I did wrong? I followed the <code>CubeExample</code> from <code>GPUImage</code> but it does not work.</p> <p>I really need some help now</p> <p>Thank you!</p> <p>PS: I'm targeting iOS 6.1 and I'm using XCode 4.6.2</p> <p><strong>EDIT</strong></p> <p>Here is the code of the function called at beginning :</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:[[[GPUImageContext sharedImageProcessingContext] context] sharegroup]]; if (!self.context) { NSLog(@"Failed to create ES context"); } GLKView *view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; [self setupGL]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload