PDA

View Full Version : Cylinder draw using QT opengl functions



YuriyRusinov
12th June 2008, 16:05
Dear colleagues !

I want to draw cylinder on QGLWidget. I do


...
void GLWidget :: initializeGL (void)
{
qDebug () << __FUNCTION__;
glClearColor (1.0, 1.0, 1.0, 0.0);
}

void GLWidget :: paintGL (void)
{
qDebug () << __FUNCTION__ << cyl_radius << cyl_height;
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (fabs (cyl_radius) < 0.1e-15 || fabs (cyl_height) < 0.1e-15)
return;
glBegin (GL_POLYGON);
glColor3d (1, 0, 0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
GLUquadricObj* q = gluNewQuadric ();

gluCylinder (q, (GLdouble)cyl_radius, (GLdouble)cyl_radius, (GLdouble)cyl_height, 320, 320);
glEnd ();
glMatrixMode (GL_MODELVIEW);
gluDeleteQuadric (q);
}

void GLWidget :: resizeGL (int width, int height)
{
qDebug () << __FUNCTION__;
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glViewport ((GLsizei)width/2, (GLsizei)height/2, (GLsizei)width, (GLsizei)height);
glOrtho (0, this->QGLWidget::width (), 0, this->QGLWidget::height (), -1,1);
glMatrixMode (GL_MODELVIEW);
}

But except cylinder I receive sector of circle as presented in attachment.

jacek
25th June 2008, 23:58
Maybe something is wrong with the projection? What happens when you draw a cylinder with smaller height? Also remove line #16.