1. for (int i = 0; i < 64; i++)  
  2.     {  
  3. for (int j = 0; j < 64; j++)  
  4.         {  
  5.             GLubyte c = (((i & 0x8) == 0) ^ ((j & 0x8) == 0) )*255;  
  6.             imageRBG[i][j][0] = imageRBG[i][j][1] = imageRBG[i][j][2] = c;  
  7.         }  
  8.     }  

GLubyte就是unsigned char  ,一个字节=八位

就是口口口口口口口口 (这里就是纯粹的口鼻的口)

看一下255对应就是11111111就是FF;

两个循环知道是64*64像素

(i & 0x8) == 0  这里判断是不是 大于等于8的奇数倍且小于8的偶数倍?是为1,否则为0 

1^1=0

0^0=0

1^0=1

0^1=1 

上面四个就是异或(没有进位的加)

1*255=FF                           黑色FF FF FF

0*255=00                           白色00 00 00

当i=0时,显然j=0-7涂白色,接着8-15涂黑色,白色,黑色……

……

当i=8时,显然j=0-7涂黑色,接着8-15图白色,黑色,白色……

……

以上就正好形成一个64*64但看到的是8*8的黑白棋盘,如图所示的一个面就是

解读OpenGL棋盘纹理贴图_解读

在我们弄的纹理里面,图的四个角是这样的坐标。

(0,1)(1,1)

(0,0)(1,0)    

然后用三角片画的一个正方形是有两个三角片构成。

b---c

| / |

a---d

上面贴的图三角形abc-00-01-11  三角形acd-00-11-10

normals[Index] = normal; points[Index] = vertices[a]; tex_coords[Index] = vec2(0.0, 0.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[b]; tex_coords[Index] = vec2(0.0, 1.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[c]; tex_coords[Index] = vec2(1.0, 1.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[a]; tex_coords[Index] = vec2(0.0, 0.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[c]; tex_coords[Index] = vec2(1.0, 1.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[d]; tex_coords[Index] = vec2(1.0, 0.0); Index++;新增或有更改


另一个有贴不一样的,三角形abc-00-11-01  三角形acd-00-11-01(明显前一个三角形贴图是扭曲过的)
normals[Index] = normal; points[Index] = vertices[a]; tex_coords[Index] = vec2(0.0, 0.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[b]; tex_coords[Index] = vec2(1.0, 1.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[c]; tex_coords[Index] = vec2(0.0, 1.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[a]; tex_coords[Index] = vec2(0.0, 0.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[c]; tex_coords[Index] = vec2(1.0, 1.0); Index++;新增或有更改
normals[Index] = normal; points[Index] = vertices[d]; tex_coords[Index] = vec2(0.0, 1.0); Index++;新增或有更改

下面图片是旋转等变换以后截的图

解读OpenGL棋盘纹理贴图_i++_02