Changeset 561 for trunk/examples/opengl/textures
- 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/textures/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 ** … … 43 43 #include <QtOpenGL> 44 44 45 #include <math.h>46 47 45 #include "glwidget.h" 48 49 GLuint GLWidget::sharedObject = 0;50 int GLWidget::refCount = 0;51 46 52 47 GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget) … … 57 52 yRot = 0; 58 53 zRot = 0; 54 #ifdef QT_OPENGL_ES_2 55 program = 0; 56 #endif 59 57 } 60 58 61 59 GLWidget::~GLWidget() 62 60 { 63 if (--refCount == 0) {64 makeCurrent();65 glDeleteLists(sharedObject, 1);66 }67 61 } 68 62 … … 93 87 void GLWidget::initializeGL() 94 88 { 95 if (!sharedObject) 96 sharedObject = makeObject(); 97 ++refCount; 89 makeObject(); 98 90 99 91 glEnable(GL_DEPTH_TEST); 100 92 glEnable(GL_CULL_FACE); 93 #ifndef QT_OPENGL_ES_2 101 94 glEnable(GL_TEXTURE_2D); 95 #endif 96 97 #ifdef QT_OPENGL_ES_2 98 99 #define PROGRAM_VERTEX_ATTRIBUTE 0 100 #define PROGRAM_TEXCOORD_ATTRIBUTE 1 101 102 QGLShader *vshader = new QGLShader(QGLShader::Vertex, this); 103 const char *vsrc = 104 "attribute highp vec4 vertex;\n" 105 "attribute mediump vec4 texCoord;\n" 106 "varying mediump vec4 texc;\n" 107 "uniform mediump mat4 matrix;\n" 108 "void main(void)\n" 109 "{\n" 110 " gl_Position = matrix * vertex;\n" 111 " texc = texCoord;\n" 112 "}\n"; 113 vshader->compileSourceCode(vsrc); 114 115 QGLShader *fshader = new QGLShader(QGLShader::Fragment, this); 116 const char *fsrc = 117 "uniform sampler2D texture;\n" 118 "varying mediump vec4 texc;\n" 119 "void main(void)\n" 120 "{\n" 121 " gl_FragColor = texture2D(texture, texc.st);\n" 122 "}\n"; 123 fshader->compileSourceCode(fsrc); 124 125 program = new QGLShaderProgram(this); 126 program->addShader(vshader); 127 program->addShader(fshader); 128 program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE); 129 program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE); 130 program->link(); 131 132 program->bind(); 133 program->setUniformValue("texture", 0); 134 135 #endif 102 136 } 103 137 … … 106 140 qglClearColor(clearColor); 107 141 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 142 143 #if !defined(QT_OPENGL_ES_2) 144 108 145 glLoadIdentity(); 109 glTranslated(0.0, 0.0, -10.0); 110 glRotated(xRot / 16.0, 1.0, 0.0, 0.0); 111 glRotated(yRot / 16.0, 0.0, 1.0, 0.0); 112 glRotated(zRot / 16.0, 0.0, 0.0, 1.0); 113 glCallList(sharedObject); 146 glTranslatef(0.0f, 0.0f, -10.0f); 147 glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f); 148 glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f); 149 glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f); 150 151 glVertexPointer(3, GL_FLOAT, 0, vertices.constData()); 152 glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData()); 153 glEnableClientState(GL_VERTEX_ARRAY); 154 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 155 156 #else 157 158 QMatrix4x4 m; 159 m.ortho(-0.5f, +0.5f, +0.5f, -0.5f, 4.0f, 15.0f); 160 m.translate(0.0f, 0.0f, -10.0f); 161 m.rotate(xRot / 16.0f, 1.0f, 0.0f, 0.0f); 162 m.rotate(yRot / 16.0f, 0.0f, 1.0f, 0.0f); 163 m.rotate(zRot / 16.0f, 0.0f, 0.0f, 1.0f); 164 165 program->setUniformValue("matrix", m); 166 program->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE); 167 program->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE); 168 program->setAttributeArray 169 (PROGRAM_VERTEX_ATTRIBUTE, vertices.constData()); 170 program->setAttributeArray 171 (PROGRAM_TEXCOORD_ATTRIBUTE, texCoords.constData()); 172 173 #endif 174 175 for (int i = 0; i < 6; ++i) { 176 glBindTexture(GL_TEXTURE_2D, textures[i]); 177 glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); 178 } 114 179 } 115 180 … … 119 184 glViewport((width - side) / 2, (height - side) / 2, side, side); 120 185 186 #if !defined(QT_OPENGL_ES_2) 121 187 glMatrixMode(GL_PROJECTION); 122 188 glLoadIdentity(); 189 #ifndef QT_OPENGL_ES 123 190 glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 191 #else 192 glOrthof(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 193 #endif 124 194 glMatrixMode(GL_MODELVIEW); 195 #endif 125 196 } 126 197 … … 148 219 } 149 220 150 GLuintGLWidget::makeObject()221 void GLWidget::makeObject() 151 222 { 152 223 static const int coords[6][4][3] = { … … 159 230 }; 160 231 161 162 GLuint textures[6]; 163 for (int j=0; j < 6; ++j) 164 textures[j] = bindTexture(QPixmap(QString(":/images/side%1.png").arg(j + 1)), 165 GL_TEXTURE_2D); 166 167 GLuint list = glGenLists(1); 168 glNewList(list, GL_COMPILE); 232 for (int j=0; j < 6; ++j) { 233 textures[j] = bindTexture 234 (QPixmap(QString(":/images/side%1.png").arg(j + 1)), GL_TEXTURE_2D); 235 } 236 169 237 for (int i = 0; i < 6; ++i) { 170 glBindTexture(GL_TEXTURE_2D, textures[i]);171 glBegin(GL_QUADS);172 238 for (int j = 0; j < 4; ++j) { 173 glTexCoord2d(j == 0 || j == 3, j == 0 || j == 1); 174 glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 175 0.2 * coords[i][j][2]); 239 texCoords.append 240 (QVector2D(j == 0 || j == 3, j == 0 || j == 1)); 241 vertices.append 242 (QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 243 0.2 * coords[i][j][2])); 176 244 } 177 glEnd(); 178 } 179 180 glEndList(); 181 return list; 182 } 245 } 246 } -
trunk/examples/opengl/textures/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 ** … … 43 43 #define GLWIDGET_H 44 44 45 #include <QtGui> 45 46 #include <QGLWidget> 47 48 class QGLShaderProgram; 46 49 47 50 class GLWidget : public QGLWidget … … 70 73 71 74 private: 72 GLuintmakeObject();75 void makeObject(); 73 76 74 77 QColor clearColor; … … 77 80 int yRot; 78 81 int zRot; 79 80 static GLuint sharedObject; 81 static int refCount; 82 GLuint textures[6]; 83 QVector<QVector3D> vertices; 84 QVector<QVector2D> texCoords; 85 #ifdef QT_OPENGL_ES_2 86 QGLShaderProgram *program; 87 #endif 82 88 }; 83 89 -
trunk/examples/opengl/textures/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/textures/textures.pro
r2 r561 12 12 sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures 13 13 INSTALLS += target sources 14 15 symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -
trunk/examples/opengl/textures/window.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 ** … … 49 49 QGridLayout *mainLayout = new QGridLayout; 50 50 51 glWidgets[0][0] = 0;52 53 51 for (int i = 0; i < NumRows; ++i) { 54 52 for (int j = 0; j < NumColumns; ++j) { … … 58 56 255, 63); 59 57 60 glWidgets[i][j] = new GLWidget(0, glWidgets[0][0]);58 glWidgets[i][j] = new GLWidget(0, 0); 61 59 glWidgets[i][j]->setClearColor(clearColor); 62 60 glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16); -
trunk/examples/opengl/textures/window.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 **
Note:
See TracChangeset
for help on using the changeset viewer.