Exemplo n.º 1
0
void drawCurves(GLenum mode) {
	/* Draw the curves */
	glColor3f(0,0,0);
	for(int i=0; i<OUTER_CPTS-3; i +=3) {
		if (mode == GL_SELECT) {
			glLoadName(i);
		}
		/* Draw the outer curve using OpenGL evaluators */
		glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, cpts[i]);
		glMapGrid1f(30, 0.0, 1.0);
		glEvalMesh1(GL_LINE, 0, 30);
	}
	
	for(int i=0; i<INNER_CPTS-3; i +=3) {
		if (mode == GL_SELECT) {
			glLoadName(i+OUTER_CPTS);
		}
		/* Draw the inner curve using OpenGL evaluators */
		glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, cpts[OUTER_CPTS+i]);
		glMapGrid1f(30, 0.0, 1.0);
		glEvalMesh1(GL_LINE, 0, 30);
	}
	
	glFlush();
}
Exemplo n.º 2
0
void drawCurves() {
	int 		i;
	GLfloat gain;
	
	/* Draw the curves */
	glColor3f(0,0,0);
	for(i=0; i<OUTER_CPTS-3; i +=3) {
		/* Draw the outer curve using OpenGL evaluators */
		glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, cpts[i]);
		glMapGrid1f(30, 0.0, 1.0);
		glEvalMesh1(GL_LINE, 0, 30);
	}
	
	for(i=0; i<INNER_CPTS-3; i +=3) {
		/* Draw the inner curve using OpenGL evaluators */
		glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, cpts[OUTER_CPTS+i]);
		glMapGrid1f(30, 0.0, 1.0);
		glEvalMesh1(GL_LINE, 0, 30);
	}
	
	glFlush();
	
	// determin gain
	for(i=0;i<ncpts;i++){
		cpts[i][0]=(-16.0+cpts[i][0])/20.0;
		cpts[i][1]=(-16.0+cpts[i][1])/20.0;
		cpts[i][2]=cpts[i][2];
		//printf("\n %d %f %f",i,cpts[i][0],cpts[i][1]);
	}
}
Exemplo n.º 3
0
void RenderScene()
{
  glClear(GL_COLOR_BUFFER_BIT);
  
  //设置贝塞尔曲线,这个函数其实只需要调用一次,可以放在SetupRC中设置
  glMap1f(GL_MAP1_VERTEX_3, //生成的数据类型
    0.0f, //u值的下界
    100.0f, //u值的上界
    3, //顶点在数据中的间隔,x,y,z所以间隔是3
    numOfPoints, //u方向上的阶,即控制点的个数
    &controlPoints[0][0] //指向控制点数据的指针
  );

  //必须在绘制顶点之前开启
  glEnable(GL_MAP1_VERTEX_3);
  //使用画线的方式来连接点
  /*glBegin(GL_LINE_STRIP);
  for (int i = 0; i <= 100; i++)
  {
    glEvalCoord1f((GLfloat)i);
  }
  glEnd();*/

  glMapGrid1f(100, 0.0f, 100.0f);

  glEvalMesh1(GL_LINE, 0, 100);
  DrawPoints();

  glutSwapBuffers();

}
Exemplo n.º 4
0
void tglDraw(const TCubic &cubic, int precision, GLenum pointOrLine)
{
	CHECK_ERRORS_BY_GL;
	assert(pointOrLine == GL_POINT || pointOrLine == GL_LINE);
	float(*ctrlPts)[3];
	ctrlPts = new float[4][3];

	ctrlPts[0][0] = cubic.getP0().x;
	ctrlPts[0][1] = cubic.getP0().y;
	ctrlPts[0][2] = 0.0;

	ctrlPts[1][0] = cubic.getP1().x;
	ctrlPts[1][1] = cubic.getP1().y;
	ctrlPts[1][2] = 0.0;

	ctrlPts[2][0] = cubic.getP2().x;
	ctrlPts[2][1] = cubic.getP2().y;
	ctrlPts[2][2] = 0.0;

	ctrlPts[3][0] = cubic.getP3().x;
	ctrlPts[3][1] = cubic.getP3().y;
	ctrlPts[3][2] = 0.0;

	CHECK_ERRORS_BY_GL;
	glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlPts[0][0]);
	CHECK_ERRORS_BY_GL;
	glEnable(GL_MAP1_VERTEX_3);
	CHECK_ERRORS_BY_GL;
	glMapGrid1f(precision, 0.0, 1.0);
	CHECK_ERRORS_BY_GL;
	glEvalMesh1(pointOrLine, 0, precision);
	CHECK_ERRORS_BY_GL;

	delete[] ctrlPts;
}
Exemplo n.º 5
0
Arquivo: g_render.c Projeto: aosm/X11
void __glXDisp_EvalMesh1(GLbyte *pc)
{
	glEvalMesh1( 
		*(GLenum   *)(pc + 0),
		*(GLint    *)(pc + 4),
		*(GLint    *)(pc + 8)
	);
}
Exemplo n.º 6
0
static void hugsprim_glEvalMesh1_19(HugsStackPtr hugs_root)
{
    HsWord32 arg1;
    HsInt32 arg2;
    HsInt32 arg3;
    arg1 = hugs->getWord32();
    arg2 = hugs->getInt32();
    arg3 = hugs->getInt32();
    glEvalMesh1(arg1, arg2, arg3);
    
    hugs->returnIO(hugs_root,0);
}
Exemplo n.º 7
0
void drawCurves()
{
    int i;
    for(i=0; i<numberOfBezierCurve; i++)
    {
        /* draw the curve using OpenGL evaluators */
        glColor3f(BC[i].color[0], BC[i].color[1], BC[i].color[2]);
        glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, BC[i].cpts[0]);
        glMapGrid1f(30, 0.0, 1.0);
        glEvalMesh1(GL_LINE, 0, 30);
    }
    glFlush();
}
Exemplo n.º 8
0
void Bezier()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glLineWidth(5);
    float PuntosdeControl[7][3] = {
        {411.0,posy(249.0),0.0},
        {505.0,posy(274.0),0.0},
        {597.0,posy(239.0),0.0},
        {620.0,posy(137.0),0.0},
        {518.0,posy(84.0),0.0},
        {414.0,posy(150.0),0.0},
        {412.0,posy(248.0),0.0}
    };
    
    glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,7,*PuntosdeControl);
    glEnable(GL_MAP1_VERTEX_3);
    glMapGrid1f(100,0.0,1.0);
    glColor3f(1,0,0);
    glEvalMesh1(GL_LINE,0,100);
    glDisable(GL_MAP1_VERTEX_3);
    
    glFlush();
}
Exemplo n.º 9
0
static void
RenderEval(void)
{

  if (colorType) {
    glEnable(GL_MAP1_COLOR_4);
    glEnable(GL_MAP2_COLOR_4);
  } else {
    glDisable(GL_MAP1_COLOR_4);
    glDisable(GL_MAP2_COLOR_4);
  }

  if (textureType) {
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_MAP2_TEXTURE_COORD_2);
  } else {
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_MAP2_TEXTURE_COORD_2);
  }

  if (polygonFilled) {
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  } else {
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  }

  glShadeModel(GL_SMOOTH);

  switch (mapType) {
  case EVAL:
    switch (arrayType) {
    case ONE_D:
      glDisable(GL_MAP2_VERTEX_4);
      glEnable(GL_MAP1_VERTEX_4);
      DrawPoints1();
      DrawMapEval1(0.1 / VORDER);
      break;
    case TWO_D:
      glDisable(GL_MAP1_VERTEX_4);
      glEnable(GL_MAP2_VERTEX_4);
      DrawPoints2();
      DrawMapEval2(0.1 / VMAJOR_ORDER, 0.1 / VMINOR_ORDER);
      break;
    }
    break;
  case MESH:
    switch (arrayType) {
    case ONE_D:
      DrawPoints1();
      glDisable(GL_MAP2_VERTEX_4);
      glEnable(GL_MAP1_VERTEX_4);
      glColor3f(0.0, 0.0, 1.0);
      glMapGrid1d(40, 0.0, 1.0);
      if (mapPoint) {
        glPointSize(2);
        glEvalMesh1(GL_POINT, 0, 40);
      } else {
        glEvalMesh1(GL_LINE, 0, 40);
      }
      break;
    case TWO_D:
      DrawPoints2();
      glDisable(GL_MAP1_VERTEX_4);
      glEnable(GL_MAP2_VERTEX_4);
      glColor3f(0.0, 0.0, 1.0);
      glMapGrid2d(20, 0.0, 1.0, 20, 0.0, 1.0);
      if (mapPoint) {
        glPointSize(2);
        glEvalMesh2(GL_POINT, 0, 20, 0, 20);
      } else if (polygonFilled) {
        glEvalMesh2(GL_FILL, 0, 20, 0, 20);
      } else {
        glEvalMesh2(GL_LINE, 0, 20, 0, 20);
      }
      break;
    }
    break;
  }
}
Exemplo n.º 10
0
static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
{
  int i;

  if (mode == CD_CLIP)
    return;

  if (mode == CD_BEZIER)
  {
    int i, prec = 100;
    double (*points)[3] = malloc(n * sizeof(*points));

    for(i = 0; i < n; i++)
    {
      points[i][0] = poly[i].x;
      points[i][1] = poly[i].y;
      points[i][2] = 0;
    }

    glMap1d(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, n, &points[0][0]);
    glEnable(GL_MAP1_VERTEX_3);
    glMapGrid1d(prec, 0.0, 1.0);
    glEvalMesh1(GL_LINE, 0, prec);
    glDisable(GL_MAP1_VERTEX_3);

    free(points);
    return;
  }

  if (mode == CD_PATH)
  {
    cdfSimPolyPath(ctxcanvas->canvas, poly, n);
    return;
  }

  switch (mode)
  {
  case CD_CLOSED_LINES :
    glBegin(GL_LINE_LOOP);
    break;
  case CD_OPEN_LINES :
    glBegin(GL_LINE_STRIP);
    break;
  case CD_FILL :
    if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE))
    {
      glDisable(GL_POLYGON_STIPPLE);
      glColor4ub(cdRed(ctxcanvas->canvas->background), 
                 cdGreen(ctxcanvas->canvas->background), 
                 cdBlue(ctxcanvas->canvas->background), 
                 cdAlpha(ctxcanvas->canvas->background));

      glBegin(GL_POLYGON);
      for(i = 0; i < n; i++)
        glVertex2d(poly[i].x, poly[i].y);
      glEnd();

      /* restore the foreground color */
      glColor4ub(cdRed(ctxcanvas->canvas->foreground), 
                 cdGreen(ctxcanvas->canvas->foreground), 
                 cdBlue(ctxcanvas->canvas->foreground), 
                 cdAlpha(ctxcanvas->canvas->foreground));
      glEnable(GL_POLYGON_STIPPLE);
    }

    glBegin(GL_POLYGON);
    break;
  }

  for(i = 0; i < n; i++)
    glVertex2d(poly[i].x, poly[i].y);
  glEnd();

  (void)ctxcanvas;
}
Exemplo n.º 11
0
static void
RenderEval(void)
{

  if (colorType) {
    glEnable(GL_MAP1_COLOR_4);
    glEnable(GL_MAP2_COLOR_4);
  } else {
    glDisable(GL_MAP1_COLOR_4);
    glDisable(GL_MAP2_COLOR_4);
  }

  if (textureType) {
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_MAP2_TEXTURE_COORD_2);
  } else {
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_MAP2_TEXTURE_COORD_2);
  }

  if (polygonFilled) {
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  } else {
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  }

  glShadeModel(GL_SMOOTH);

  switch (mapType) {
  case EVAL:
    switch (arrayType) {
    case ONE_D:
      glDisable(GL_MAP2_VERTEX_4);
      glEnable(GL_MAP1_VERTEX_4);
      DrawPoints1();
      DrawMapEval1(0.1 / VORDER);
      break;
    case TWO_D:
      glDisable(GL_MAP1_VERTEX_4);
      glEnable(GL_MAP2_VERTEX_4);
      DrawPoints2();
      DrawMapEval2(0.1 / VMAJOR_ORDER, 0.1 / VMINOR_ORDER);
      break;
    }
    break;
  case MESH:
    switch (arrayType) {
    case ONE_D:
      DrawPoints1();
      glDisable(GL_MAP2_VERTEX_4);
      glEnable(GL_MAP1_VERTEX_4);
      glColor3f(0.0, 0.0, 1.0);
      glMapGrid1d(40, 0.0, 1.0);
      if (mapPoint) {
        glPointSize(2);
        glEvalMesh1(GL_POINT, 0, 40);
      } else {
        glEvalMesh1(GL_LINE, 0, 40);
      }
      break;
    case TWO_D:
      DrawPoints2();
      glDisable(GL_MAP1_VERTEX_4);
      glEnable(GL_MAP2_VERTEX_4);
      glColor3f(0.0, 0.0, 1.0);
      glMapGrid2d(20, 0.0, 1.0, 20, 0.0, 1.0);
      if (mapPoint) {
        glPointSize(2);
        glEvalMesh2(GL_POINT, 0, 20, 0, 20);
      } else if (polygonFilled) {
        glEvalMesh2(GL_FILL, 0, 20, 0, 20);
      } else {
        glEvalMesh2(GL_LINE, 0, 20, 0, 20);
      }
      break;
    default:;
      /* Mesa makes GLenum be a C "enum" and gcc will warn if
         all the cases of an enum are not tested in a switch
         statement.  Add default case to supress the error. */
    }
    break;
  }
}
Exemplo n.º 12
0
/////////////////////////////////////////////////////////
// Render
//
void GEMglEvalMesh1 :: render(GemState *state)
{
  glEvalMesh1 (mode, i1, i2);
}
Exemplo n.º 13
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   int k,i;
   Point S[NMAX];

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT);
   //  Enable vertex generation
   glEnable(GL_MAP1_VERTEX_3);

   //  Draw and label points
   glColor3f(1,1,1);
   glPointSize(5);
   glBegin(GL_POINTS);
   for (k=0;k<n;k++)
      glVertex2f(P[k].x,P[k].y);
   glEnd();
   for (k=0;k<n;k++)
   {
      glRasterPos2d(P[k].x,P[k].y);
      Print("P%d",k);
   }
   //  Draw curve when we have enough points
   switch (mode)
   {
      //  Continuous Bezier
      case 0:
         for (k=0;k<n-3;k+=3)
         {
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)(P+k));
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
         }
         break;
      //  Smooth Bezier
      case 1:
         //  First four
         if (n>=4)
         {
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)P);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
         }
         //  Subsequent triples
         for (k=3;k<n-2;k+=2)
         {
            Point r[4];
            //  P0, P2 and P3 are specified points
            r[0] = P[k];
            r[2] = P[k+1];
            r[3] = P[k+2];
            //  P1 is computed by reflecting P2 from previous segment
            r[1].x = 2*P[k].x-P[k-1].x;
            r[1].y = 2*P[k].y-P[k-1].y;
            r[1].z = 2*P[k].z-P[k-1].z;
            //  Draw curve
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)r);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
            //  Draw reflected point in red
            glColor3f(1,0,0);
            glBegin(GL_POINTS);
            glVertex2f(r[1].x,r[1].y);
            glEnd();
            glRasterPos2d(r[1].x,r[1].y);Print("R%d",k-1);
         }
         break;
      //  Interpolate 4 at a time
      case 2:
         for (k=0;k<n-3;k+=3)
         {
            Point r[4];
            //  Transform 4 data points to 4 control points
            Pmult(Mi,P+k,r);
            //  Draw curve
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)r);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
            //  Draw control points
            glColor3f(1,0,0);
            glBegin(GL_POINTS);
            glVertex2f(r[1].x,r[1].y);
            glVertex2f(r[2].x,r[2].y);
            glEnd();
            glRasterPos2d(r[1].x,r[1].y);Print("R%d",k+1);
            glRasterPos2d(r[2].x,r[2].y);Print("R%d",k+2);
         }
         break;
      //  B Spline 4 at a time
      case 3:
         for (k=0;k<n-3;k++)
         {
            int j;
            Point r[4];
            //  Transform 4 data points to 4 control points (note increment is 1)
            Pmult(Ms,P+k,r);
            //  Draw curve
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)r);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
            //  Draw control points
            glColor3f(1,0,0);
            glBegin(GL_POINTS);
            for (j=0;j<4;j++)
               glVertex2f(r[j].x,r[j].y);
            glEnd();
         }
         break;
      //  Cubic Natural Spline
      case 4:
         //  Calculate (x,y,z) splines
         CubicSpline((void*)P,(void*)S,0,n);
         CubicSpline((void*)P,(void*)S,1,n);
         CubicSpline((void*)P,(void*)S,2,n);
         //  Draw entire curve
         glColor3f(1,1,0);
         glBegin(GL_LINE_STRIP);
         for (k=0;k<n-1;k++)
         {
            //  Cardinal point
            glVertex2d(P[k].x,P[k].y);
            //  Increment between k and k+1
            for (i=1;i<m;i++)
            {
               double f  = (double)i/m;
               double g  = 1-f;
               double f2 = (f*f*f-f)/6;
               double g2 = (g*g*g-g)/6;
               double x  = f*P[k+1].x + g*P[k].x + f2*S[k+1].x + g2*S[k].x;
               double y  = f*P[k+1].y + g*P[k].y + f2*S[k+1].y + g2*S[k].y;
               double z  = f*P[k+1].z + g*P[k].z + f2*S[k+1].z + g2*S[k].z;
               glVertex3d(x,y,z);
            }
         }
         //  Last cardinal point
         glVertex2d(P[n-1].x,P[n-1].y);
         glEnd();
         break;
      default:
         break;
   }
   
   //  Display parameters
   glColor3f(1,1,1);
   glWindowPos2i(5,5);
   Print(text[mode]);
   if (n<NMAX)
      Print(" Click to add point\n");
   else
      Print(" Click to start new curve\n");

   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
Exemplo n.º 14
0
M(void, glEvalMesh1, jint mode, jint i1, jint i2) {
	glEvalMesh1(mode, i1, i2);
}