Search code examples
pythonopenglpygletpsychopy

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.


Solution

  • 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