summaryrefslogtreecommitdiffstats
path: root/examples/opengl/textures
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/textures')
-rw-r--r--examples/opengl/textures/glwidget.cpp182
-rw-r--r--examples/opengl/textures/glwidget.h84
-rw-r--r--examples/opengl/textures/images/side1.pngbin0 -> 935 bytes
-rw-r--r--examples/opengl/textures/images/side2.pngbin0 -> 1622 bytes
-rw-r--r--examples/opengl/textures/images/side3.pngbin0 -> 2117 bytes
-rw-r--r--examples/opengl/textures/images/side4.pngbin0 -> 1222 bytes
-rw-r--r--examples/opengl/textures/images/side5.pngbin0 -> 1806 bytes
-rw-r--r--examples/opengl/textures/images/side6.pngbin0 -> 2215 bytes
-rw-r--r--examples/opengl/textures/main.cpp54
-rw-r--r--examples/opengl/textures/textures.pro13
-rw-r--r--examples/opengl/textures/textures.qrc10
-rw-r--r--examples/opengl/textures/window.cpp89
-rw-r--r--examples/opengl/textures/window.h67
13 files changed, 499 insertions, 0 deletions
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
new file mode 100644
index 0000000..5882373
--- /dev/null
+++ b/examples/opengl/textures/glwidget.cpp
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+
+#include <math.h>
+
+#include "glwidget.h"
+
+GLuint GLWidget::sharedObject = 0;
+int GLWidget::refCount = 0;
+
+GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget)
+ : QGLWidget(parent, shareWidget)
+{
+ clearColor = Qt::black;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+}
+
+GLWidget::~GLWidget()
+{
+ if (--refCount == 0) {
+ makeCurrent();
+ glDeleteLists(sharedObject, 1);
+ }
+}
+
+QSize GLWidget::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+
+QSize GLWidget::sizeHint() const
+{
+ return QSize(200, 200);
+}
+
+void GLWidget::rotateBy(int xAngle, int yAngle, int zAngle)
+{
+ xRot += xAngle;
+ yRot += yAngle;
+ zRot += zAngle;
+ updateGL();
+}
+
+void GLWidget::setClearColor(const QColor &color)
+{
+ clearColor = color;
+ updateGL();
+}
+
+void GLWidget::initializeGL()
+{
+ if (!sharedObject)
+ sharedObject = makeObject();
+ ++refCount;
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_TEXTURE_2D);
+}
+
+void GLWidget::paintGL()
+{
+ qglClearColor(clearColor);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glTranslated(0.0, 0.0, -10.0);
+ glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
+ glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
+ glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
+ glCallList(sharedObject);
+}
+
+void GLWidget::resizeGL(int width, int height)
+{
+ int side = qMin(width, height);
+ glViewport((width - side) / 2, (height - side) / 2, side, side);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void GLWidget::mousePressEvent(QMouseEvent *event)
+{
+ lastPos = event->pos();
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ int dx = event->x() - lastPos.x();
+ int dy = event->y() - lastPos.y();
+
+ if (event->buttons() & Qt::LeftButton) {
+ rotateBy(8 * dy, 8 * dx, 0);
+ } else if (event->buttons() & Qt::RightButton) {
+ rotateBy(8 * dy, 0, 8 * dx);
+ }
+ lastPos = event->pos();
+}
+
+void GLWidget::mouseReleaseEvent(QMouseEvent * /* event */)
+{
+ emit clicked();
+}
+
+GLuint GLWidget::makeObject()
+{
+ static const int coords[6][4][3] = {
+ { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } },
+ { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } },
+ { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
+ { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
+ { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } },
+ { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
+ };
+
+
+ GLuint textures[6];
+ for (int j=0; j < 6; ++j)
+ textures[j] = bindTexture(QPixmap(QString(":/images/side%1.png").arg(j + 1)),
+ GL_TEXTURE_2D);
+
+ GLuint list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+ for (int i = 0; i < 6; ++i) {
+ glBindTexture(GL_TEXTURE_2D, textures[i]);
+ glBegin(GL_QUADS);
+ for (int j = 0; j < 4; ++j) {
+ glTexCoord2d(j == 0 || j == 3, j == 0 || j == 1);
+ glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
+ 0.2 * coords[i][j][2]);
+ }
+ glEnd();
+ }
+
+ glEndList();
+ return list;
+}
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
new file mode 100644
index 0000000..623b301
--- /dev/null
+++ b/examples/opengl/textures/glwidget.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0);
+ ~GLWidget();
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+ void rotateBy(int xAngle, int yAngle, int zAngle);
+ void setClearColor(const QColor &color);
+
+signals:
+ void clicked();
+
+protected:
+ void initializeGL();
+ void paintGL();
+ void resizeGL(int width, int height);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private:
+ GLuint makeObject();
+
+ QColor clearColor;
+ QPoint lastPos;
+ int xRot;
+ int yRot;
+ int zRot;
+
+ static GLuint sharedObject;
+ static int refCount;
+};
+
+#endif
diff --git a/examples/opengl/textures/images/side1.png b/examples/opengl/textures/images/side1.png
new file mode 100644
index 0000000..2e6b471
--- /dev/null
+++ b/examples/opengl/textures/images/side1.png
Binary files differ
diff --git a/examples/opengl/textures/images/side2.png b/examples/opengl/textures/images/side2.png
new file mode 100644
index 0000000..d1acf1b
--- /dev/null
+++ b/examples/opengl/textures/images/side2.png
Binary files differ
diff --git a/examples/opengl/textures/images/side3.png b/examples/opengl/textures/images/side3.png
new file mode 100644
index 0000000..a638613
--- /dev/null
+++ b/examples/opengl/textures/images/side3.png
Binary files differ
diff --git a/examples/opengl/textures/images/side4.png b/examples/opengl/textures/images/side4.png
new file mode 100644
index 0000000..ebbc1e3
--- /dev/null
+++ b/examples/opengl/textures/images/side4.png
Binary files differ
diff --git a/examples/opengl/textures/images/side5.png b/examples/opengl/textures/images/side5.png
new file mode 100644
index 0000000..fa2f709
--- /dev/null
+++ b/examples/opengl/textures/images/side5.png
Binary files differ
diff --git a/examples/opengl/textures/images/side6.png b/examples/opengl/textures/images/side6.png
new file mode 100644
index 0000000..97141e4
--- /dev/null
+++ b/examples/opengl/textures/images/side6.png
Binary files differ
diff --git a/examples/opengl/textures/main.cpp b/examples/opengl/textures/main.cpp
new file mode 100644
index 0000000..5129cda
--- /dev/null
+++ b/examples/opengl/textures/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(textures);
+
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/opengl/textures/textures.pro b/examples/opengl/textures/textures.pro
new file mode 100644
index 0000000..cd98a68
--- /dev/null
+++ b/examples/opengl/textures/textures.pro
@@ -0,0 +1,13 @@
+HEADERS = glwidget.h \
+ window.h
+SOURCES = glwidget.cpp \
+ main.cpp \
+ window.cpp
+RESOURCES = textures.qrc
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS textures.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
+INSTALLS += target sources
diff --git a/examples/opengl/textures/textures.qrc b/examples/opengl/textures/textures.qrc
new file mode 100644
index 0000000..efa9e9c
--- /dev/null
+++ b/examples/opengl/textures/textures.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/side1.png</file>
+ <file>images/side2.png</file>
+ <file>images/side3.png</file>
+ <file>images/side4.png</file>
+ <file>images/side5.png</file>
+ <file>images/side6.png</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/textures/window.cpp b/examples/opengl/textures/window.cpp
new file mode 100644
index 0000000..a974e68
--- /dev/null
+++ b/examples/opengl/textures/window.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "glwidget.h"
+#include "window.h"
+
+Window::Window()
+{
+ QGridLayout *mainLayout = new QGridLayout;
+
+ glWidgets[0][0] = 0;
+
+ for (int i = 0; i < NumRows; ++i) {
+ for (int j = 0; j < NumColumns; ++j) {
+ QColor clearColor;
+ clearColor.setHsv(((i * NumColumns) + j) * 255
+ / (NumRows * NumColumns - 1),
+ 255, 63);
+
+ glWidgets[i][j] = new GLWidget(0, glWidgets[0][0]);
+ glWidgets[i][j]->setClearColor(clearColor);
+ glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
+ mainLayout->addWidget(glWidgets[i][j], i, j);
+
+ connect(glWidgets[i][j], SIGNAL(clicked()),
+ this, SLOT(setCurrentGlWidget()));
+ }
+ }
+ setLayout(mainLayout);
+
+ currentGlWidget = glWidgets[0][0];
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
+ timer->start(20);
+
+ setWindowTitle(tr("Textures"));
+}
+
+void Window::setCurrentGlWidget()
+{
+ currentGlWidget = qobject_cast<GLWidget *>(sender());
+}
+
+void Window::rotateOneStep()
+{
+ if (currentGlWidget)
+ currentGlWidget->rotateBy(+2 * 16, +2 * 16, -1 * 16);
+}
diff --git a/examples/opengl/textures/window.h b/examples/opengl/textures/window.h
new file mode 100644
index 0000000..50bb7f0
--- /dev/null
+++ b/examples/opengl/textures/window.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+class GLWidget;
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private slots:
+ void setCurrentGlWidget();
+ void rotateOneStep();
+
+private:
+ enum { NumRows = 2, NumColumns = 3 };
+
+ GLWidget *glWidgets[NumRows][NumColumns];
+ GLWidget *currentGlWidget;
+};
+
+#endif