File: DrawingIntoTexturesTest.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (65 lines) | stat: -rw-r--r-- 1,662 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function DrawingIntoTexturesTest(imagingmode)

if IsOctave
  pkg load image;
end

AssertOpenGL;

screenid = max(Screen('Screens'));

if nargin < 1
    imagingmode = [];
end

if isempty(imagingmode)
    imagingmode = 0;
end

if imagingmode > 0
    imagingmode = kPsychNeedFastBackingStore;
    floatflag = 2;
else
    imagingmode = 0;
    floatflag = 0;
end

% Open window, with or without imaging pipeline:
win = Screen('OpenWindow', screenid, 255, [], [], [], [], [], imagingmode);
Screen('Blendfunction', win, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

for floatprec =0:floatflag
    for layers=1:4
        fprintf('Testing Drawing into %i layer textures of precision mode %i...\n', layers, floatprec);

        inimg = imread([PsychtoolboxRoot 'PsychDemos/konijntjes1024x768.jpg']);
        switch layers
            case 1,
                teximg = rgb2gray(inimg);
            case 2,
                teximg = randn(size(inimg, 1), size(inimg, 2), 2) * 255;
                teximg(:,:,1) = rgb2gray(inimg);
            case 3,
                teximg = inimg;
            case 4,
                teximg = randn(size(inimg, 1), size(inimg, 2), 4) * 255;
                teximg(:,:,1:3) = inimg;
        end

        if (floatprec>0)
            teximg = double(teximg)/255.0;
        end
        
        tex = Screen('MakeTexture', win, teximg, [], [], floatprec);

        DrawFormattedText(tex, ['Everything is fine with ' num2str(layers) ' layers of precision' num2str(floatprec) '...'], 'center', 'center');

        Screen('DrawTexture', win, tex);
        Screen('Flip', win);

        while KbCheck; end;
        KbWait;
    end
end

Screen('CloseAll');