Changeset 561 for trunk/examples/opengl/hellogl/glwidget.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/examples/opengl/hellogl/glwidget.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the examples of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 46 46 47 47 #include "glwidget.h" 48 #include "qtlogo.h" 49 50 #ifndef GL_MULTISAMPLE 51 #define GL_MULTISAMPLE 0x809D 52 #endif 48 53 49 54 //! [0] 50 55 GLWidget::GLWidget(QWidget *parent) 51 : QGLWidget( parent)52 { 53 object= 0;56 : QGLWidget(QGLFormat(QGL::SampleBuffers), parent) 57 { 58 logo = 0; 54 59 xRot = 0; 55 60 yRot = 0; 56 61 zRot = 0; 57 62 58 trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);59 trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);63 qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0); 64 qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0); 60 65 } 61 66 //! [0] … … 64 69 GLWidget::~GLWidget() 65 70 { 66 makeCurrent();67 glDeleteLists(object, 1);68 71 } 69 72 //! [1] … … 84 87 //! [4] 85 88 89 static void qNormalizeAngle(int &angle) 90 { 91 while (angle < 0) 92 angle += 360 * 16; 93 while (angle > 360 * 16) 94 angle -= 360 * 16; 95 } 96 86 97 //! [5] 87 98 void GLWidget::setXRotation(int angle) 88 99 { 89 normalizeAngle(&angle);100 qNormalizeAngle(angle); 90 101 if (angle != xRot) { 91 102 xRot = angle; … … 98 109 void GLWidget::setYRotation(int angle) 99 110 { 100 normalizeAngle(&angle);111 qNormalizeAngle(angle); 101 112 if (angle != yRot) { 102 113 yRot = angle; … … 108 119 void GLWidget::setZRotation(int angle) 109 120 { 110 normalizeAngle(&angle);121 qNormalizeAngle(angle); 111 122 if (angle != zRot) { 112 123 zRot = angle; … … 119 130 void GLWidget::initializeGL() 120 131 { 121 qglClearColor(trolltechPurple.dark()); 122 object = makeObject(); 123 glShadeModel(GL_FLAT); 132 qglClearColor(qtPurple.dark()); 133 134 logo = new QtLogo(this, 64); 135 logo->setColor(qtGreen.dark()); 136 124 137 glEnable(GL_DEPTH_TEST); 125 138 glEnable(GL_CULL_FACE); 139 glShadeModel(GL_SMOOTH); 140 glEnable(GL_LIGHTING); 141 glEnable(GL_LIGHT0); 142 glEnable(GL_MULTISAMPLE); 143 static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 }; 144 glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); 126 145 } 127 146 //! [6] … … 132 151 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 133 152 glLoadIdentity(); 134 glTranslate d(0.0, 0.0, -10.0);135 glRotate d(xRot / 16.0, 1.0, 0.0, 0.0);136 glRotate d(yRot / 16.0, 0.0, 1.0, 0.0);137 glRotate d(zRot / 16.0, 0.0, 0.0, 1.0);138 glCallList(object);153 glTranslatef(0.0, 0.0, -10.0); 154 glRotatef(xRot / 16.0, 1.0, 0.0, 0.0); 155 glRotatef(yRot / 16.0, 0.0, 1.0, 0.0); 156 glRotatef(zRot / 16.0, 0.0, 0.0, 1.0); 157 logo->draw(); 139 158 } 140 159 //! [7] … … 148 167 glMatrixMode(GL_PROJECTION); 149 168 glLoadIdentity(); 150 glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 169 #ifdef QT_OPENGL_ES_1 170 glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0); 171 #else 172 glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0); 173 #endif 151 174 glMatrixMode(GL_MODELVIEW); 152 175 } … … 176 199 } 177 200 //! [10] 178 179 GLuint GLWidget::makeObject()180 {181 GLuint list = glGenLists(1);182 glNewList(list, GL_COMPILE);183 184 glBegin(GL_QUADS);185 186 GLdouble x1 = +0.06;187 GLdouble y1 = -0.14;188 GLdouble x2 = +0.14;189 GLdouble y2 = -0.06;190 GLdouble x3 = +0.08;191 GLdouble y3 = +0.00;192 GLdouble x4 = +0.30;193 GLdouble y4 = +0.22;194 195 quad(x1, y1, x2, y2, y2, x2, y1, x1);196 quad(x3, y3, x4, y4, y4, x4, y3, x3);197 198 extrude(x1, y1, x2, y2);199 extrude(x2, y2, y2, x2);200 extrude(y2, x2, y1, x1);201 extrude(y1, x1, x1, y1);202 extrude(x3, y3, x4, y4);203 extrude(x4, y4, y4, x4);204 extrude(y4, x4, y3, x3);205 206 const double Pi = 3.14159265358979323846;207 const int NumSectors = 200;208 209 for (int i = 0; i < NumSectors; ++i) {210 double angle1 = (i * 2 * Pi) / NumSectors;211 GLdouble x5 = 0.30 * sin(angle1);212 GLdouble y5 = 0.30 * cos(angle1);213 GLdouble x6 = 0.20 * sin(angle1);214 GLdouble y6 = 0.20 * cos(angle1);215 216 double angle2 = ((i + 1) * 2 * Pi) / NumSectors;217 GLdouble x7 = 0.20 * sin(angle2);218 GLdouble y7 = 0.20 * cos(angle2);219 GLdouble x8 = 0.30 * sin(angle2);220 GLdouble y8 = 0.30 * cos(angle2);221 222 quad(x5, y5, x6, y6, x7, y7, x8, y8);223 224 extrude(x6, y6, x7, y7);225 extrude(x8, y8, x5, y5);226 }227 228 glEnd();229 230 glEndList();231 return list;232 }233 234 void GLWidget::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,235 GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)236 {237 qglColor(trolltechGreen);238 239 glVertex3d(x1, y1, -0.05);240 glVertex3d(x2, y2, -0.05);241 glVertex3d(x3, y3, -0.05);242 glVertex3d(x4, y4, -0.05);243 244 glVertex3d(x4, y4, +0.05);245 glVertex3d(x3, y3, +0.05);246 glVertex3d(x2, y2, +0.05);247 glVertex3d(x1, y1, +0.05);248 }249 250 void GLWidget::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)251 {252 qglColor(trolltechGreen.dark(250 + int(100 * x1)));253 254 glVertex3d(x1, y1, +0.05);255 glVertex3d(x2, y2, +0.05);256 glVertex3d(x2, y2, -0.05);257 glVertex3d(x1, y1, -0.05);258 }259 260 void GLWidget::normalizeAngle(int *angle)261 {262 while (*angle < 0)263 *angle += 360 * 16;264 while (*angle > 360 * 16)265 *angle -= 360 * 16;266 }
Note:
See TracChangeset
for help on using the changeset viewer.