0

I have drawn a 10x10 grid of noise textures. I would like to be able to control the depth of each texture. As a test I tried translating half of the textured objects with the z coordinate at -.5 but it seems to be having no effect. What am I missing?

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0, 0, RectWidth(winRect), RectHeight(winRect));
glMatrixMode(GL.PROJECTION);
glLoadIdentity;

glMatrixMode(GL.MODELVIEW);
glLoadIdentity;


glEnable(GL.TEXTURE_2D);


wall_texid = glGenTextures(1);
halfTextureSize = 128; % in px for meshgrid

%plaidData = makePlaidData(halfTextureSize);
%normalizedPlaidData = (plaidData - min(plaidData)) / ( max(plaidData) - min(plaidData) );

[x,y] = meshgrid(-halfTextureSize+1:halfTextureSize,-halfTextureSize+1:halfTextureSize);

noysSlope = 1.0; %1.5;
noys = 255.*oneoverf(noysSlope, size(x,1), size(x,2)); % oneoverf -> [0:1]
noys=repmat(noys,[ 1 1 3 ]);
noys=permute(uint8(noys),[ 3 2 1 ]);

xoffset = -10:1:10;
yoffset = -10:1:10;
rmin_bg = 45.6874;% pixels 
rmax_bg = 350.7631;% pixels  
rstrip = 11.6268;% this cuts a strip into the fixation disk that has a height the size of the paddle height
% this code pokes out the transparent aperture
opaque = ones(size(x'));

% for i = 1:length(xoffset)
%     opaque = min(opaque, ((sqrt((x'+xoffset(i)).^2+(y'+yoffset(i)).^2) >  rmax_bg)  |( sqrt((x'+xoffset(i)).^2+(y'+yoffset(i)).^2) <  rmin_bg)));
% end
% noys(4,:,:) = shiftdim(255 .* opaque, -1); 

glBindTexture(GL_TEXTURE_2D,  wall_texid);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, halfTextureSize*2, halfTextureSize*2, 0, GL_RGB, GL_UNSIGNED_BYTE, noys);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

%glClear(GL.COLOR_BUFFER_BIT);
corners = [0 0;
    1 0;
    1 1;
    0 1
];

halfHeight = winRect(4)/2;
halfWidth  = winRect(3)/2;
canvas = .09; % pick the larger of the two dimensions, since they are not equal
depth = 0.0;
v=[-canvas -canvas depth;... 
    canvas -canvas depth;...
    canvas canvas  depth;...
    -canvas canvas depth]';

surroundTexture = glGenLists(1);
glNewList(surroundTexture, GL.COMPILE);
glBegin(GL.POLYGON);

for i = 1:4
    
    glTexCoord2dv(corners(i,:));
    glVertex3dv(v(:,i));
end

glEnd;

glEndList;



translations = struct('x',{},'y',{},'z',{});
index = 1;
offset = 0.1;
for y = -10:2:9
    for x = -10:2:9
        translation.x = x / 10.0 + offset;
        translation.y = y / 10.0 + offset;
        translations(index) = translation;
        index = index+1;
    end
end

    %%%Draw texture grid%%%%
    for i = 1:100
        glPushMatrix;
        if i < 51
             glTranslated(translations(i).x, translations(i).y, -.5);
        else
             glTranslated(translations(i).x, translations(i).y, 0.0);
        end
        glCallList(surroundTexture);
        glPopMatrix;
    end

NB: I am using PsychToolBox which gives access to opengl in Matlab.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Ben Jenney
  • 75
  • 6
  • 3
    Changing the texture-coordinate z value when querying a 2D texture is not supposed to have any effect. What are you expecting to happen? – BDL Aug 10 '21 at 18:10
  • I figured since the textures have no sides, they are effectively rectangles, that I could draw 2d textures and translate them along the z-axis in the world. I guess this is incorrect? – Ben Jenney Aug 10 '21 at 18:14
  • 3
    Ah, so you are talking about moving the object along the z-axis? ModelView and Projection matrix are both identity matrices, when you look at a quad from the front and with parallel projection, there is no difference how far away the object is. (unless it's outside of the clip space). – BDL Aug 10 '21 at 18:16
  • I figured that translating the objects along the z-axis would move them away from the camera making them "smaller". Am I using the wrong type of projection? – Ben Jenney Aug 10 '21 at 18:24
  • 2
    You are not using any projection at all, you are setting the projection matrix to an identity matrix. If you want a perspective projection, you need to set that. For example, with `gluPerspective`. – BDL Aug 10 '21 at 18:26

0 Answers0