Results 1 to 2 of 2

Thread: Draw multiples lines with glVertex3f

  1. #1
    Junior Member Newbie pelaoqlo's Avatar
    Join Date
    Aug 2018
    Posts
    12

    Question Draw multiples lines with glVertex3f

    Hi everyone! I need your help

    Im trying to draw multiples lines with glBegin(GL_LINE_STRIP); right?
    For this, i have 2 class
    1.
    Code :
    Class1::Class1(float x, float y, float z)
        {
            xS  = x;    /* xS is a float */
            yS  = y;    /* yS is a float *
            zS  = z;    /* zS is a float *
        }
    2.
    Code :
    Class2::Class2(float x1, float y1, float z1)
        {
            xT  = x1;    /* xT is a float */
            yT  = y1;    /* yT is a float *
            zT  = z1;    /* zT is a float *
        }
    Two class have getter and setter methods.
    And i have 2 QVector
    Code :
    1. QVector<Class1*> clas1Vector;  /* any object in the vector contain 3 values: x, y, z*/
    1. QVector<Class2*> clas2Vector; /* any object in the vector contain 3 values: x1, y1, z1*/
    and i have 2 iterator, obviously:
    Code :
    1.
    QVector<Class1*>::iterator is;
               for (is = clas1Vector.begin(); is != clas1Vector.end(); ++is)
               {
                   x = (*is)->getXS();
                   y = (*is)->getYS();
                   z = (*is)->getZS();
               }
     
    2.
    QVector<Class2*>::iterator it;
               for (it = clas2Vector.begin(); it != clas2Vector.end(); ++it)
               {
                   x2 = (*it)->getXT();
                   y2 = (*it)->getYT();
                   z2 = (*it)->getZT();
               }
    okay, now its my question: How can i draw lines with glBegin(GL_LINE_STRIP); without deleting or replacing the previous line? That is, when drawing a new line, the previous one do not erase.
    Actually draw the lines so:
    Code :
    glBegin(GL_LINE_STRIP);   
    glColor3f(0.0f, 1.0f, 0.0f);     // Green
    glVertex3f( x, y, z);
    glVertex3f( x2, y2, z2);
    glEnd();

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650
    Quote Originally Posted by pelaoqlo View Post
    okay, now its my question: How can i draw lines with glBegin(GL_LINE_STRIP); without deleting or replacing the previous line?
    Each frame: 1) clear the screen, and 2) draw two line strips instead of one.

    Since you're using the oold "immediate mode" way of registering vertices with OpenGL, put your glBegin()..glEnd() block in a loop and parameterize the vertex positions being registered for each line based on the loop index. Alternatively, copy/paste this block and change the vertex positions sent for the 2nd line.

    Also, all the code you posted related to your C++ classes is not relevant to your question.

Tags for this Thread

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