ios - GPUImage render to OpenGL ES texture does not work -


i render video in opengl es texture can apply texture 3d surface in ios program. i'm using gpuimage, not work, no texture seems loaded in output.

here .h code :

#import <uikit/uikit.h> #import <glkit/glkit.h>  #import "gpuimage.h"  @interface viewcontroller : glkviewcontroller <gpuimagetextureoutputdelegate> {     gluint texture;     gpuimagemovie* movie;     gpuimagetextureoutput *output;       gpuimagepixellatefilter* pixellatefilter; }  @end 

and here parts of the.m file :

init

- (void)setupgl {     [eaglcontext setcurrentcontext:self.context];      [self loadshaders];      _vertexarraybuff = generatesphere(0, 0, 0, 10, 20, 10, &_arraysize);      glenable(gl_depth_test);      glgenvertexarraysoes(1, &_vertexarray);     glbindvertexarrayoes(_vertexarray);      glgenbuffers(1, &_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]; } 

render

- (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 object again 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); } 

delegate

- (void)newframereadyfromtextureoutput:(gpuimagetextureoutput *)callbacktextureoutput; {     dispatch_async(dispatch_get_main_queue(), ^{         texture = callbacktextureoutput.texture;     }); } 

i tried manually load texture , display , worked shaders , texture coordinates not issue.

but when try set texture gpuimage not work more, texture not displayed, instead have black surface.

does know did wrong? followed cubeexample gpuimage not work.

i need now

thank you!

ps: i'm targeting ios 6.1 , i'm using xcode 4.6.2

edit

here code of function called @ beginning :

- (void)viewdidload {     [super viewdidload];      self.context = [[eaglcontext alloc] initwithapi:keaglrenderingapiopengles2 sharegroup:[[[gpuimagecontext sharedimageprocessingcontext] context] sharegroup]];      if (!self.context) {         nslog(@"failed create es context");     }      glkview *view = (glkview *)self.view;     view.context = self.context;     view.drawabledepthformat = glkviewdrawabledepthformat24;      [self setupgl]; } 

i think you're missing 1 critical part of cubeexample sample code. need use share group textures created in gpuimage's opengl es context appear in view's opengl es context.

in cubeexample, i'm not using glkit, create context caeagllayer-hosting view using following code:

    context = [[eaglcontext alloc] initwithapi:keaglrenderingapiopengles2 sharegroup:[[[gpuimagecontext sharedimageprocessingcontext] context] sharegroup]]; 

this grabs share group used gpuimage's image processing opengl es context , uses share group rendering context view.

i haven't done work glkit myself (i've preferred lower-level opengl es, out of habit), believe set opengl es context glkview @ point. insert gpuimage share group @ point, or before gpuimage setup or work, use -usesharegroup: method on gpuimagecontext's sharedimageprocessingcontext go other way , set gpuimage use view's context's share group.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -