mmagnuski
mmagnuski

Reputation: 1275

Psychopy: bad contrast in blendMode add

I am using blendMode="add" in psychopy - ufortunatelly GratingStim contrast works well only when no text is drawn in the window. As soon as text is drawn - following GratingStims contrast looks as if 1 was subtracted from it (take a look at the screenshots). I don't experience this problem with avg blendMode, but I really need blendMode="add".

This is how the GratingStim looks before text is drawn:
enter image description here
This is how it looks after some text is drawn:
enter image description here

After drawing text to the window any following GratingStim has contrast rendered like this. Only opening another window helps.
I guess this can be solved by injecting some shaders into pyglet, but I have no idea how to do it (related issue on github).

The code below reproduces this problem:

from psychopy import visual, event, core

win = visual.Window(monitor='testMonitor', useFBO=True,
    blendMode='add', units='deg')

g = visual.GratingStim(win, tex='sin', mask='gauss', size=4.5, pos=(0,6))
t = visual.TextStim(win=win, text='Hello blendMode="add"!')

draw_order = [[g], [g, t], [g, t]]
for draw_now in draw_order:
    for stim in draw_now:
        stim.draw()
    win.flip()
    event.waitKeys()

core.quit()

I am using Windows - I have this problem on both Windows 7 and 8.

Upvotes: 2

Views: 296

Answers (2)

Jon
Jon

Reputation: 1223

OK, my guess is that the pyglet text renderer is executing some code that alters the blendmode rule so that when the text is drawn its left in the wrong state. For now doing

win.blendMode = 'add'

after drawing the text stimulus fixes the problem for me

Upvotes: 2

Jonas Lindeløv
Jonas Lindeløv

Reputation: 5683

Set visual.Window(wynType='pygame') rather than the default winType='pyglet'. In your example:

win = visual.Window(monitor='testMonitor', useFBO=True,
blendMode='add', units='deg', winType='pygame')

Why this solves the problem, I'm not entirely sure. I came up with this guess by looking at the source code for the TextStim.draw method in which a whole bunch of calls to GL are executed for pyglet but not for pygame.

Upvotes: 0

Related Questions