Changeset 561 for trunk/examples/opengl/overpainting
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 7 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/overpainting/bubble.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 ** -
trunk/examples/opengl/overpainting/bubble.h
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 ** -
trunk/examples/opengl/overpainting/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 ** … … 47 47 48 48 #include "bubble.h" 49 #include "qtlogo.h" 49 50 #include "glwidget.h" 50 51 … … 60 61 qsrand(midnight.secsTo(QTime::currentTime())); 61 62 62 object= 0;63 logo = 0; 63 64 xRot = 0; 64 65 yRot = 0; 65 66 zRot = 0; 66 67 67 trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);68 trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);68 qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0); 69 qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0); 69 70 70 71 animationTimer.setSingleShot(false); … … 81 82 GLWidget::~GLWidget() 82 83 { 83 makeCurrent();84 glDeleteLists(object, 1);85 84 } 86 85 //! [1] 87 86 87 static void qNormalizeAngle(int &angle) 88 { 89 while (angle < 0) 90 angle += 360 * 16; 91 while (angle > 360 * 16) 92 angle -= 360 * 16; 93 } 94 88 95 void GLWidget::setXRotation(int angle) 89 96 { 90 normalizeAngle(&angle);97 qNormalizeAngle(angle); 91 98 if (angle != xRot) 92 99 xRot = angle; … … 95 102 void GLWidget::setYRotation(int angle) 96 103 { 97 normalizeAngle(&angle);104 qNormalizeAngle(angle); 98 105 if (angle != yRot) 99 106 yRot = angle; … … 102 109 void GLWidget::setZRotation(int angle) 103 110 { 104 normalizeAngle(&angle);111 qNormalizeAngle(angle); 105 112 if (angle != zRot) 106 113 zRot = angle; … … 110 117 void GLWidget::initializeGL() 111 118 { 112 object = makeObject(); 119 glEnable(GL_MULTISAMPLE); 120 121 logo = new QtLogo(this); 122 logo->setColor(qtGreen.dark()); 113 123 } 114 124 //! [2] … … 143 153 144 154 //! [6] 145 qglClearColor( trolltechPurple.dark());155 qglClearColor(qtPurple.dark()); 146 156 glShadeModel(GL_SMOOTH); 147 157 glEnable(GL_DEPTH_TEST); … … 159 169 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 160 170 glLoadIdentity(); 161 glTranslated(0.0, 0.0, -10.0); 162 glRotated(xRot / 16.0, 1.0, 0.0, 0.0); 163 glRotated(yRot / 16.0, 0.0, 1.0, 0.0); 164 glRotated(zRot / 16.0, 0.0, 0.0, 1.0); 165 glCallList(object); 171 glTranslatef(0.0, 0.0, -10.0); 172 glRotatef(xRot / 16.0, 1.0, 0.0, 0.0); 173 glRotatef(yRot / 16.0, 0.0, 1.0, 0.0); 174 glRotatef(zRot / 16.0, 0.0, 0.0, 1.0); 175 176 logo->draw(); 166 177 //! [7] 167 178 168 179 //! [8] 180 glShadeModel(GL_FLAT); 181 glDisable(GL_CULL_FACE); 182 glDisable(GL_DEPTH_TEST); 183 glDisable(GL_LIGHTING); 184 169 185 glMatrixMode(GL_MODELVIEW); 170 186 glPopMatrix(); … … 203 219 } 204 220 205 GLuint GLWidget::makeObject()206 {207 GLuint list = glGenLists(1);208 glNewList(list, GL_COMPILE);209 210 glEnable(GL_NORMALIZE);211 glBegin(GL_QUADS);212 213 static GLfloat logoDiffuseColor[4] = {trolltechGreen.red()/255.0,214 trolltechGreen.green()/255.0,215 trolltechGreen.blue()/255.0, 1.0};216 glMaterialfv(GL_FRONT, GL_DIFFUSE, logoDiffuseColor);217 218 GLdouble x1 = +0.06;219 GLdouble y1 = -0.14;220 GLdouble x2 = +0.14;221 GLdouble y2 = -0.06;222 GLdouble x3 = +0.08;223 GLdouble y3 = +0.00;224 GLdouble x4 = +0.30;225 GLdouble y4 = +0.22;226 227 quad(x1, y1, x2, y2, y2, x2, y1, x1);228 quad(x3, y3, x4, y4, y4, x4, y3, x3);229 230 extrude(x1, y1, x2, y2);231 extrude(x2, y2, y2, x2);232 extrude(y2, x2, y1, x1);233 extrude(y1, x1, x1, y1);234 extrude(x3, y3, x4, y4);235 extrude(x4, y4, y4, x4);236 extrude(y4, x4, y3, x3);237 238 const double Pi = 3.14159265358979323846;239 const int NumSectors = 200;240 241 for (int i = 0; i < NumSectors; ++i) {242 double angle1 = (i * 2 * Pi) / NumSectors;243 GLdouble x5 = 0.30 * sin(angle1);244 GLdouble y5 = 0.30 * cos(angle1);245 GLdouble x6 = 0.20 * sin(angle1);246 GLdouble y6 = 0.20 * cos(angle1);247 248 double angle2 = ((i + 1) * 2 * Pi) / NumSectors;249 GLdouble x7 = 0.20 * sin(angle2);250 GLdouble y7 = 0.20 * cos(angle2);251 GLdouble x8 = 0.30 * sin(angle2);252 GLdouble y8 = 0.30 * cos(angle2);253 254 quad(x5, y5, x6, y6, x7, y7, x8, y8);255 256 extrude(x6, y6, x7, y7);257 extrude(x8, y8, x5, y5);258 }259 260 glEnd();261 262 glEndList();263 return list;264 }265 266 void GLWidget::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,267 GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)268 {269 glNormal3d(0.0, 0.0, -1.0);270 glVertex3d(x1, y1, -0.05);271 glVertex3d(x2, y2, -0.05);272 glVertex3d(x3, y3, -0.05);273 glVertex3d(x4, y4, -0.05);274 275 glNormal3d(0.0, 0.0, 1.0);276 glVertex3d(x4, y4, +0.05);277 glVertex3d(x3, y3, +0.05);278 glVertex3d(x2, y2, +0.05);279 glVertex3d(x1, y1, +0.05);280 }281 282 void GLWidget::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)283 {284 qglColor(trolltechGreen.dark(250 + int(100 * x1)));285 286 glNormal3d((x1 + x2)/2.0, (y1 + y2)/2.0, 0.0);287 glVertex3d(x1, y1, +0.05);288 glVertex3d(x2, y2, +0.05);289 glVertex3d(x2, y2, -0.05);290 glVertex3d(x1, y1, -0.05);291 }292 293 void GLWidget::normalizeAngle(int *angle)294 {295 while (*angle < 0)296 *angle += 360 * 16;297 while (*angle > 360 * 16)298 *angle -= 360 * 16;299 }300 301 221 void GLWidget::createBubbles(int number) 302 222 { … … 333 253 glMatrixMode(GL_PROJECTION); 334 254 glLoadIdentity(); 335 glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 255 #ifdef QT_OPENGL_ES 256 glOrthof(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0); 257 #else 258 glOrtho(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0); 259 #endif 336 260 glMatrixMode(GL_MODELVIEW); 337 261 } -
trunk/examples/opengl/overpainting/glwidget.h
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 ** … … 51 51 52 52 class Bubble; 53 class QtLogo; 53 54 QT_BEGIN_NAMESPACE 54 55 class QPaintEvent; … … 89 90 90 91 private: 91 GLuint makeObject();92 92 void createBubbles(int number); 93 93 void drawInstructions(QPainter *painter); 94 94 //! [1] 95 void extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);96 void normalizeAngle(int *angle);97 void quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,98 GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4);99 95 void setupViewport(int width, int height); 96 97 QColor qtGreen; 98 QColor qtPurple; 100 99 101 100 GLuint object; … … 104 103 int zRot; 105 104 QPoint lastPos; 106 QColor trolltechGreen;107 QColor trolltechPurple;108 105 //! [4] 106 QtLogo *logo; 109 107 QList<Bubble*> bubbles; 110 108 QTimer animationTimer; 109 //! [4] 111 110 }; 112 //! [4]113 111 114 112 #endif -
trunk/examples/opengl/overpainting/main.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 ** -
trunk/examples/opengl/overpainting/overpainting.pro
r2 r561 1 QT += opengl 1 VPATH += ../shared 2 INCLUDEPATH += ../shared 2 3 3 HEADERS = bubble.h \ 4 glwidget.h 5 SOURCES = bubble.cpp \ 6 glwidget.cpp \ 7 main.cpp 4 QT += opengl 5 HEADERS = bubble.h \ 6 glwidget.h \ 7 qtlogo.h 8 SOURCES = bubble.cpp \ 9 glwidget.cpp \ 10 main.cpp \ 11 qtlogo.cpp 8 12 9 13 # install 10 14 target.path = $$[QT_INSTALL_EXAMPLES]/opengl/overpainting 11 sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS overpainting.pro 15 sources.files = $$SOURCES \ 16 $$HEADERS \ 17 $$RESOURCES \ 18 $$FORMS \ 19 overpainting.pro 12 20 sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/overpainting 13 INSTALLS += target sources 21 INSTALLS += target \ 22 sources 23 symbian:include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
Note:
See TracChangeset
for help on using the changeset viewer.