Can anyone give a hint why the textures images are different?
Here is the matlab code
TEX_SIZE = 128; for i=1:TEX_SIZE for j=1:TEX_SIZE R = 255; G = 255-j*2 ; B = 255-i; A = 255-i*2; if (mod((i*j)/8,2)) R = 255; G = 255; B = 0; A = 255; end pTexData(i,j,1)= R; pTexData(i,j,2)= G; pTexData(i,j,3)= B; end end pTexData = uint8(pTexData); imagesc (pTexData); figure(gcf)
I don’t know anything about Matlab, but i and j in the Matlab version run from 1 to 128 instead of 0 to 127 in the C++ version; thus, the expression mod((ij)/8,2) will result in different values. You should use mod(((i-1)(j-1))/8,2) in the Matlab version to take this into account.
Also, in the C++ code, (ij)/8 will be rounded down to the next smaller integer. I assume that Matlab doesn’t do this, thus you should use something like a “floor” function (I don’t know the Matlab function to round down, “floor” is just a guess), i.e.: mod(floor(((i-1)(j-1))/8),2)
Also note that alpha is the highest-valued byte and red the lowest-valued; thus, your variable names are a bit confusing.
While we appreciate that your responses to several topics have been informative, we prefer not to resurrect topics that have been inactive for long periods of time. Instead, can you please create new topics to discuss these issues, or respond to topics that are still live (this way, it’s more likely that others in the community will benefit from your advice).