2

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.

mmagnuski
  • 1,249
  • 1
  • 11
  • 23
  • +1 for the reproducible example. The same thing happens substituting the TextStim for the new TextBox stimulus as well, which was my only suggestion... – Michael MacAskill Aug 24 '15 at 15:08

2 Answers2

2

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

Jon
  • 1,198
  • 7
  • 8
  • I am experiencing the same issue, but this does not solve it for me. `win.blendMode` does not seem to be changing, and forcing it to `'add'` after drawing the text does not revert the problem. My stims look OK if no text has been drawn. I am on psychopy version '1.80.01'. Do you have any ideas for why it might not be working? – mwaskom Jun 29 '16 at 15:46
  • FWIW I am developing the code on a laptop with an Intel integrated graphics card, which might be the culprit. – mwaskom Jun 29 '16 at 15:53
  • Or the fact that 1.80.01 is a couple of years old. We may have fixed bugs since then. Could you do an upgrade and see? – Jon Jun 30 '16 at 17:04
  • I've just fixed this in PsychoPy itself, effectively resetting the blendMode every time text gets rendered. This doesn't fix the issue with pyglet text itself (we can't render the pyglet text itself using blendmode='add' because we don't have control over the pyglet lib) and I've added a warning to users about that issue, but at least it won't now affect other stimuli. – Jon Mar 15 '17 at 15:28
0

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.

Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
  • The problem is that I am using blendMode add to be able to obtain contrast > 1.0 without marking the out of bounds rgb values with noise, and for this I am relying on some monkey patched shaders for pyglet (see the github issue I link in the question), so I am not sure whether what I am trying to do will work with pygame. I will check tomorrow, thanks! – mmagnuski Aug 24 '15 at 23:02
  • Are you sure that the blendMode remains 'add' when the text is drawn? In my case I get these warnings: `6.9603 WARNING Framebuffer object (FBO) not supported on this graphics card 6.9603 WARNING Framebuffer object (FBO) is required for blendMode='add'. Reverting to blendMode='avg'` so I can't get blendMode add with pygame. The graphics card I have is nvidia GeForce GTX 650, so it should be sufficient for FBO. – mmagnuski Aug 25 '15 at 17:25
  • No, I'm not sure blendmode remains the same for pygame, now that you raise that issue. Happy to see that Jon solved your problem! – Jonas Lindeløv Aug 25 '15 at 19:31