using glBindTexture with multiple monitor setup

Hello,
I am trying to set up a haploscope using two CRT monitors. I have
been attempting to use the Stereo mode of Screen to handle the two
displays. I am rendering my stimuli with GL.

The code works fine in anaglyph stereo and multi display stereo with
my scene of GL primitives.

However, once I add a glBindTexture command after my Screen
('OpenWindow') command, the program will only run in anaglyph mode.
When I try to run it in the multi-screen mode it says:

??? MOGL-Error: Your OpenGL command glBindTexture() caused the
following OpenGL error: invalid operation. Aborted.

These are my Screen commands

[windowPtr , winRect] = Screen('OpenWindow', screenid, 0, [], [], [],
viewMode, 0);

if viewMode==10
Screen('OpenWindow', 1, 0, [], [], [], viewMode, 0);
end

I've tried it on an intel-imac and an intel-MacPro, with the same
problem turning up on both setups.

Does anyone know what might be wrong, or have some example code where
they bound textures on a multiple monitor setup?

Thanks,
David
Please post all your relevant code up to the glBindTexture
call. Adding a simple glBindTexture() doesn't cause any
problem on my setup, so this should work.

-mario

--- In psychtoolbox@yahoogroups.com, "david_h514" <davem.hoffman@...> wrote:
>
> Hello,
> I am trying to set up a haploscope using two CRT monitors. I have
> been attempting to use the Stereo mode of Screen to handle the two
> displays. I am rendering my stimuli with GL.
>
> The code works fine in anaglyph stereo and multi display stereo with
> my scene of GL primitives.
>
> However, once I add a glBindTexture command after my Screen
> ('OpenWindow') command, the program will only run in anaglyph mode.
> When I try to run it in the multi-screen mode it says:
>
> ??? MOGL-Error: Your OpenGL command glBindTexture() caused the
> following OpenGL error: invalid operation. Aborted.
>
> These are my Screen commands
>
> [windowPtr , winRect] = Screen('OpenWindow', screenid, 0, [], [], [],
> viewMode, 0);
>
> if viewMode==10
> Screen('OpenWindow', 1, 0, [], [], [], viewMode, 0);
> end
>
> I've tried it on an intel-imac and an intel-MacPro, with the same
> problem turning up on both setups.
>
> Does anyone know what might be wrong, or have some example code where
> they bound textures on a multiple monitor setup?
>
> Thanks,
> David
>
Hi Mario,
Thanks for trying out the glBindTexture command on multiple monitors.
Here is the relevant portion of the code.
Passing in argument 10 to the function will cause the error. Getting
rid of the glBindTexture command will make it compile.

David


function [] = Stereo_reduced(viewMode)


if(nargin() < 1)
viewMode = 9; %Default to red/blue anaglyph
end

% Is the script running in OpenGL Psychtoolbox?
AssertOpenGL;
InitializeMatlabOpenGL;

% Find the screen to use for display:
screenid=max(Screen('Screens'));

if viewMode == 10
% Yes. Do we have at least two separate displays for both views?
if length(Screen('Screens')) < 2
error('Sorry, for stereoMode 10 you''ll need at least 2
separate display screens in non-mirrored mode.');
end

if ~IsWin
% Assign left-eye view (the master window) to main display:
screenid = 0;
else
% Assign left-eye view (the master window) to main display:
screenid = 1;
end
end




ListenChar(2)
try

% Enable unified mode of KbName, so KbName accepts identical key
names on
% all operating systems:
KbName('UnifyKeyNames');




% Open a double-buffered full-screen window on the main displays
screen.
[windowPtr , winRect] = Screen('OpenWindow', screenid, 0, [], [],
[], viewMode, []);




if viewMode == 10
% In dual-window, dual-display mode, we open the slave window on
% the secondary screen. Please note that, after opening this
window
% with the same parameters as the "master-window", we won't touch
% it anymore until the end of the experiment. PTB will take
care of
% managing this window automatically as appropriate for a stereo
% display setup. That is why we are not even interested in the
window
% handles of this window:
if IsWin
slaveScreen = 2;
else
slaveScreen = 1;
end
Screen('OpenWindow', slaveScreen, 0, [], [], [], viewMode, []);
end


% Initially fill left- and right-eye image buffer with black
background
% color:
Screen('SelectStereoDrawBuffer', windowPtr, 0);
Screen('FillRect', windowPtr, BlackIndex(screenid));
Screen('SelectStereoDrawBuffer', windowPtr, 1);
Screen('FillRect', windowPtr, BlackIndex(screenid));

% Show cleared start screen:
Screen('Flip', windowPtr);



glActiveTexture(GL.TEXTURE1);
glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);
glActiveTexture(GL.TEXTURE0);
glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);

glClearDepth(1.0);
DEPTHTEXSIZE=1024;
depthtex_id=1;
for i=1:DEPTHTEXSIZE
texture(i)=10;
end
charimage=uint8(texture);


glBindTexture(GL.TEXTURE_1D, depthtex_id)



glTexImage1D(GL.TEXTURE_1D, 0, GL.LUMINANCE8,
DEPTHTEXSIZE, 0, GL.LUMINANCE, GL.UNSIGNED_BYTE, charimage)
glTexParameteri(GL.TEXTURE_1D,
GL.TEXTURE_MIN_FILTER, GL.LINEAR);
glTexParameteri(GL.TEXTURE_1D,
GL.TEXTURE_MAG_FILTER, GL.LINEAR);
glTexParameteri(GL.TEXTURE_1D, GL.TEXTURE_WRAP_S,
GL.CLAMP);




glActiveTexture(GL.TEXTURE1);
glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);
glActiveTexture(GL.TEXTURE0);
glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);


% Display loop: hit escape to exit
while (1)

[strInputName, x, y] = bvlWaitForInput(0.001);
if strcmp(strInputName, 'ESCAPE')
ListenChar(0);
break;
end


end


% Close onscreen window and release all other ressources:
Screen('CloseAll');

% Reenable Synctests after this simple demo:
Screen('Preference','SkipSyncTests',1);

% Well done!
%return
catch
% Executes in case of an error: Closes onscreen window:
Screen('CloseAll');
ListenChar(0);
psychrethrow(psychlasterror);
end;




--- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
<mario.kleiner@...> wrote:
>
> Please post all your relevant code up to the glBindTexture
> call. Adding a simple glBindTexture() doesn't cause any
> problem on my setup, so this should work.
>
> -mario
>
> --- In psychtoolbox@yahoogroups.com, "david_h514" <davem.hoffman@>
wrote:
> >
> > Hello,
> > I am trying to set up a haploscope using two CRT monitors. I have
> > been attempting to use the Stereo mode of Screen to handle the two
> > displays. I am rendering my stimuli with GL.
> >
> > The code works fine in anaglyph stereo and multi display stereo with
> > my scene of GL primitives.
> >
> > However, once I add a glBindTexture command after my Screen
> > ('OpenWindow') command, the program will only run in anaglyph mode.
> > When I try to run it in the multi-screen mode it says:
> >
> > ??? MOGL-Error: Your OpenGL command glBindTexture() caused the
> > following OpenGL error: invalid operation. Aborted.
> >
> > These are my Screen commands
> >
> > [windowPtr , winRect] = Screen('OpenWindow', screenid, 0, [], [], [],
> > viewMode, 0);
> >
> > if viewMode==10
> > Screen('OpenWindow', 1, 0, [], [], [], viewMode, 0);
> > end
> >
> > I've tried it on an intel-imac and an intel-MacPro, with the same
> > problem turning up on both setups.
> >
> > Does anyone know what might be wrong, or have some example code where
> > they bound textures on a multiple monitor setup?
> >
> > Thanks,
> > David
> >
>
That was the expected mistake ;-) -- Good, saves time.

1. Wrap all your glXXX commands in pairs of
Screen('BeginOpenGL', windowPtr); and
Screen('EndOpenGL', windowPtr);

-> Isolates your OpenGL code from PTB's internal code
and does a few other magic things.
-> If you try to call Screen() commands inside such a
'Begin' 'End' pair, PTB will abort with error.

2. This...
depthtex_id=1;
...is bad - and the reason for the error.
use...
depthtex_id=glGenTextures(1);
...instead.

Texture handles are shared between PTB and your code,
and between all open displays, and PTB uses some textures
for itself internally sometimes, so if you hardcode a handle
to be '1' like here, it will likely happen that this handle
is already used by someone else (your code, or PTB's
internal textures) and you'll get a conflict. In case of
stereomode 10, handle 1 will probably be used for
a texture of type GL_TEXTURE_RECTANGLE_EXT, so
your glBindTexture(GL.TEXTURE_1D, ...); call tries to
attach an existing rectangle 2D texture to a 1D
texture target ---> Invalid operation error.

The glGenTextures(n) call will return you 'n' unused
texture handles for a pleasant texture mapping experience,
so that's how to do it.

If a GL call throws some error like 'invalid operation', you
can open the MacOS/X terminal window and type
'man commandname', e.g., man glBindTexture
That will give you the online help for glBindTexture, and
at the end a list of possible error messages and their
likely cause. This one would be:

"GL_INVALID_OPERATION is generated if texture has a
dimensionality that doesn't match that of target."

best,
-mario


--- In psychtoolbox@yahoogroups.com, "david_h514" <davem.hoffman@...> wrote:
>
> Hi Mario,
> Thanks for trying out the glBindTexture command on multiple monitors.
> Here is the relevant portion of the code.
> Passing in argument 10 to the function will cause the error. Getting
> rid of the glBindTexture command will make it compile.
>
> David
>
>
> function [] = Stereo_reduced(viewMode)
>
>
> if(nargin() < 1)
> viewMode = 9; %Default to red/blue anaglyph
> end
>
> % Is the script running in OpenGL Psychtoolbox?
> AssertOpenGL;
> InitializeMatlabOpenGL;
>
> % Find the screen to use for display:
> screenid=max(Screen('Screens'));
>
> if viewMode == 10
> % Yes. Do we have at least two separate displays for both views?
> if length(Screen('Screens')) < 2
> error('Sorry, for stereoMode 10 you''ll need at least 2
> separate display screens in non-mirrored mode.');
> end
>
> if ~IsWin
> % Assign left-eye view (the master window) to main display:
> screenid = 0;
> else
> % Assign left-eye view (the master window) to main display:
> screenid = 1;
> end
> end
>
>
>
>
> ListenChar(2)
> try
>
> % Enable unified mode of KbName, so KbName accepts identical key
> names on
> % all operating systems:
> KbName('UnifyKeyNames');
>
>
>
>
> % Open a double-buffered full-screen window on the main displays
> screen.
> [windowPtr , winRect] = Screen('OpenWindow', screenid, 0, [], [],
> [], viewMode, []);
>
>
>
>
> if viewMode == 10
> % In dual-window, dual-display mode, we open the slave window on
> % the secondary screen. Please note that, after opening this
> window
> % with the same parameters as the "master-window", we won't touch
> % it anymore until the end of the experiment. PTB will take
> care of
> % managing this window automatically as appropriate for a stereo
> % display setup. That is why we are not even interested in the
> window
> % handles of this window:
> if IsWin
> slaveScreen = 2;
> else
> slaveScreen = 1;
> end
> Screen('OpenWindow', slaveScreen, 0, [], [], [], viewMode, []);
> end
>
>
> % Initially fill left- and right-eye image buffer with black
> background
> % color:
> Screen('SelectStereoDrawBuffer', windowPtr, 0);
> Screen('FillRect', windowPtr, BlackIndex(screenid));
> Screen('SelectStereoDrawBuffer', windowPtr, 1);
> Screen('FillRect', windowPtr, BlackIndex(screenid));
>
> % Show cleared start screen:
> Screen('Flip', windowPtr);
>
>
>
> glActiveTexture(GL.TEXTURE1);
> glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);
> glActiveTexture(GL.TEXTURE0);
> glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);
>
> glClearDepth(1.0);
> DEPTHTEXSIZE=1024;
> depthtex_id=1;
> for i=1:DEPTHTEXSIZE
> texture(i)=10;
> end
> charimage=uint8(texture);
>
>
> glBindTexture(GL.TEXTURE_1D, depthtex_id)
>
>
>
> glTexImage1D(GL.TEXTURE_1D, 0, GL.LUMINANCE8,
> DEPTHTEXSIZE, 0, GL.LUMINANCE, GL.UNSIGNED_BYTE, charimage)
> glTexParameteri(GL.TEXTURE_1D,
> GL.TEXTURE_MIN_FILTER, GL.LINEAR);
> glTexParameteri(GL.TEXTURE_1D,
> GL.TEXTURE_MAG_FILTER, GL.LINEAR);
> glTexParameteri(GL.TEXTURE_1D, GL.TEXTURE_WRAP_S,
> GL.CLAMP);
>
>
>
>
> glActiveTexture(GL.TEXTURE1);
> glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);
> glActiveTexture(GL.TEXTURE0);
> glTexEnvi(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);
>
>
> % Display loop: hit escape to exit
> while (1)
>
> [strInputName, x, y] = bvlWaitForInput(0.001);
> if strcmp(strInputName, 'ESCAPE')
> ListenChar(0);
> break;
> end
>
>
> end
>
>
> % Close onscreen window and release all other ressources:
> Screen('CloseAll');
>
> % Reenable Synctests after this simple demo:
> Screen('Preference','SkipSyncTests',1);
>
> % Well done!
> %return
> catch
> % Executes in case of an error: Closes onscreen window:
> Screen('CloseAll');
> ListenChar(0);
> psychrethrow(psychlasterror);
> end;
>
>
>
>
> --- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
> <mario.kleiner@> wrote:
> >
> > Please post all your relevant code up to the glBindTexture
> > call. Adding a simple glBindTexture() doesn't cause any
> > problem on my setup, so this should work.
> >
> > -mario
> >
> > --- In psychtoolbox@yahoogroups.com, "david_h514" <davem.hoffman@>
> wrote:
> > >
> > > Hello,
> > > I am trying to set up a haploscope using two CRT monitors. I have
> > > been attempting to use the Stereo mode of Screen to handle the two
> > > displays. I am rendering my stimuli with GL.
> > >
> > > The code works fine in anaglyph stereo and multi display stereo with
> > > my scene of GL primitives.
> > >
> > > However, once I add a glBindTexture command after my Screen
> > > ('OpenWindow') command, the program will only run in anaglyph mode.
> > > When I try to run it in the multi-screen mode it says:
> > >
> > > ??? MOGL-Error: Your OpenGL command glBindTexture() caused the
> > > following OpenGL error: invalid operation. Aborted.
> > >
> > > These are my Screen commands
> > >
> > > [windowPtr , winRect] = Screen('OpenWindow', screenid, 0, [], [], [],
> > > viewMode, 0);
> > >
> > > if viewMode==10
> > > Screen('OpenWindow', 1, 0, [], [], [], viewMode, 0);
> > > end
> > >
> > > I've tried it on an intel-imac and an intel-MacPro, with the same
> > > problem turning up on both setups.
> > >
> > > Does anyone know what might be wrong, or have some example code where
> > > they bound textures on a multiple monitor setup?
> > >
> > > Thanks,
> > > David
> > >
> >
>