# All elements clipped at a certain distance from the edge?

**URL:** <https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271>\
**Category:** Coding\
**Tags:** screen\
**Created:** [June 27, 2019, 3:44pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271 "2019-06-27T15:44:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam\_coyne](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@adam\_coyne](https://discourse.psychopy.org/u/adam_coyne)\
**Post date:** [June 27, 2019, 3:44pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/1 "2019-06-27T15:44:35Z")

</div>

Hi all, so bear with me, I just started using PsychoPy!

Very simple issue; I want to show a TextStim near the top of the window (to act as a title). It seems to be clipped off once it gets to a certain distance:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/e/6e570d097e0d6a666761a3bd11836c4e9bc3052e.png)

So of course I could just move it lower and change everything accordingly, but it would be great if I could increase that boundary somehow.  
Anyone know what’s going on here?

**OS** : Ubuntu 16.04  
**PsychoPy version** : 3.1.2  
**Standard Standalone? (y/n)**: Yes (I think)

Thanks! 🙂

**Edit:** A colleague recommended I move to pure coding instead of the Builder. I’m comfortable with Python, so I’m changing the topic to Coding.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [June 28, 2019, 12:57pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/2 "2019-06-28T12:57:32Z")

</div>

Hi @adam_coyne, its hard to know without seeing your code. If you are using an Aperture component to control where text can be presented, you could try making the aperture larger. If not, would you mind sharing a minimal working example? E.g. one slider and the text component.

---

<div class="post-metadata">

**Author:** ![adam\_coyne](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@adam\_coyne](https://discourse.psychopy.org/u/adam_coyne)\
**Post date:** [June 28, 2019, 3:40pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/3 "2019-06-28T15:40:10Z")

</div>

So I think I may have found a bug. I was preparing a working example with a single routine, and I found that without other routines before the one pictured the problem didn’t occur. It seems to be clipped to the edges of the Form component I used in the previous one.

So far I haven’t messed around with the code, here’s two examples generated by the Builder so I’m sure it’s fairly standard:  
[testingAWN\_1routine.py](https://discourse.psychopy.org/uploads/short-url/6hUTAvbdTVQ9H074bPwesUIe7Vx.py) (18.4 KB) [testingAWN\_2routines.py](https://discourse.psychopy.org/uploads/short-url/NKsnReO2hln09LWJj7MGAAzx1p.py) (22.8 KB)

For me, the 1routine file displays fine, but the same routine with the Form preceding it cuts off the edges like I described.

---

<div class="post-metadata">

**Author:** ![adam\_coyne](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@adam\_coyne](https://discourse.psychopy.org/u/adam_coyne)\
**Post date:** [June 28, 2019, 3:42pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/4 "2019-06-28T15:42:22Z")

</div>

Here’s a quick view of how it looks.

Single routine:

 ![1routine](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/5/75404aa723d2018d8f298fb8ed4a577686d89fad.png)  
The same routine, after another with a Form component:  
 ![2routines](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/4/f45d0109cae0f61f06bc94b71208ac2572c68a51.png)

Also I realised you’ll need form questions for the 2routines file, here’s mine: [ssq.xlsx](https://discourse.psychopy.org/uploads/short-url/cUwhM7PnqTwrwc01cD9rlWj1sLg.xlsx) (5.3 KB)

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [June 28, 2019, 6:17pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/5 "2019-06-28T18:17:49Z")

</div>

Yes, it is related to the aperture that is being used in the Form component, however I cannot recreate this error from Builder or Coder. Would you mind also sending me your psyexp file?

---

<div class="post-metadata">

**Author:** ![adam\_coyne](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@adam\_coyne](https://discourse.psychopy.org/u/adam_coyne)\
**Post date:** [July 1, 2019, 12:26pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/6 "2019-07-01T12:26:58Z")

</div>

Here’s the experiment file. You’ll also need the ssq.xlsx file again.  
[2routines.psyexp](https://discourse.psychopy.org/uploads/short-url/wgTKzuxHrxZ4hohgoUA1w8IMwrs.psyexp) (38.4 KB)  
Thanks for all your help!

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [July 1, 2019, 3:12pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/7 "2019-07-01T15:12:48Z")

</div>

@adam_coyne, there is a fix but this involves changing the source code. If you are happy to output your code into Coder and run the study from Coder, you just need to set the `useFBO` param in the Window component to False:

```auto
# Setup the Window
win = visual.Window(
    size=[1920, 1080], fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=False, # Change useFBO to False 
    units='height')

```

If you are happy to change the source code, go to the psychopy\>visual folder and in the `window.py" file and…

# replace line 690

> <https://github.com/psychopy/psychopy/blob/b5eeb16b14a50f1bf392338a3cd024b8a9853a55/psychopy/visual/window.py#L690>

# with the following:

```auto
if GL.glIsEnabled(GL.GL_STENCIL_TEST):
    GL.glEnable(GL.GL_STENCIL_TEST)

```

---

<div class="post-metadata">

**Author:** ![adam\_coyne](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@adam\_coyne](https://discourse.psychopy.org/u/adam_coyne)\
**Post date:** [July 1, 2019, 3:53pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/8 "2019-07-01T15:53:19Z")

</div>

So I tried changing the source code, however I don’t seem to have the same window.py as the one you linked. Here’s a snippet of my version where I found the only reference to `GL.glEnable(GL.GL_STENCIL_TEST)` (around line 790):

```auto
        flipThisFrame = self._startOfFlip()
        self.resetEyeTransform(False) # reset transformations
        if self.useFBO:
            if flipThisFrame:
                self._prepareFBOrender()
                # need blit the framebuffer object to the actual back buffer

                # unbind the framebuffer as the render target
                GL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0)
                GL.glDisable(GL.GL_BLEND)
                stencilOn = GL.glIsEnabled(GL.GL_STENCIL_TEST)
                GL.glDisable(GL.GL_STENCIL_TEST)

                if self.bits is not None:
                    self.bits._prepareFBOrender()

                # before flipping need to copy the renderBuffer to the
                # frameBuffer
                GL.glActiveTexture(GL.GL_TEXTURE0)
                GL.glEnable(GL.GL_TEXTURE_2D)
                GL.glBindTexture(GL.GL_TEXTURE_2D, self.frameTexture)
                GL.glColor3f(1.0, 1.0, 1.0) # glColor multiplies with texture
                GL.glColorMask(True, True, True, True)

                self._renderFBO()

                GL.glEnable(GL.GL_BLEND)
                self._finishFBOrender()

        # call this before flip() whether FBO was used or not
        self._afterFBOrender()

        self.backend.swapBuffers(flipThisFrame)
        if self.useFBO:
            if flipThisFrame:
                # set rendering back to the framebuffer object
                GL.glBindFramebufferEXT(
                    GL.GL_FRAMEBUFFER_EXT, self.frameBuffer)
                GL.glReadBuffer(GL.GL_COLOR_ATTACHMENT0_EXT)
                GL.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0_EXT)
                # set to no active rendering texture
                GL.glActiveTexture(GL.GL_TEXTURE0)
                GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
                if stencilOn:
                    GL.glEnable(GL.GL_STENCIL_TEST)

```

It seems to already include the stencil check you mentioned; I tried playing around with it, inverting the condition, removing the `if` statement, removing the `glEnable` line entirely, but it didn’t stop the issue. I see you’re a contributor on the Github @dvbridges, would you think this is a bug that should be reported?

Setting `useFBO=True` in the Coder did solve the problem however, so I’m happy meanwhile 🙂  
Thanks for all your time!

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [July 1, 2019, 4:01pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/9 "2019-07-01T16:01:40Z")

</div>

Ah I see, my fix only works on the GitHub repository as the changes have not been released yet (the fix has been posted [here](https://github.com/psychopy/psychopy/pull/2509)). You would instead go into the `psychopy\visual\backends` folder and make the changes to the `pygletbackend.py` file, line 291.

> <https://github.com/psychopy/psychopy/blob/25a78c77f4e3cb8f7bd22012952a0d87c47cc36b/psychopy/visual/backends/pygletbackend.py#L291>

---

<div class="post-metadata">

**Author:** ![adam\_coyne](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@adam\_coyne](https://discourse.psychopy.org/u/adam_coyne)\
**Post date:** [July 1, 2019, 5:06pm UTC](https://discourse.psychopy.org/t/all-elements-clipped-at-a-certain-distance-from-the-edge/8271/10 "2019-07-01T17:06:48Z")

</div>

Beautiful! All fixed, with the default project code. Thanks!
