+1  A: 

While I don't know much (read: any) Matlab, I do know that textures are very picky in openGL. Last I checked, openGL requires texture files to be square and of a power of two (i.e. 128 x 128, 256 x 256, 512 x 512).

If they aren't, openGL is supposed to pad the file with appropriate white pixels where they're needed to meet this condition, although it could be a crapshoot depending on which system you are running it on.

I suggest making sure that your checkerboard texture fits these requirements.

Also, I can't quite make sure from your code posted, but openGL expects you to map the corners of your texture to the corners of the object you are intending to texture.

Another bit of advice, maybe try a linear filter instead of nearest neighbor. It's heavier computationally, but results in a better image. This probably won't matter in the end.

While this help is not Matlab specific, hope it is useful.

SauceMaster
+1  A: 

Without knowing a lot about the Psychtoolbox, but having dealt with graphics and user interfaces a lot in MATLAB, the first thing I would try would be to fiddle with the fourth input to Screen (the "source" input). Try shifting each corner by half-pixel and whole-pixel values. For example, the first thing I would try would be:

Screen('DrawTexture', win, tex, [0 0 2.5 2.5], [100 100 200 200], 0, 0);

And if that didn't seem to do anything, I would next try:

Screen('DrawTexture', win, tex, [0 0 3 3], [100 100 200 200], 0, 0);

My reasoning for this advice: I've noticed sometimes that images or GUI controls in my figures can appear to be off by a pixel, which I can only speculate is some kind of round-off error when scaling or positioning them.

That's the best advice I can give. Hope it helps!

gnovice
I had not expected this to work, because the source rectangle is only 2x2 and the last .5 should thus be empty. However, it did, so thanks! The solution when trying to show a BxA matrix is to use a source rectangle of [0 0 A+.5 B+.5].
Jordi
Honestly, I'm a little surprised it was that easy too. As I was typing it, it sounded like I was telling you the software equivalent of "just hit the side of the machine a few times and it will work". I guess testing the simplest things first can really pay off! =)
gnovice

related questions