11 #include <QOpenGLFunctions> 25 QOpenGLFunctions* pFunc =
26 QOpenGLContext::currentContext()->functions();
27 pFunc->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
29 pFunc->glEnable(GL_DEPTH_TEST);
30 glShadeModel(GL_FLAT);
37 glViewport(0, 0, (GLint)nWidth, (GLint)nHeight);
38 glMatrixMode(GL_PROJECTION);
40 glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
46 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
48 glMatrixMode(GL_MODELVIEW);
50 glTranslatef(0.0, 0.0, -3.0);
52 glRotatef(m_xRotate, 1.0, 0.0, 0.0);
53 glRotatef(m_yRotate, 0.0, 1.0, 0.0);
55 glCallList(m_nPyramid);
61 m_ptPosition = pe->pos();
67 m_xRotate += 180 * (GLfloat)(pe->y() - m_ptPosition.y()) / height();
68 m_yRotate += 180 * (GLfloat)(pe->x() - m_ptPosition.x()) / width();
71 m_ptPosition = pe->pos();
77 GLuint n = glGenLists(1);
79 glNewList(n, GL_COMPILE);
80 glBegin(GL_TRIANGLE_FAN);
81 glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
82 glVertex3f(0.0, fSize, 0.0);
83 glVertex3f(-fSize, -fSize, fSize);
84 glVertex3f(fSize, -fSize, fSize);
85 glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
86 glVertex3f(fSize, -fSize, -fSize);
87 glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
88 glVertex3f(-fSize, -fSize, -fSize);
89 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
90 glVertex3f(-fSize, -fSize, fSize);
94 glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
95 glVertex3f(-fSize, -fSize, fSize);
96 glVertex3f(fSize, -fSize, fSize);
97 glVertex3f(fSize, -fSize, -fSize);
98 glVertex3f(-fSize, -fSize, -fSize);
OGLPyramid(QWidget *pwgt=0)
virtual void mousePressEvent(QMouseEvent *pe)
virtual void mouseMoveEvent(QMouseEvent *pe)
virtual void initializeGL()
GLuint createPyramid(GLfloat fSize=1.0f)
virtual void resizeGL(int nWidth, int nHeight)