diff options
Diffstat (limited to 'examples/svg')
-rw-r--r-- | examples/svg/opengl/framebufferobject/bubbles.svg | 215 | ||||
-rw-r--r-- | examples/svg/opengl/framebufferobject/designer.png | bin | 2810 -> 0 bytes | |||
-rw-r--r-- | examples/svg/opengl/framebufferobject/framebufferobject.pro | 11 | ||||
-rw-r--r-- | examples/svg/opengl/framebufferobject/framebufferobject.qrc | 6 | ||||
-rw-r--r-- | examples/svg/opengl/framebufferobject/glwidget.cpp | 332 | ||||
-rw-r--r-- | examples/svg/opengl/framebufferobject/glwidget.h | 92 | ||||
-rw-r--r-- | examples/svg/opengl/framebufferobject/main.cpp | 71 | ||||
-rw-r--r-- | examples/svg/opengl/opengl.pro | 2 | ||||
-rw-r--r-- | examples/svg/svg.pro | 2 | ||||
-rw-r--r-- | examples/svg/svgviewer/main.cpp | 3 | ||||
-rw-r--r-- | examples/svg/svgviewer/svgview.cpp | 4 |
11 files changed, 2 insertions, 736 deletions
diff --git a/examples/svg/opengl/framebufferobject/bubbles.svg b/examples/svg/opengl/framebufferobject/bubbles.svg deleted file mode 100644 index 5173012..0000000 --- a/examples/svg/opengl/framebufferobject/bubbles.svg +++ /dev/null @@ -1,215 +0,0 @@ -<?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/svg/opengl/framebufferobject/designer.png b/examples/svg/opengl/framebufferobject/designer.png Binary files differdeleted file mode 100644 index 4f32d57..0000000 --- a/examples/svg/opengl/framebufferobject/designer.png +++ /dev/null diff --git a/examples/svg/opengl/framebufferobject/framebufferobject.pro b/examples/svg/opengl/framebufferobject/framebufferobject.pro deleted file mode 100644 index d180d4d..0000000 --- a/examples/svg/opengl/framebufferobject/framebufferobject.pro +++ /dev/null @@ -1,11 +0,0 @@ -qtConfig(opengles2):error("This example is written for OpenGL 1.x") - -QT += widgets opengl svg - -HEADERS += glwidget.h -SOURCES += glwidget.cpp main.cpp -RESOURCES += framebufferobject.qrc - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/svg/opengl/framebufferobject -INSTALLS += target diff --git a/examples/svg/opengl/framebufferobject/framebufferobject.qrc b/examples/svg/opengl/framebufferobject/framebufferobject.qrc deleted file mode 100644 index 986f1ca..0000000 --- a/examples/svg/opengl/framebufferobject/framebufferobject.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/res"> - <file>bubbles.svg</file> - <file>designer.png</file> -</qresource> -</RCC> diff --git a/examples/svg/opengl/framebufferobject/glwidget.cpp b/examples/svg/opengl/framebufferobject/glwidget.cpp deleted file mode 100644 index 03eed6c..0000000 --- a/examples/svg/opengl/framebufferobject/glwidget.cpp +++ /dev/null @@ -1,332 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <qmath.h> -#include "glwidget.h" - -#ifndef GL_MULTISAMPLE -#define GL_MULTISAMPLE 0x809D -#endif - -GLWidget::GLWidget(QWidget *parent) - : QGLWidget(QGLFormat(QGL::SampleBuffers|QGL::AlphaChannel), parent) -{ - setWindowTitle(tr("OpenGL framebuffer objects")); - makeCurrent(); - - if (QGLFramebufferObject::hasOpenGLFramebufferBlit()) { - QGLFramebufferObjectFormat format; - format.setSamples(4); - format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); - - render_fbo = new QGLFramebufferObject(512, 512, format); - texture_fbo = new QGLFramebufferObject(512, 512); - } else { - render_fbo = new QGLFramebufferObject(1024, 1024); - texture_fbo = render_fbo; - } - - 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); - - 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 -} - -GLWidget::~GLWidget() -{ - delete[] wave; - glDeleteLists(tile_list, 1); - delete texture_fbo; - if (render_fbo != texture_fbo) - delete render_fbo; -} - -void GLWidget::paintEvent(QPaintEvent *) -{ - draw(); -} - -void GLWidget::draw() -{ - QPainter p(this); // used for text overlay - - // save the GL state set for QPainter - saveGLState(); - - // render the 'bubbles.svg' file into our framebuffer object - QPainter fbo_painter(render_fbo); - svg_renderer->render(&fbo_painter); - fbo_painter.end(); - - if (render_fbo != texture_fbo) { - QRect rect(0, 0, render_fbo->width(), render_fbo->height()); - QGLFramebufferObject::blitFramebuffer(texture_fbo, rect, - render_fbo, rect); - } - - // 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(), height()); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glBindTexture(GL_TEXTURE_2D, texture_fbo->texture()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glEnable(GL_TEXTURE_2D); - glEnable(GL_MULTISAMPLE); - glEnable(GL_CULL_FACE); - - // 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(); - - // 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 framebuffer object 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.horizontalAdvance(str1)/2, 20, str1); - p.drawText(width()/2 - fm.horizontalAdvance(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->angleDelta().y() > 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(); -} - -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 ? 1.01f : 0.99f; - rot_z += 0.3f; - rot_x += 0.1f; - - static float wt = 0.0; - wt += 0.1f; - - const int width = logo.width(); - const int dx = width >> 1, dy = dx; // disturbance point - const float W = .3f; - const float v = -4; // wave speed - const int AMP = 5; - - for (int i = 0; i < width; ++i) { - for (int j = 0; j < width; ++j) { - const float s = hypot(j - dx, i - dy); - const double raw = AMP * sin(2 * M_PI * W * (wt + s / v)); - if (s != 0) - wave[i * width + j] = raw / (0.2 * (s + 2)); - else - wave[i * width + j] = raw; - } - } -} diff --git a/examples/svg/opengl/framebufferobject/glwidget.h b/examples/svg/opengl/framebufferobject/glwidget.h deleted file mode 100644 index 15cc7e7..0000000 --- a/examples/svg/opengl/framebufferobject/glwidget.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 *) override; - void mousePressEvent(QMouseEvent *) override; - void mouseDoubleClickEvent(QMouseEvent *) override; - void mouseMoveEvent(QMouseEvent *) override; - void timerEvent(QTimerEvent *) override; - void wheelEvent(QWheelEvent *) override; - -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; - - QImage logo; - QTimeLine *anim; - QSvgRenderer *svg_renderer; - QGLFramebufferObject *render_fbo; - QGLFramebufferObject *texture_fbo; -}; - diff --git a/examples/svg/opengl/framebufferobject/main.cpp b/examples/svg/opengl/framebufferobject/main.cpp deleted file mode 100644 index 78b5f4e..0000000 --- a/examples/svg/opengl/framebufferobject/main.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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(framebufferobject); - - QApplication a(argc, argv); - if (!QGLFormat::hasOpenGL() || !QGLFramebufferObject::hasOpenGLFramebufferObjects()) { - QMessageBox::information(0, "OpenGL framebuffer objects", - "This system does not support OpenGL/framebuffer objects."); - return -1; - } - - GLWidget widget(0); - widget.resize(640, 480); - widget.show(); - return a.exec(); -} - diff --git a/examples/svg/opengl/opengl.pro b/examples/svg/opengl/opengl.pro deleted file mode 100644 index 82c616c..0000000 --- a/examples/svg/opengl/opengl.pro +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE = subdirs -qtHaveModule(widgets):!qtConfig(opengles2):!qtConfig(dynamicgl): SUBDIRS += framebufferobject diff --git a/examples/svg/svg.pro b/examples/svg/svg.pro index 410415b..4303b77 100644 --- a/examples/svg/svg.pro +++ b/examples/svg/svg.pro @@ -2,5 +2,3 @@ TEMPLATE = subdirs qtHaveModule(widgets): SUBDIRS += embeddedsvgviewer svggenerator svgviewer SUBDIRS += embedded richtext draganddrop network - -qtHaveModule(opengl):!qtConfig(opengles2): SUBDIRS += opengl diff --git a/examples/svg/svgviewer/main.cpp b/examples/svg/svgviewer/main.cpp index 5eb76c8..2233723 100644 --- a/examples/svg/svgviewer/main.cpp +++ b/examples/svg/svgviewer/main.cpp @@ -52,9 +52,6 @@ #include <QCommandLineParser> #include <QCommandLineOption> #include <QStringList> -#ifndef QT_NO_OPENGL -#include <QGLFormat> -#endif #include "mainwindow.h" diff --git a/examples/svg/svgviewer/svgview.cpp b/examples/svg/svgviewer/svgview.cpp index e87d0ea..6674f87 100644 --- a/examples/svg/svgviewer/svgview.cpp +++ b/examples/svg/svgviewer/svgview.cpp @@ -59,7 +59,7 @@ #include <qmath.h> #ifndef QT_NO_OPENGL -#include <QGLWidget> +#include <QOpenGLWidget> #endif SvgView::SvgView(QWidget *parent) @@ -146,7 +146,7 @@ void SvgView::setRenderer(RendererType type) if (m_renderer == OpenGL) { #ifndef QT_NO_OPENGL - setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); + setViewport(new QOpenGLWidget); #endif } else { setViewport(new QWidget); |