# Imprecise position of offscreen window

**URL:** https://psychtoolbox.discourse.group/t/imprecise-position-of-offscreen-window/3972
**Category:** Programming Help
**Tags:** windows
**Created:** [August 15, 2021, 2:21pm UTC](https://psychtoolbox.discourse.group/t/imprecise-position-of-offscreen-window/3972 "2021-08-15T14:21:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![opn](https://avatars.discourse-cdn.com/v4/letter/o/ebca7d/32.png) [@opn](https://psychtoolbox.discourse.group/u/opn)
#### Post date: [August 15, 2021, 2:21pm UTC](https://psychtoolbox.discourse.group/t/imprecise-position-of-offscreen-window/3972/1 "2021-08-15T14:21:16Z")

</div>

Hi everyone!

In my script I flip an offscreen window, wait for the detection of an event and then flip a second offscreen window as fast as possible. The image textures that I draw to the first and the second offscreen window are supposed to have exactly the same size and position. However, in some but not all instances, the second image appears in a slightly different position. The difference is just big enough to detect it, but seems to be only about one or two pixel. I would be grateful for any pointers for solving this problem, thank you!

> % prepare first offscreen window  
> image\_1 = imread(strcat(impath, current\_image\_name\_1,‘.jpg’));  
> texture\_1 = Screen(‘MakeTexture’, window, image\_1);  
> offscreen\_1 = Screen(‘OpenOffscreenWindow’, window, 0, );  
> Screen(‘DrawTextures’, offscreen\_1, texture\_1, , dstRects);
> 
> % prepare second offscreen window  
> image\_2 = imread(strcat(impath, current\_image\_name\_2,‘.jpg’));  
> texture\_2 = Screen(‘MakeTexture’, window, image\_2);  
> offscreen\_2 = Screen(‘OpenOffscreenWindow’, window, 0, );  
> Screen(‘DrawTextures’, offscreen\_2, texture\_2, , dstRects);
> 
> % flip lines and first offscreen window  
> Screen(‘DrawLines’, window, ArrowCoords, lineWidth, white, [xm ym], 2);  
> Screen(‘CopyWindow’, offscreen\_1, window, dstRects, dstRects)  
> [VBLT, StimulusOnset, FlipTimestamp, missed, beampos] = Screen(‘Flip’, window);
> 
> % […] (code for detecting event)
> 
> % as soon as the event is detected, flip lines and second offscreen window  
> Screen(‘DrawLines’, window, ArrowCoords, lineWidth, white, [xm ym], 2);  
> Screen(‘CopyWindow’, offscreen\_2, window, dstRects, dstRects);  
> [VBLT, StimulusOnset, FlipTimestamp, missed, beampos] = Screen(‘Flip’, window);

Psychtoolbox version: 3.0.15 - Flavor: beta  
MATLAB version: 9.5.0.944444 (R2018b)  
Intel(R) Core™ i7-7820HK CPU @ 2.90GHz; RAM 64 GB; Windows 10  
graphics card driver: NVIDA GeForce GTX 1080, version: 25.21.14.1735  
screen: 24.5" Full HD 1920x1080p 240Hz

---

<div class="post-metadata">

### Author: ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)
#### Post date: [August 15, 2021, 3:30pm UTC](https://psychtoolbox.discourse.group/t/imprecise-position-of-offscreen-window/3972/2 "2021-08-15T15:30:09Z")

</div>

are your two images exactly the same size when loaded into matlab?

Other than that, i’d skip the whole offscreen windows, and just drawtextures directly on the main screen, any graphics card will be able to easily handle that, unless its some insane amount you’re drawing them
