Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpenglWidget - Draw Points from a QList
QtWS: Super Early Bird Tickets Available!

QOpenglWidget - Draw Points from a QList

Scheduled Pinned Locked Moved General and Desktop
qopenglwiqt5.5
10 Posts 3 Posters 5.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Lays147L Offline
    Lays147L Offline
    Lays147
    wrote on last edited by Lays147
    #1

    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?

    Lays Rodrigues
    Newby on Qt - Learning always!
    Using QT 5.7
    ArchLinux

    1 Reply Last reply
    0
  • mrjjM Offline
    mrjjM Offline
    mrjj Lifetime Qt Champion
    wrote on last edited by
    #2

    @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();
    }
    
    1 Reply Last reply
    1
  • Lays147L Offline
    Lays147L Offline
    Lays147
    wrote on last edited by
    #3

    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?

    Lays Rodrigues
    Newby on Qt - Learning always!
    Using QT 5.7
    ArchLinux

    1 Reply Last reply
    0
  • Paul H.P Offline
    Paul H.P Offline
    Paul H.
    wrote on last edited by
    #4

    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?

    Lays147L 1 Reply Last reply
    0
  • Lays147L Offline
    Lays147L Offline
    Lays147
    replied to Paul H. on last edited by
    #5

    @Paul-H.
    glPointSize(2);

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

    Lays Rodrigues
    Newby on Qt - Learning always!
    Using QT 5.7
    ArchLinux

    1 Reply Last reply
    0
  • Paul H.P Offline
    Paul H.P Offline
    Paul H.
    wrote on last edited by
    #6

    " 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

    Lays147L 1 Reply Last reply
    0
  • Lays147L Offline
    Lays147L Offline
    Lays147
    replied to Paul H. on last edited by
    #7

    @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.

    Lays Rodrigues
    Newby on Qt - Learning always!
    Using QT 5.7
    ArchLinux

    1 Reply Last reply
    0
  • mrjjM Offline
    mrjjM Offline
    mrjj Lifetime Qt Champion
    wrote on last edited by mrjj
    #8

    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 :)

    Lays147L 1 Reply Last reply
    0
  • Lays147L Offline
    Lays147L Offline
    Lays147
    replied to mrjj on last edited by
    #9

    @mrjj Its not working anyway. =/

    Lays Rodrigues
    Newby on Qt - Learning always!
    Using QT 5.7
    ArchLinux

    mrjjM 1 Reply Last reply
    0
  • mrjjM Offline
    mrjjM Offline
    mrjj Lifetime Qt Champion
    replied to Lays147 on last edited by
    #10

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

    sorry =/

    1 Reply Last reply
    0

  • Login

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved