Esempio n. 1
0
static void tetrahedron(GLdouble p0[3], GLdouble radius, GLenum shadeType)
{
    int i;

    for (i = 0; i < 4; i++)
        drawtriangle(i, 2, 1, p0, radius, shadeType, 0);
}
Esempio n. 2
0
void myDisplay(void)
{
	// 清除。GL_COLOR_BUFFER_BIT表示清除颜色
	/*
	在RGB模式下,使用glClearColor来指定“空”的颜色,它需要四个参数,其参数的意义跟glColor4f相似。
	在索引颜色模式下,使用glClearIndex来指定“空”的颜色所在的索引,它需要一个参数,其意义跟glIndexi相似。
	*/
	glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
	glClear(GL_COLOR_BUFFER_BIT);

	drawrect();

	drawpoint();

	drawline();

	drawpolygon();
	
	draw5star();

	drawsin();

	drawtriangle();

	//保证前面的OpenGL命令立即执行(而不是让它们在缓冲区中等待)。其作用跟fflush(stdout)类似。
	glFlush();

}
static void
tetrahedron(GLenum shadeType)
{
  int i;

  for (i = 3; i >= 0; i--)
    drawtriangle(i, tdata, tndex, shadeType);
}
static void
icosahedron(GLenum shadeType)
{
  int i;

  for (i = 19; i >= 0; i--) {
    drawtriangle(i, idata, index, shadeType);
  }
}
static void
octahedron(GLenum shadeType)
{
  int i;

  for (i = 7; i >= 0; i--) {
    drawtriangle(i, odata, ondex, shadeType);
  }
}
Esempio n. 6
0
void icosadraw(float xyzr[4])
{

  /*  This routine draws a Gouraud shade icosahedron.  */

  int i;

   xoff = xyzr[0];  yoff = xyzr[1];  zoff = xyzr[2];
   radius = xyzr[3];

   /*  Draw the icosahedron.  */
   for (i = 0; i < 20; i++)
     {
      drawtriangle(&vdata[tindices[i][0]][0],
                   &vdata[tindices[i][1]][0],
                   &vdata[tindices[i][2]][0]);
     }
}
Esempio n. 7
0
void subdivide(float *v1, float *v2, float *v3, int depth)
{
  float v12[3], v23[3], v31[3], d;
  int i;
  void drawtrinagle(float *v1, float *v2, float *v3);

   /*  Draw this triangle when depth is zero.  */
   if (depth == 0)
     {
      drawtriangle(v1,v2,v3);
      return;
     }

   /*  Normalize the midpoints of each triangle side.  */
   for (i = 0; i < 3; i++)
     {
      v12[i] = v1[i] + (v2[i]-v1[i])/2.;
      v23[i] = v2[i] + (v3[i]-v2[i])/2.;
      v31[i] = v3[i] + (v1[i]-v3[i])/2.;
     }
   d = sqrt(v12[0]*v12[0] + v12[1]*v12[1] + v12[2]*v12[2]);
   if (d > 0.0)
     { v12[0] /= d; v12[1] /= d; v12[2] /= d; }
   d = sqrt(v23[0]*v23[0] + v23[1]*v23[1] + v23[2]*v23[2]);
   if (d > 0.0)
     { v23[0] /= d; v23[1] /= d; v23[2] /= d; }
   d = sqrt(v31[0]*v31[0] + v31[1]*v31[1] + v31[2]*v31[2]);
   if (d > 0.0)
     { v31[0] /= d; v31[1] /= d; v31[2] /= d; }

   /*  Recursively subdivide the new triangles.  */
   subdivide(v1,v12,v31,depth-1);
   subdivide(v2,v23,v12,depth-1);
   subdivide(v3,v31,v23,depth-1);
   subdivide(v12,v23,v31,depth-1);
}