I attached/copied my sources. Basically I am trying to do realtime processing on video while displaying the result in another window. In a nutshell here are the steps I am trying to accomplish:
3) upload the result along with original frame to second window where there are blended using a shader.
I am sure I am doing something wrong, I just can't figure out what.
--------------------------------------------------------------------------------------------------------------------------------------------------------
function MyDemo()
Screen('Preference', 'SkipSyncTests', 1);
% Check if Psychtoolbox is properly installed:
AssertOpenGL;
moviename = [ 'risen_trailer_c.mp4' ];
windowrect = [];
% Wait until user releases keys on keyboard:
KbReleaseWait;
% Select screen for display of movie:
screenid = max(Screen('Screens'));
scale = 0.25;
try
% Open 1st window (playback input. Use opengl fixed pipeline to render):
[win, w_size]= Screen('OpenWindow', screenid, [], windowrect);
[c_x, c_y] = RectCenter(w_size);
% Open an offscreen window keeping downsample version of current frame (to move to CPU)
[win1, w1_size] = Screen('OpenOffscreenWindow', screenid, [], [0 0 w_size(3)*scale w_size(4)*scale]);
% Open 2nd window (playback output. Use shader with multitexture)
win2 = Screen('OpenWindow', screenid - 1, [], windowrect);
% Setup Uniform location for texture mapping in shader
glsl = LoadGLSLProgramFromFiles('C:\toolbox\Psychtoolbox\PsychDemos\MovieDemos\shader',1);
glUseProgram(glsl);
glUniform1i(glGetUniformLocation(glsl, 'Image'), 0);
glUniform1i(glGetUniformLocation(glsl, 'Image1'), 1);
glUseProgram(0);
% Open movie file:
movie = Screen('OpenMovie', win, moviename);
% Start playback engine:
Screen('PlayMovie', movie, 1);
% Playback loop: Runs until end of movie or keypress:
n=0;
while ~KbCheck
n=n+1;
pause(1/90);
tex = Screen('GetMovieImage', win, movie,0, [], 1);
if tex<0
break;
end
% Get form GPU
cap = Screen('GetImage', win1) ; %, crop_rect);
% Process in CPU
gain = myfunction(cap);
% Copy back to GPU on win2
tex1 = Screen('MakeTexture', win2, cap, [], 1 );
tex2 = Screen('MakeTexture', win2, gain, [], 1 );
if tex == 0
continue;
end
% Draw the new texture immediately to screen:
Screen('DrawTexture', win, tex, [], [], [],[],[],[]);
Screen('DrawTexture', win1, tex, [],[0 0 w_size(3)*scale w_size(4)*scale],[],1);
Screen('DrawTextures',win2, [tex1 tex2], [], [], [],[],[],[], glsl);
Screen('Flip', win);
Screen('Flip', win2);
% Release texture:
Screen('Close', tex);
Screen('Close', tex1);
end
toc
% Stop playback:
Screen('PlayMovie', movie, 0)
% Close movie:
Screen('CloseMovie', movie);
% Close Screen, we're done:
Screen('CloseAll');
catch %#ok<CTCH>
sca;
psychrethrow(psychlasterror);
end
return