Texture in the trainingcourse 4

This topic contains 3 replies, has 4 voices, and was last updated by  Joe Davis 6 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #30324

    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;
     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;
        pTexData(i,j,1)= R;
        pTexData(i,j,2)= G;
        pTexData(i,j,3)= B;
    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((i*j)/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, (i*j)/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.


    Joe Davis

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



Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.