Results 1 to 2 of 2

Thread: How to draw 2 bezier curves on the same screen?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2005
    Posts
    2

    How to draw 2 bezier curves on the same screen?

    Hello,

    I ve actually a small pb to draw 2 bezier curves on a single window.

    This is the code (sorry for french description):
    Code :
    // Point de controle présent en dur
    GLfloat ctrlpoints[6][3] = {
       { 2.f, 2.f, 0.f}, { 4.f, 4.f, 0.f},
       {6.f, 2.f, 0.f}, {7.f, 7.f, 0.f},
       {11.f, 4.f, 0.f}, {7.f, 10.f, 0.f}
    };
     
    /*---------------------------------------------------------------*/
    /*   Partie 1, continuité C1 pour une courbe de bezier de degré 2 */
    /*    le degré de liberté est de 1                         */
    /*---------------------------------------------------------------*/
     
    GLfloat pC1[3];
     
    // On calcul le point c1 pour avoir une continuité C1 entre les 2 courbes
    // On applique la formule c1 = c0 + b3 - b2
    // en sachant que c0 = b3
    GLfloat DonnePoint(GLfloat b2, GLfloat c0){
     
       return (2*c0-b2);
    }
     
    // Le but ici est d'initialiser les points de controles
    // et d'initialiser les différentes courbes de bezier
    // de façon à ce qu'elles soient de continuité C1   
     
    void display1(void)
    {
       int i;
       //Initialisation du tableau de points à (0,0, 0)
       GLfloat points[11][3]={{0},{0},{0}};
     
       //
       // Courbe 1
       //
     
       // Point 1 (qui est en dur)
       for (i=0; i!=3; i++)
             points[0][i]=ctrlpoints[0][i];
     
     
       // Point 2 (qui est celui demandé)
       for (i=0; i!=3; i++)
             points[1][i]=pC1[i];
     
     
       //Point 3 (qui est en dur)
       for (i=0; i!=3; i++)
             points[2][i]=ctrlpoints[1][i];
     
       //
       // Courbe 2
       // le dernier point de la courbe 1 etant le premier point de la courbe 2
     
       // Point 4 (qui est calculé)
       for (i=0; i!=3; i++)
             points[3][i]=DonnePoint(points[1][i], points[2][i]);
     
     
       //Point 5 (qui est en dur)
       for (i=0; i!=3; i++)
             points[4][i]=ctrlpoints[2][i];
     
     
       glClearColor(0.0, 0.0, 0.0, 0.0);
       glShadeModel(GL_FLAT);
       glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 3, &points[0][0]); 
       glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 3, &points[2][0]); 
       glEnable(GL_MAP1_VERTEX_3);
       glEnable(GL_MAP1_VERTEX_3);
     
       glClear(GL_COLOR_BUFFER_BIT);
       glColor3f(1.0, 1.0, 1.0);
     
      glBegin(GL_LINE_STRIP);
             for (i = 0; i <= 30; i++)
                glEvalCoord1f((GLfloat) i/30.0);
       glEnd();
     
     
       // On trace les points que nous avons à la base
       glPointSize(5.0);
       glColor3f(1.0, 1.0, 0.0);
       glBegin(GL_POINTS);
             for (i = 0; i < 6; i++)
             glVertex3fv(&amp;ctrlpoints[i][0]);
       glEnd();
     
       // On trace les points calculé
       glPointSize(5.0);
       glColor3f(1.0, 0.0, 1.0);
       glBegin(GL_POINTS);
             glVertex3fv(&amp;points[1][0]);
          glVertex3fv(&amp;points[3][0]);
       glEnd();
     
       glutSwapBuffers();
    }
    I understand that the probleme is with glEnable(GL_MAP1_VERTEX_3); because i ve only the second curve.

    My goal is to draw 2 bezier curves ( final point of the first curve is the first point of the second curve), with a continuity C1.

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2005
    Posts
    2

    Re: How to draw 2 bezier curves on the same screen?

    I finally found the solution:
    i only need to do a glEvalCoord1f() after each definition of glMap1f ^^

Similar Threads

  1. Trouble using tessellation to draw cubic Bézier curves
    By ehoops in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-02-2016, 02:20 PM
  2. convert four interconnected bezier curves into bezier surface patch
    By pat1il in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 07-08-2015, 09:33 AM
  3. How do I draw multiple bezier curves??
    By sdyajian in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-08-2007, 07:07 AM
  4. Bezier Curves
    By Mungo in forum OpenGL: General
    Replies: 6
    Last Post: 04-23-2004, 08:27 AM
  5. Bezier Curves
    By Selva in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 11-05-2001, 07:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean