Results 1 to 2 of 2

Thread: Cylinder draw using QT opengl functions

  1. #1
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Cylinder draw using QT opengl functions

    Dear colleagues !

    I want to draw cylinder on QGLWidget. I do
    Qt Code:
    1. ...
    2. void GLWidget :: initializeGL (void)
    3. {
    4. qDebug () << __FUNCTION__;
    5. glClearColor (1.0, 1.0, 1.0, 0.0);
    6. }
    7.  
    8. void GLWidget :: paintGL (void)
    9. {
    10. qDebug () << __FUNCTION__ << cyl_radius << cyl_height;
    11. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    12. if (fabs (cyl_radius) < 0.1e-15 || fabs (cyl_height) < 0.1e-15)
    13. return;
    14. glBegin (GL_POLYGON);
    15. glColor3d (1, 0, 0);
    16. glMatrixMode (GL_PROJECTION);
    17. glLoadIdentity();
    18. GLUquadricObj* q = gluNewQuadric ();
    19.  
    20. gluCylinder (q, (GLdouble)cyl_radius, (GLdouble)cyl_radius, (GLdouble)cyl_height, 320, 320);
    21. glEnd ();
    22. glMatrixMode (GL_MODELVIEW);
    23. gluDeleteQuadric (q);
    24. }
    25.  
    26. void GLWidget :: resizeGL (int width, int height)
    27. {
    28. qDebug () << __FUNCTION__;
    29. glMatrixMode (GL_PROJECTION);
    30. glLoadIdentity ();
    31. glViewport ((GLsizei)width/2, (GLsizei)height/2, (GLsizei)width, (GLsizei)height);
    32. glOrtho (0, this->QGLWidget::width (), 0, this->QGLWidget::height (), -1,1);
    33. glMatrixMode (GL_MODELVIEW);
    34. }
    To copy to clipboard, switch view to plain text mode 
    But except cylinder I receive sector of circle as presented in attachment.
    Attached Images Attached Images
    Best regards,
    Yuriy Rusinov.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cylinder draw using QT opengl functions

    Maybe something is wrong with the projection? What happens when you draw a cylinder with smaller height? Also remove line #16.

Similar Threads

  1. Replies: 4
    Last Post: 9th May 2008, 21:56
  2. Replies: 5
    Last Post: 11th March 2008, 13:38
  3. Replies: 5
    Last Post: 7th November 2006, 15:01
  4. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 12:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.