# Texture in the trainingcourse 4

**URL:** <https://forums.imgtec.com/t/texture-in-the-trainingcourse-4/877>\
**Category:** PowerVR Insider\
**Created:** [October 22, 2010, 4:33pm UTC](https://forums.imgtec.com/t/texture-in-the-trainingcourse-4/877 "2010-10-22T16:33:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![renaissance](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@renaissance](https://forums.imgtec.com/u/renaissance)\
**Post date:** [October 22, 2010, 4:33pm UTC](https://forums.imgtec.com/t/texture-in-the-trainingcourse-4/877/1 "2010-10-22T16:33:19Z")

</div>

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

&nbsp;
  

_TEX\_SIZE = 128;_
  

_&nbsp;GLuint\* pTexData1 = new GLuint[TEX\_SIZE\*TEX\_SIZE];  
&nbsp;for (int i=0; i\<TEX\_SIZE; i++)  
&nbsp;for (int j=0; j\<TEX\_SIZE; j++)  
&nbsp;{  
&nbsp;&nbsp;GLuint col = (255L\<\<24) + ((255L-j\*2)\<\<16) + ((255L-i)\<\<8) + (255L-i\*2);  
&nbsp;&nbsp;if ( ((i\*j)/8) % 2 ) col = (GLuint) (255L\<\<24) + (255L\<\<16) + (0L\<\<8) + (255L);  
&nbsp;  
&nbsp;&nbsp;pTexData1[j\*TEX\_SIZE+i] = col;  
&nbsp;}  
&nbsp;glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGBA, TEX\_SIZE, TEX\_SIZE, 0, GL\_RGBA, GL\_UNSIGNED\_BYTE, pTexData1);  
&nbsp;delete [] pTexData1;_
  

&nbsp;
  

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

&nbsp;
  

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

[http://i54.tinypic.com/2pu060h.jpg](http://i54.tinypic.com/2pu060h.jpg)
  

&nbsp;
  

Can anyone give a hint why the textures images are different?
  

&nbsp;
  

Here is the matlab code 
  

_TEX\_SIZE = 128;  
for i=1:TEX\_SIZE  
for j=1:TEX\_SIZE  
&nbsp;&nbsp;&nbsp; R = 255;  
&nbsp;&nbsp;&nbsp; G = 255-j\*2 ;  
&nbsp;&nbsp;&nbsp; B = 255-i;  
&nbsp;&nbsp;&nbsp; A = 255-i\*2;  
&nbsp;&nbsp;&nbsp; if (mod((i\*j)/8,2))  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R = 255;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; G = 255;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B = 0;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A = 255;  
&nbsp;&nbsp;&nbsp; end  
&nbsp;&nbsp;&nbsp; pTexData(i,j,1)= R;  
&nbsp;&nbsp;&nbsp; pTexData(i,j,2)= G;  
&nbsp;&nbsp;&nbsp; pTexData(i,j,3)= B;  
end  
end  
pTexData = uint8(pTexData);  
imagesc (pTexData); figure(gcf)_
  

&nbsp;

---

<div class="post-metadata">

**Author:** ![martin-kraus](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@martin-kraus](https://forums.imgtec.com/u/martin-kraus)\
**Post date:** [October 23, 2010, 4:26pm UTC](https://forums.imgtec.com/t/texture-in-the-trainingcourse-4/877/2 "2010-10-23T16:26:28Z")

</div>

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, (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.

---

<div class="post-metadata">

**Author:** ![cgp](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@cgp](https://forums.imgtec.com/u/cgp)\
**Post date:** [July 1, 2011, 2:05am UTC](https://forums.imgtec.com/t/texture-in-the-trainingcourse-4/877/3 "2011-07-01T02:05:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [July 1, 2011, 7:42am UTC](https://forums.imgtec.com/t/texture-in-the-trainingcourse-4/877/4 "2011-07-01T07:42:04Z")

</div>

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
