Changeset 561 for trunk/examples/opengl/hellogl
- 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/hellogl/glwidget.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 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 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 46 46 47 47 #include "glwidget.h" 48 49 50 51 52 48 53 49 54 //! [0] 50 55 GLWidget::GLWidget(QWidget *parent) 51 : QGLWidget( parent)52 { 53 object= 0;56 : QGLWidget(parent) 57 { 58 = 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 Green = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0); 64 Purple = 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 90 91 92 93 94 95 96 86 97 //! [5] 87 98 void GLWidget::setXRotation(int angle) 88 99 { 89 normalizeAngle(&angle);100 angle); 90 101 if (angle != xRot) { 91 102 xRot = angle; … … 98 109 void GLWidget::setYRotation(int angle) 99 110 { 100 normalizeAngle(&angle);111 angle); 101 112 if (angle != yRot) { 102 113 yRot = angle; … … 108 119 void GLWidget::setZRotation(int angle) 109 120 { 110 normalizeAngle(&angle);121 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 140 141 142 143 144 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 glTranslate(0.0, 0.0, -10.0); 154 glRotate(xRot / 16.0, 1.0, 0.0, 0.0); 155 glRotate(yRot / 16.0, 0.0, 1.0, 0.0); 156 glRotate(zRot / 16.0, 0.0, 0.0, 1.0); 157 ); 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 } -
trunk/examples/opengl/hellogl/glwidget.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 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 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 44 44 45 45 #include <QGLWidget> 46 47 46 48 47 49 //! [0] … … 81 83 //! [3] 82 84 private: 83 GLuint makeObject(); 84 void quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2, 85 GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4); 86 void extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); 87 void normalizeAngle(int *angle); 88 89 GLuint object; 85 QtLogo *logo; 90 86 int xRot; 91 87 int yRot; 92 88 int zRot; 93 89 QPoint lastPos; 94 QColor trolltechGreen;95 QColor trolltechPurple;90 QColor Green; 91 QColor Purple; 96 92 }; 97 93 //! [3] -
trunk/examples/opengl/hellogl/hellogl.pro
r2 r561 1 2 3 1 4 HEADERS = glwidget.h \ 2 window.h 5 window.h \ 6 qtlogo.h 3 7 SOURCES = glwidget.cpp \ 4 8 main.cpp \ 5 window.cpp 9 window.cpp \ 10 qtlogo.cpp 6 11 QT += opengl 7 12 … … 11 16 sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl 12 17 INSTALLS += target sources 18 19 -
trunk/examples/opengl/hellogl/main.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 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 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include <QApplication> 43 43 44 44 45 #include "window.h" … … 48 49 QApplication app(argc, argv); 49 50 Window window; 50 window.show(); 51 window.resize(window.sizeHint()); 52 int desktopArea = QApplication::desktop()->width() * 53 QApplication::desktop()->height(); 54 int widgetArea = window.width() * window.height(); 55 if (((float)widgetArea / (float)desktopArea) < 0.75f) 56 window.show(); 57 else 58 window.showMaximized(); 51 59 return app.exec(); 52 60 } -
trunk/examples/opengl/hellogl/window.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 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 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 89 89 } 90 90 //! [2] 91 92 93 94 95 96 97 98 -
trunk/examples/opengl/hellogl/window.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 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 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 58 58 Window(); 59 59 60 61 62 60 63 private: 61 64 QSlider *createSlider();
Note:
See TracChangeset
for help on using the changeset viewer.