QOpenglWidget - Draw Points from a QList



  • Hi guys!
    I'm trying to draw points on a glwidget from a QList <Points>. My fuction to draw is like this:

    void GLWidget::drawGcode(QList<Points*> gcodeDots)
    {
        float x=0,y=0,z=0;
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        makeCurrent();
        for(unsigned int i=0;i<gcodeDots.size();i++)
        {   try{
                gcodeDots[i]->getPoint(&x,&y,&z);
            }catch(QString str)
            {
                qDebug() << i << ' ' <<QString(str);
            }
            glPushMatrix();
            glPointSize(0.2f);
            glColor3b(0,0,1);
            glBegin(GL_POINTS);
                glVertex3f(x,y,z);
            glEnd();
            glPopMatrix();
            glFlush();
    
        }
        doneCurrent();
        update();
    }
    

    But after that fill the QList with the necessary points and call the function through UI-> openglwidget-> drawGcode (gcodeDots);
    nothing happens. I've tried using update () and glFlush (), but nothing happens.
    I'm trying to make this application without using the lib glut. I even tried the functions of class OpenGLContext and OpenGLFunctions, but could not get nowhere.
    Can someone help me?


  • Qt Champions 2016

    @Lays147 said:

    void GLWidget::drawGcode(QList<Points*> gcodeDots)

    I have no idea why nothing is shown.
    Did you try GL_LINES just for test?

    But I do wonder if passing a
    Qlist like that (not ref & or pointer *) will make you a new (deep) copy
    of your QList ?
    Which is ok, but might not be what you meant.
    If you did that to get a copy, please just ignore this post :)

    void GLWidget::drawGcode ( QList<Points*> gcodeDots )
    {
    	float x = 0, y = 0, z = 0;
    	glMatrixMode ( GL_MODELVIEW );
    	glLoadIdentity();
    	makeCurrent();
    	for ( unsigned int i = 0; i < gcodeDots.size(); i++ ) {
    		try {
    			gcodeDots[i]->getPoint ( &x, &y, &z );
    		} catch ( QString str ) {
    			qDebug() << i << ' ' << QString ( str );
    		}
    		glPushMatrix();
    		glPointSize ( 0.2f );
    		glColor3b ( 0, 0, 1 );
    		glBegin ( GL_POINTS );
    		glVertex3f ( x, y, z );
    		glEnd();
    		glPopMatrix();
    		glFlush();
    	}
    	doneCurrent();
    	update();
    }
    


  • With this code i have a result, a one single dot on z axis. Like de print>> http://i57.tinypic.com/25zqs1d.png

    void GLWidget::drawGcode(QList<Points*> gcodeDots)
    {
        float x=0,y=0,z=0, xx=0,yy=0,zz=0;
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        makeCurrent();
        for(unsigned int i=1;i<gcodeDots.size();i++)
        {   try{
                gcodeDots[i]->getPoint(&x,&y,&z);
            }catch(QString str)
            {
                qDebug() << i << ' ' <<QString(str);
            }
            glPushMatrix();
            glPointSize(1);
            glColor3b(0,0,1);
           
            glBegin(GL_POINTS);
                
                 glVertex3f(x,y,z);
            glEnd();
    
            glPopMatrix();
        }
        doneCurrent();
        glFlush();
    
    }
    
    

    Why the another dots are no shown?



  • What is the size of gcodeDots when you enter the for loop? And why are you starting the loop index at 1 instead of 0?



  • @Paul-H.
    glPointSize(2);

    I started the loop on 1 in another test, but start with 0.
    Thanks



  • " glPointSize(2);"

    What I was asking is how many elements (points) are in the QList<Points*> gcodeDots when you enter the for loop. If there are only 2 points and you start the index at 1, that would explain why you are only getting 1 point. That wouldn't explain it if you have more than 2 points, though.
    Now, if you have 2 or more points in the list and are starting indexing at 0 and still only getting 1 point displayed, I would check to see that your getPoint() function is actually setting the x,y,z coordinates to different values each time thru the loop.
    Paul



  • @Paul-H. the gcode file, have at least 10.000 of points. In another post i talk about gcode file.
    Example:

    G1 X70.211 Y66.283 E1.16316 F1080.000
    G1 X72.173 Y64.643 E1.32463
    G1 X74.270 Y63.088 E1.48952
    G1 X76.303 Y61.747 E1.64326
    G1 X78.457 Y60.493 E1.80071
    G1 X80.665 Y59.367 E1.95715
    G1 X82.779 Y58.426 E2.10329
    G1 X84.233 Y57.852 E2.20197
    G1 X85.695 Y57.335 E2.29996
    G1 X86.455 Y57.089 E2.35037
    

    So i read this points and make a QList like this:

    Points *p= new Points();
    p->addPoint(x,y,z);
    gcodeDots.append(p);
    

    getPoint function.

    void Points::getPoint(float *x, float *y, float *z) throw (QString)
    {
        (*x) = this->x;
        (*y) = this->y;
        (*z) = this->z;
    }
    

    At the loop i read the QList that already initialized. I run a test with qDebug at the function gcodeDraw, at the QList<Points *> is correct.


  • Qt Champions 2016

    Hi
    I wonder if
    glEnd();
    should be after the looping over the points?`
    Im not into opengl but it seems that one would do

    void GLWidget::drawGcode(QList<Points*> gcodeDots)
    {
        float x=0,y=0,z=0, xx=0,yy=0,zz=0;
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        makeCurrent();¨
            glPushMatrix();
            glPointSize(1);
            glColor3b(0,0,1);
           
          glBegin(GL_POINTS);            
    
        for(unsigned int i=1;i<gcodeDots.size();i++)
        {   try{
                gcodeDots[i]->getPoint(&x,&y,&z);
            }catch(QString str)
            {
                qDebug() << i << ' ' <<QString(str);
            }
                 glVertex3f(x,y,z);
        }
            glEnd();
            glPopMatrix();
    
        doneCurrent();
        glFlush();
    
    }
    

    Or else it seems you would only add one point each time and draw that one. Not All the points.

    Again, you know more of opengl than i do but looking at this sample

    glBegin(GL_POINTS);

    //color of group #1 is white 
    glColor3f(1,1,1);                                
    
    for(int a=0; a<x; a++)
        for(int b=0; b<y; b++)
                    glVertex3f(a/953.,-b/413.,0.);   //location of points
    

    glEnd();

    he adds the points between begin/end. So Im guessing :)



  • @mrjj Its not working anyway. =/


  • Qt Champions 2016

    @Lays147
    Ok. was just a guess since most examples have the begin/end outside of
    the loop.

    sorry =/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.