Exemplo n.º 1
0
static void
Init(void)
{
  static float ambient[] =
  {0.1, 0.1, 0.1, 1.0};
  static float diffuse[] =
  {1.0, 1.0, 1.0, 1.0};
  static float position[] =
  {0.0, 0.0, -150.0, 0.0};
  static float front_mat_diffuse[] =
  {1.0, 0.2, 1.0, 1.0};
  static float back_mat_diffuse[] =
  {1.0, 1.0, 0.2, 1.0};
  static float lmodel_ambient[] =
  {1.0, 1.0, 1.0, 1.0};
  static float lmodel_twoside[] =
  {GL_TRUE};
  static float decal[] =
  {GL_DECAL};
  static float repeat[] =
  {GL_REPEAT};
  static float nr[] =
  {GL_NEAREST};

  glFrontFace(GL_CCW);

  glEnable(GL_DEPTH_TEST);

  glMap1d(GL_MAP1_VERTEX_4, 0.0, 1.0, VDIM, VORDER, point1);
  glMap1d(GL_MAP1_COLOR_4, 0.0, 1.0, CDIM, CORDER, cpoint1);

  glMap2d(GL_MAP2_VERTEX_4, 0.0, 1.0, VMINOR_ORDER * VDIM, VMAJOR_ORDER, 0.0,
    1.0, VDIM, VMINOR_ORDER, point2);
  glMap2d(GL_MAP2_COLOR_4, 0.0, 1.0, CMINOR_ORDER * CDIM, CMAJOR_ORDER, 0.0,
    1.0, CDIM, CMINOR_ORDER, cpoint2);
  glMap2d(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, TMINOR_ORDER * TDIM,
    TMAJOR_ORDER, 0.0, 1.0, TDIM, TMINOR_ORDER, tpoint2);

  glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, position);

  glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
  glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);

  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);

  glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal);
  glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat);
  glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat);
  glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nr);
  glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nr);
  glTexImage2D(GL_TEXTURE_2D, 0, 4, 2, 4, 0, GL_RGBA, GL_FLOAT,
    (GLvoid *) textureImage);
}
Exemplo n.º 2
0
GLvoid display()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotated(orientation_angle, orientation_axis[0], orientation_axis[1], orientation_axis[2]);
    glTranslated(0.0, 0.0, -5.0);
    glRotated(location_angle, location_axis[0], location_axis[1], location_axis[2]);
    glTranslated(0.0, 0.0, 0.0);

    glColor3f(1.0, 1.0, 1.0);
    glMap1d(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);
    glBegin(GL_LINE_STRIP);
    for (GLint i = 0; i <= 30; i++)
        glEvalCoord1f((GLdouble) i/30.0);
    glEnd();
    glMap1d(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[3][0]);
    glBegin(GL_LINE_STRIP);
    for (GLint j = 0; j <= 30; j++)
        glEvalCoord1f((GLdouble) j/30.0);
    glEnd();

    /* The following code displays the control points as dots. */
    glPointSize(5.0);
    glBegin(GL_POINTS);
    if (-1 != selectedPointIndex)
    {
        glColor3f(0.0, 1.0, 1.0);
        glVertex3dv(&ctrlpoints[selectedPointIndex][0]);
    }
    glColor3f(1.0, 1.0, 0.0);
    for (GLint i = 0; i < 7; i++)
    {
        if (i != selectedPointIndex)
        {
            glVertex3dv(&ctrlpoints[i][0]);
        }
    }
    glEnd();
    glFlush();
}
Exemplo n.º 3
0
void
__glXDispSwap_Map1d(GLbyte * pc)
{
    GLint order, k, compsize;
    GLenum target;
    GLdouble u1, u2, *points;

    __GLX_DECLARE_SWAP_VARIABLES;
    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;

    __GLX_SWAP_DOUBLE(pc + 0);
    __GLX_SWAP_DOUBLE(pc + 8);
    __GLX_SWAP_INT(pc + 16);
    __GLX_SWAP_INT(pc + 20);

    target = *(GLenum *) (pc + 16);
    order = *(GLint *) (pc + 20);
    k = __glMap1d_size(target);
    if (order <= 0 || k < 0) {
        /* Erroneous command. */
        compsize = 0;
    }
    else {
        compsize = order * k;
    }
    __GLX_GET_DOUBLE(u1, pc);
    __GLX_GET_DOUBLE(u2, pc + 8);
    __GLX_SWAP_DOUBLE_ARRAY(pc + 24, compsize);
    pc += 24;

#ifdef __GLX_ALIGN64
    if (((unsigned long) pc) & 7) {
        /*
         ** Copy the doubles up 4 bytes, trashing the command but aligning
         ** the data in the process
         */
        __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
        points = (GLdouble *) (pc - 4);
    }
    else {
        points = (GLdouble *) pc;
    }
#else
    points = (GLdouble *) pc;
#endif
    glMap1d(target, u1, u2, k, order, points);
}
Exemplo n.º 4
0
void
__glXDisp_Map1d(GLbyte * pc)
{
    GLint order, k;

#ifdef __GLX_ALIGN64
    GLint compsize;
#endif
    GLenum target;
    GLdouble u1, u2, *points;

    target = *(GLenum *) (pc + 16);
    order = *(GLint *) (pc + 20);
    k = __glMap1d_size(target);

#ifdef __GLX_ALIGN64
    if (order < 0 || k < 0) {
        compsize = 0;
    }
    else {
        compsize = order * k;
    }
#endif

    __GLX_GET_DOUBLE(u1, pc);
    __GLX_GET_DOUBLE(u2, pc + 8);
    pc += 24;

#ifdef __GLX_ALIGN64
    if (((unsigned long) pc) & 7) {
        /*
         ** Copy the doubles up 4 bytes, trashing the command but aligning
         ** the data in the process
         */
        __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
        points = (GLdouble *) (pc - 4);
    }
    else {
        points = (GLdouble *) pc;
    }
#else
    points = (GLdouble *) pc;
#endif
    glMap1d(target, u1, u2, k, order, points);
}
Exemplo n.º 5
0
static void hugsprim_glMap1d_1(HugsStackPtr hugs_root)
{
    HsWord32 arg1;
    HsDouble arg2;
    HsDouble arg3;
    HsInt32 arg4;
    HsInt32 arg5;
    HsPtr arg6;
    arg1 = hugs->getWord32();
    arg2 = hugs->getDouble();
    arg3 = hugs->getDouble();
    arg4 = hugs->getInt32();
    arg5 = hugs->getInt32();
    arg6 = hugs->getPtr();
    glMap1d(arg1, arg2, arg3, arg4, arg5, arg6);
    
    hugs->returnIO(hugs_root,0);
}
Exemplo n.º 6
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.º 7
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.º 8
0
M(void, glMap1d, jint target, jdouble u1, jdouble u2, jint stride, jint order, jobject points) {
	glMap1d(target, u1, u2, stride, order, BUFF(GLdouble, points));
}