textured-torus.c
// Most of init is copied verbatim from checker.c. In addition
// there is a loop to fill the vertex and texture co-ordinates array.

Most of init is copied verbatim from checker.c. In addition
there is a loop to fill the vertex and texture co-ordinates array.
Most of init is copied verbatim from checker . c . In addition there is a loop to fill the vertex and texture co - ordinates array .
void init (void) 
{
  int i, j, k, l;
  glClearColor (0.0, 0.0, 0.0, 0.0);
  glShadeModel(GL_FLAT);
  glEnable(GL_DEPTH_TEST);
   makeCheckImage();
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
#ifdef GL_VERSION_1_1
   glGenTextures(1, &texName);
   glBindTexture(GL_TEXTURE_2D, texName);
#endif
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
#ifdef GL_VERSION_1_1
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 
                0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#else
   glTexImage2D(GL_TEXTURE_2D, 0, 4, checkImageWidth, checkImageHeight, 
                0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#endif
  k = 0;
  l = 0;
  for (j = 0; j <= N; j++)
    for (i = 0; i <= M; i++){
      vdata[k++] = FNX(i,j); 
      vdata[k++] = FNY(i,j);
      vdata[k++] = FNZ(i,j); 
      texdata[l++] = (GLfloat) i/M;
      texdata[l++] = (GLfloat) j/N;
	}  
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glVertexPointer(3, GL_FLOAT, 0, vdata);
  glTexCoordPointer(2, GL_FLOAT, 0, texdata);
}
void init ( void ) { int i , j , k , l ; glClearColor ( 0.0 , 0.0 , 0.0 , 0.0 ) ; glShadeModel ( GL_FLAT ) ; glEnable ( GL_DEPTH_TEST ) ; makeCheckImage ( ) ; glPixelStorei ( GL_UNPACK_ALIGNMENT , 1 ) ; #ifdef GL_VERSION_1_1 glGenTextures ( 1 , & texName ) ; glBindTexture ( GL_TEXTURE_2D , texName ) ; #endif glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_REPEAT ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_REPEAT ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; #ifdef GL_VERSION_1_1 glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , checkImageWidth , checkImageHeight , 0 , GL_RGBA , GL_UNSIGNED_BYTE , checkImage ) ; #else glTexImage2D ( GL_TEXTURE_2D , 0 , 4 , checkImageWidth , checkImageHeight , 0 , GL_RGBA , GL_UNSIGNED_BYTE , checkImage ) ; #endif k = 0 ; l = 0 ; for ( j = 0 ; j <= N ; j ++ ) for ( i = 0 ; i <= M ; i ++ ) { vdata [ k ++ ] = FNX ( i , j ) ; vdata [ k ++ ] = FNY ( i , j ) ; vdata [ k ++ ] = FNZ ( i , j ) ; texdata [ l ++ ] = ( GLfloat ) i / M ; texdata [ l ++ ] = ( GLfloat ) j / N ; } glEnableClientState ( GL_VERTEX_ARRAY ) ; glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; glVertexPointer ( 3 , GL_FLOAT , 0 , vdata ) ; glTexCoordPointer ( 2 , GL_FLOAT , 0 , texdata ) ; }
Most of init is copied verbatim from checker.c.
Most of init is copied verbatim from checker . c .
/* The vertex array is filled. */ /* Filling the texture co-ordinates array:
       * The parameter space is a unit square with corners at (0,0) and (1,1)
       * so that the both the parameter space x and y co-ordinates run from 
       * 0 to 1. But this is *identical* to s and t co-ordinate ranges for the 
       * texture object. So we simply provide the grid point (s,t) in the 
       * parameter space (or more accurately the torus point to which it is 
       * mapped) the texture co-ordinates (s,t) as well.
       */