Texture in the trainingcourse 4

In the PVRshell Texture in the trainingcourse 4, the texture is defined as

 

TEX_SIZE = 128;

 GLuint* pTexData1 = new GLuint[TEX_SIZE*TEX_SIZE];
 for (int i=0; i<TEX_SIZE; i++)
 for (int j=0; j<TEX_SIZE; j++)
 {
  GLuint col = (255L<<24) + ((255L-j*2)<<16) + ((255L-i)<<8) + (255L-i*2);
  if ( ((i*j)/8) % 2 ) col = (GLuint) (255L<<24) + (255L<<16) + (0L<<8) + (255L);
 
  pTexData1[j*TEX_SIZE+i] = col;
 }
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTexData1);
 delete [] pTexData1;

 

The corresponding texture image looks like http://i51.tinypic.com/2j41y0m.jpg

 

However, when I defined the same texture with the same RGB components in matlab and I got the texture image which is simlar as  

 

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)

 

Hi,

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.

the sdk deals with either png or pvr files. jpegs need to be converted.


Hi cgp,





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).





Thanks,


Joe