summaryrefslogtreecommitdiffstats
path: root/examples/opengl/legacy/pbuffers2
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/legacy/pbuffers2')
-rw-r--r--examples/opengl/legacy/pbuffers2/bubbles.svg215
-rw-r--r--examples/opengl/legacy/pbuffers2/designer.pngbin0 -> 2810 bytes
-rw-r--r--examples/opengl/legacy/pbuffers2/glwidget.cpp325
-rw-r--r--examples/opengl/legacy/pbuffers2/glwidget.h84
-rw-r--r--examples/opengl/legacy/pbuffers2/main.cpp61
-rw-r--r--examples/opengl/legacy/pbuffers2/pbuffers2.pro15
-rw-r--r--examples/opengl/legacy/pbuffers2/pbuffers2.qrc6
7 files changed, 706 insertions, 0 deletions
diff --git a/examples/opengl/legacy/pbuffers2/bubbles.svg b/examples/opengl/legacy/pbuffers2/bubbles.svg
new file mode 100644
index 0000000000..51730124a2
--- /dev/null
+++ b/examples/opengl/legacy/pbuffers2/bubbles.svg
@@ -0,0 +1,215 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg width="20cm" height="15cm" viewBox="0 0 800 600"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink/"
+ baseProfile="tiny" version="1.2">
+ <title>Spheres</title>
+ <desc>Semi-transparent bubbles on a colored background.</desc>
+ <defs>
+ <!-- Create radial gradients for each bubble. -->
+ <radialGradient id="blueBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#cdcdff" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#cdaacd" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="redBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#ffcdcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#bbbb99" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="greenBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#cdffcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#99aaaa" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="yellowBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#ffffcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#bbbbaa" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="background" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="400" fx="250" fy="250">
+ <stop offset="0%" stop-color="#ffffee" />
+ <stop offset="100%" stop-color="#ccccaa" />
+ </radialGradient>
+ <linearGradient id="surface" gradientUnits="userSpaceOnUse"
+ x1="-100" y1="200" x2="400" y2="200">
+ <stop offset="0%" stop-color="#ffffcc" />
+ <stop offset="100%" stop-color="#bbbb88" />
+ </linearGradient>
+
+ <!-- Create radial gradients for each circle to make them look like
+ spheres. -->
+ <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="blue" />
+ <stop offset="100%" stop-color="#222244" />
+ </radialGradient>
+ <radialGradient id="redSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="red" />
+ <stop offset="100%" stop-color="#442222" />
+ </radialGradient>
+ <radialGradient id="greenSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="green" />
+ <stop offset="100%" stop-color="#113311" />
+ </radialGradient>
+ <radialGradient id="yellowSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="yellow" />
+ <stop offset="100%" stop-color="#444422" />
+ </radialGradient>
+ <radialGradient id="shadowGrad" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="50">
+ <stop offset="0%" stop-color="black" stop-opacity="1.0" />
+ <stop offset="100%" stop-color="black" stop-opacity="0.0" />
+ </radialGradient>
+
+ <!-- Define a shadow for each sphere. -->
+ <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" />
+ <g id="bubble">
+ <circle fill="black" cx="0" cy="0" r="50" />
+ <circle fill="#a6ce39" cx="0" cy="0" r="33" />
+ <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
+ L -11,22 L -1,12 Z" />
+ <circle cx="0" cy="0" r="100" />
+ </g>
+ </defs>
+ <g>
+ <rect fill="url(#background)" x="0" y="0" width="800" height="600" />
+ </g>
+
+ <g transform="translate(200,700)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="10s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(315,700)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="7s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(80,700)">
+ <g transform="scale(0.65,0.65)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="5s" dur="9s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(255,700)">
+ <g transform="scale(0.3,0.3)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="2s" dur="6s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(565,700)">
+ <g transform="scale(0.4,0.4)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="4s" dur="8s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(715,700)">
+ <g transform="scale(0.6,0.6)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="4s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(645,700)">
+ <g transform="scale(0.375,0.375)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="0s" dur="11s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(555,700)">
+ <g transform="scale(0.9,0.9)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="7.5s" fill="freeze" repeatCount="indefinite" />
+ </g>
+
+ <g transform="translate(360,700)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="6s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(215,700)">
+ <g transform="scale(0.45,0.45)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="5.5s" dur="7s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(420,700)">
+ <g transform="scale(0.75,0.75)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="9s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(815,700)">
+ <g transform="scale(0.6,0.6)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="2s" dur="9.5s" fill="freeze" repeatCount="indefinite" />
+ </g>
+
+ <g transform="translate(225,375)" >
+ <g transform="scale(1.0,0.5)" >
+ <path d="M 0 0 L 350 0 L 450 450 L -100 450 z"
+ fill="url(#surface)" stroke="none" />
+ </g>
+ </g>
+ <g transform="translate(200,0)" >
+ <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" >
+ <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" />
+ <circle fill="black" cx="0" cy="0" r="50" />
+ <circle fill="#a6ce39" cx="0" cy="0" r="33" />
+ <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
+ L -11,22 L -1,12 Z" />
+ <animateTransform attributeName="transform" type="rotate" additive="sum" values="0; 360"
+ begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(200,375)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" />
+ </g>
+ <g transform="translate(315,440)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#redSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(80,475)">
+ <g transform="scale(0.65,0.65)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#greenSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(255,525)">
+ <g transform="scale(0.3,0.3)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#yellowSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/examples/opengl/legacy/pbuffers2/designer.png b/examples/opengl/legacy/pbuffers2/designer.png
new file mode 100644
index 0000000000..4f32d57496
--- /dev/null
+++ b/examples/opengl/legacy/pbuffers2/designer.png
Binary files differ
diff --git a/examples/opengl/legacy/pbuffers2/glwidget.cpp b/examples/opengl/legacy/pbuffers2/glwidget.cpp
new file mode 100644
index 0000000000..de30bb8b21
--- /dev/null
+++ b/examples/opengl/legacy/pbuffers2/glwidget.cpp
@@ -0,0 +1,325 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QImage>
+#include "glwidget.h"
+
+#include <math.h>
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+{
+ setWindowTitle(tr("OpenGL pbuffers 2"));
+
+ pbuffer = new QGLPixelBuffer(1024, 1024, format(), this);
+
+ rot_x = rot_y = rot_z = 0.0f;
+ scale = 0.1f;
+ anim = new QTimeLine(750, this);
+ anim->setUpdateInterval(20);
+ connect(anim, SIGNAL(valueChanged(qreal)), SLOT(animate(qreal)));
+ connect(anim, SIGNAL(finished()), SLOT(animFinished()));
+
+ svg_renderer = new QSvgRenderer(QLatin1String(":/res/bubbles.svg"), this);
+ connect(svg_renderer, SIGNAL(repaintNeeded()), this, SLOT(draw()));
+
+ logo = QImage(":/res/designer.png");
+ logo = logo.convertToFormat(QImage::Format_ARGB32);
+
+ makeCurrent(); // need a current context to create the display list
+ tile_list = glGenLists(1);
+ glNewList(tile_list, GL_COMPILE);
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
+
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
+
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
+
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
+
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
+
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
+}
+ glEnd();
+ glEndList();
+
+ wave = new GLfloat[logo.width()*logo.height()];
+ memset(wave, 0, logo.width()*logo.height());
+ startTimer(30); // wave timer
+
+ pbuffer->makeCurrent();
+ dynamicTexture = pbuffer->generateDynamicTexture();
+
+ // bind the dynamic texture to the pbuffer - this is a no-op under X11
+ hasDynamicTextureUpdate = pbuffer->bindToDynamicTexture(dynamicTexture);
+}
+
+GLWidget::~GLWidget()
+{
+ delete[] wave;
+ glDeleteLists(tile_list, 1);
+ pbuffer->releaseFromDynamicTexture();
+ glDeleteTextures(1, &dynamicTexture);
+ delete pbuffer;
+}
+
+void GLWidget::paintEvent(QPaintEvent *)
+{
+ draw();
+}
+
+void GLWidget::draw()
+{
+ QPainter p(this); // used for text overlay
+
+ // save the GL state set for QPainter
+ p.beginNativePainting();
+ saveGLState();
+
+ // render the 'bubbles.svg' file into our pbuffer
+ QPainter pbuffer_painter(pbuffer);
+ svg_renderer->render(&pbuffer_painter);
+ pbuffer_painter.end();
+ glFlush();
+
+ if (!hasDynamicTextureUpdate)
+ pbuffer->updateDynamicTexture(dynamicTexture);
+
+ makeCurrent();
+ // draw into the GL widget
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1, 1, -1, 1, 10, 100);
+ glTranslatef(0.0f, 0.0f, -15.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glViewport(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio());
+
+ glBindTexture(GL_TEXTURE_2D, dynamicTexture);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_MULTISAMPLE);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ // draw background
+ glPushMatrix();
+ glScalef(1.7f, 1.7f, 1.7f);
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ glCallList(tile_list);
+ glPopMatrix();
+
+ const int w = logo.width();
+ const int h = logo.height();
+
+ glRotatef(rot_x, 1.0f, 0.0f, 0.0f);
+ glRotatef(rot_y, 0.0f, 1.0f, 0.0f);
+ glRotatef(rot_z, 0.0f, 0.0f, 1.0f);
+ glScalef(scale/w, scale/w, scale/w);
+
+ glDepthFunc(GL_LESS);
+ glEnable(GL_DEPTH_TEST);
+
+ // draw the Qt icon
+ glTranslatef(-w+1, -h+1, 0.0f);
+ for (int y=h-1; y>=0; --y) {
+ uint *p = (uint*) logo.scanLine(y);
+ uint *end = p + w;
+ int x = 0;
+ while (p < end) {
+ glColor4ub(qRed(*p), qGreen(*p), qBlue(*p), uchar(qAlpha(*p)*.9));
+ glTranslatef(0.0f, 0.0f, wave[y*w+x]);
+ if (qAlpha(*p) > 128)
+ glCallList(tile_list);
+ glTranslatef(0.0f, 0.0f, -wave[y*w+x]);
+ glTranslatef(2.0f, 0.0f, 0.0f);
+ ++x;
+ ++p;
+ }
+ glTranslatef(-w*2.0f, 2.0f, 0.0f);
+ }
+
+ // restore the GL state that QPainter expects
+ restoreGLState();
+ p.endNativePainting();
+
+ // draw the overlayed text using QPainter
+ p.setPen(QColor(197, 197, 197, 157));
+ p.setBrush(QColor(197, 197, 197, 127));
+ p.drawRect(QRect(0, 0, width(), 50));
+ p.setPen(Qt::black);
+ p.setBrush(Qt::NoBrush);
+ const QString str1(tr("A simple OpenGL pbuffer example."));
+ const QString str2(tr("Use the mouse wheel to zoom, press buttons and move mouse to rotate, double-click to flip."));
+ QFontMetrics fm(p.font());
+ p.drawText(width()/2 - fm.width(str1)/2, 20, str1);
+ p.drawText(width()/2 - fm.width(str2)/2, 20 + fm.lineSpacing(), str2);
+}
+
+void GLWidget::mousePressEvent(QMouseEvent *e)
+{
+ anchor = e->pos();
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *e)
+{
+ QPoint diff = e->pos() - anchor;
+ if (e->buttons() & Qt::LeftButton) {
+ rot_x += diff.y()/5.0f;
+ rot_y += diff.x()/5.0f;
+ } else if (e->buttons() & Qt::RightButton) {
+ rot_z += diff.x()/5.0f;
+ }
+
+ anchor = e->pos();
+ draw();
+}
+
+void GLWidget::wheelEvent(QWheelEvent *e)
+{
+ e->delta() > 0 ? scale += scale*0.1f : scale -= scale*0.1f;
+ draw();
+}
+
+void GLWidget::mouseDoubleClickEvent(QMouseEvent *)
+{
+ anim->start();
+}
+
+void GLWidget::animate(qreal val)
+{
+ rot_y = val * 180;
+ draw();
+}
+
+void GLWidget::animFinished()
+{
+ if (anim->direction() == QTimeLine::Forward)
+ anim->setDirection(QTimeLine::Backward);
+ else
+ anim->setDirection(QTimeLine::Forward);
+}
+
+void GLWidget::saveGLState()
+{
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+}
+
+void GLWidget::restoreGLState()
+{
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+ glPopAttrib();
+}
+
+#define PI 3.14159
+
+void GLWidget::timerEvent(QTimerEvent *)
+{
+ if (QApplication::mouseButtons() != 0)
+ return;
+
+ static bool scale_in = true;
+
+ if (scale_in && scale > 35.0f)
+ scale_in = false;
+ else if (!scale_in && scale < .5f)
+ scale_in = true;
+
+ scale = scale_in ? scale + scale*0.01f : scale-scale*0.01f;
+ rot_z += 0.3f;
+ rot_x += 0.1f;
+
+ int dx, dy; // disturbance point
+ float s, v, W, t;
+ int i, j;
+ static float wt[128][128];
+ const int width = logo.width();
+ const int AMP = 5;
+
+ dx = dy = width >> 1;
+
+ W = .3f;
+ v = -4; // wave speed
+
+ for (i = 0; i < width; ++i) {
+ for ( j = 0; j < width; ++j) {
+ s = sqrt((double) ((j - dx) * (j - dx) + (i - dy) * (i - dy)));
+ wt[i][j] += 0.1f;
+ t = s / v;
+ if (s != 0)
+ wave[i*width + j] = AMP * sin(2 * PI * W * (wt[i][j] + t)) / (0.2*(s + 2));
+ else
+ wave[i*width + j] = AMP * sin(2 * PI * W * (wt[i][j] + t));
+ }
+ }
+}
diff --git a/examples/opengl/legacy/pbuffers2/glwidget.h b/examples/opengl/legacy/pbuffers2/glwidget.h
new file mode 100644
index 0000000000..20dd796a48
--- /dev/null
+++ b/examples/opengl/legacy/pbuffers2/glwidget.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtOpenGL>
+#include <QImage>
+#include <QTimeLine>
+#include <QSvgRenderer>
+
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent);
+ ~GLWidget();
+
+ void saveGLState();
+ void restoreGLState();
+
+ void paintEvent(QPaintEvent *);
+ void mousePressEvent(QMouseEvent *);
+ void mouseDoubleClickEvent(QMouseEvent *);
+ void mouseMoveEvent(QMouseEvent *);
+ void timerEvent(QTimerEvent *);
+ void wheelEvent(QWheelEvent *);
+
+public slots:
+ void animate(qreal);
+ void animFinished();
+ void draw();
+
+private:
+ QPoint anchor;
+ float scale;
+ float rot_x, rot_y, rot_z;
+ GLuint tile_list;
+ GLfloat *wave;
+ bool hasDynamicTextureUpdate;
+
+ QImage logo;
+ QTimeLine *anim;
+ QSvgRenderer *svg_renderer;
+
+ GLuint dynamicTexture;
+ QGLPixelBuffer *pbuffer;
+};
+
diff --git a/examples/opengl/legacy/pbuffers2/main.cpp b/examples/opengl/legacy/pbuffers2/main.cpp
new file mode 100644
index 0000000000..79fd88a3c8
--- /dev/null
+++ b/examples/opengl/legacy/pbuffers2/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QMessageBox>
+#include "glwidget.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(pbuffers2);
+
+ QApplication a(argc, argv);
+ GLWidget widget(0);
+ widget.resize(640, 480);
+ widget.makeCurrent();
+ if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
+ QMessageBox::information(0, "OpenGL pbuffers 2",
+ "This system does not support OpenGL/pbuffers.");
+ return -1;
+ }
+ widget.show();
+ return a.exec();
+}
+
diff --git a/examples/opengl/legacy/pbuffers2/pbuffers2.pro b/examples/opengl/legacy/pbuffers2/pbuffers2.pro
new file mode 100644
index 0000000000..f9dd269eea
--- /dev/null
+++ b/examples/opengl/legacy/pbuffers2/pbuffers2.pro
@@ -0,0 +1,15 @@
+QT += opengl svg widgets
+
+HEADERS += glwidget.h
+SOURCES += glwidget.cpp main.cpp
+RESOURCES += pbuffers2.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/pbuffers2
+INSTALLS += target
+
+contains(QT_CONFIG, opengles.) {
+ contains(QT_CONFIG, angle): \
+ warning("Qt was built with ANGLE, which provides only OpenGL ES 2.0 on top of DirectX 9.0c")
+ error("This example requires Qt to be configured with -opengl desktop")
+}
diff --git a/examples/opengl/legacy/pbuffers2/pbuffers2.qrc b/examples/opengl/legacy/pbuffers2/pbuffers2.qrc
new file mode 100644
index 0000000000..986f1ca385
--- /dev/null
+++ b/examples/opengl/legacy/pbuffers2/pbuffers2.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res">
+ <file>bubbles.svg</file>
+ <file>designer.png</file>
+</qresource>
+</RCC>