diff options
Diffstat (limited to 'examples/opengl')
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.cpp | 27 | ||||
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.h | 2 | ||||
-rw-r--r-- | examples/opengl/legacy/framebufferobject2/glwidget.cpp | 5 | ||||
-rw-r--r-- | examples/opengl/legacy/grabber/glwidget.cpp | 16 | ||||
-rw-r--r-- | examples/opengl/legacy/pbuffers2/glwidget.cpp | 35 | ||||
-rw-r--r-- | examples/opengl/legacy/samplebuffers/glwidget.cpp | 26 | ||||
-rw-r--r-- | examples/opengl/qopenglwidget/glwidget.cpp | 32 | ||||
-rw-r--r-- | examples/opengl/qopenglwidget/main.cpp | 4 | ||||
-rw-r--r-- | examples/opengl/qopenglwindow/background.frag | 2 | ||||
-rw-r--r-- | examples/opengl/threadedqopenglwidget/glwidget.cpp | 26 |
10 files changed, 88 insertions, 87 deletions
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index dc48cc4b76..048190d766 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -93,6 +93,8 @@ HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *scre void HelloWindow::exposeEvent(QExposeEvent *) { m_renderer->setAnimating(this, isExposed()); + if (isExposed()) + m_renderer->render(); } void HelloWindow::mousePressEvent(QMouseEvent *) @@ -276,21 +278,20 @@ void Renderer::createGeometry() extrude(x4, y4, y4, x4); extrude(y4, x4, y3, x3); - const qreal Pi = 3.14159f; const int NumSectors = 100; - + const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors; for (int i = 0; i < NumSectors; ++i) { - qreal angle1 = (i * 2 * Pi) / NumSectors; - qreal x5 = 0.30 * qSin(angle1); - qreal y5 = 0.30 * qCos(angle1); - qreal x6 = 0.20 * qSin(angle1); - qreal y6 = 0.20 * qCos(angle1); - - qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors; - qreal x7 = 0.20 * qSin(angle2); - qreal y7 = 0.20 * qCos(angle2); - qreal x8 = 0.30 * qSin(angle2); - qreal y8 = 0.30 * qCos(angle2); + qreal angle = i * sectorAngle; + qreal x5 = 0.30 * qSin(angle); + qreal y5 = 0.30 * qCos(angle); + qreal x6 = 0.20 * qSin(angle); + qreal y6 = 0.20 * qCos(angle); + + angle += sectorAngle; + qreal x7 = 0.20 * qSin(angle); + qreal y7 = 0.20 * qCos(angle); + qreal x8 = 0.30 * qSin(angle); + qreal y8 = 0.30 * qCos(angle); quad(x5, y5, x6, y6, x7, y7, x8, y8); diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h index 1372152e93..e92e45a125 100644 --- a/examples/opengl/hellowindow/hellowindow.h +++ b/examples/opengl/hellowindow/hellowindow.h @@ -70,7 +70,7 @@ public: void setAnimating(HelloWindow *window, bool animating); -private slots: +public slots: void render(); private: diff --git a/examples/opengl/legacy/framebufferobject2/glwidget.cpp b/examples/opengl/legacy/framebufferobject2/glwidget.cpp index ac8deddd1f..f14d31aff6 100644 --- a/examples/opengl/legacy/framebufferobject2/glwidget.cpp +++ b/examples/opengl/legacy/framebufferobject2/glwidget.cpp @@ -50,8 +50,7 @@ #include "glwidget.h" #include <QtGui/QImage> - -#include <math.h> +#include <qmath.h> static GLint cubeArray[][3] = { {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, @@ -253,6 +252,6 @@ void GLWidget::drawCube(int i, GLfloat z, GLfloat rotation, GLfloat jmp, GLfloat xOffs[i] = xOffs[i] > 1.0f ? 1.0f : -1.0f; } xOffs[i] += xInc[i]; - yOffs[i] = qAbs(cos((-3.141592f * jmp) * xOffs[i]) * amp) - 1; + yOffs[i] = qAbs(cos((-GLfloat(M_PI) * jmp) * xOffs[i]) * amp) - 1; rot[i] += rotation; } diff --git a/examples/opengl/legacy/grabber/glwidget.cpp b/examples/opengl/legacy/grabber/glwidget.cpp index 958b8055cd..6be4d30597 100644 --- a/examples/opengl/legacy/grabber/glwidget.cpp +++ b/examples/opengl/legacy/grabber/glwidget.cpp @@ -52,8 +52,7 @@ #include <QMouseEvent> #include <QTimer> - -#include <math.h> +#include <qmath.h> GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) @@ -190,8 +189,6 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, GLdouble outerRadius, GLdouble thickness, GLdouble toothSize, GLint toothCount) { - const double Pi = 3.14159265358979323846; - GLuint list = glGenLists(1); glNewList(list, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, reflectance); @@ -199,7 +196,8 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, GLdouble r0 = innerRadius; GLdouble r1 = outerRadius - toothSize / 2.0; GLdouble r2 = outerRadius + toothSize / 2.0; - GLdouble delta = (2.0 * Pi / toothCount) / 4.0; + GLdouble toothAngle = 2 * M_PI / toothCount; + GLdouble delta = toothAngle / 4.0; GLdouble z = thickness / 2.0; glShadeModel(GL_FLAT); @@ -211,7 +209,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUAD_STRIP); for (int j = 0; j <= toothCount; ++j) { - GLdouble angle = 2.0 * Pi * j / toothCount; + GLdouble angle = j * toothAngle; glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z); glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z); glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z); @@ -221,7 +219,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUADS); for (int j = 0; j < toothCount; ++j) { - GLdouble angle = 2.0 * Pi * j / toothCount; + GLdouble angle = j * toothAngle; glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z); glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta), sign * z); glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta), sign * z); @@ -233,7 +231,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUAD_STRIP); for (int i = 0; i < toothCount; ++i) { for (int j = 0; j < 2; ++j) { - GLdouble angle = 2.0 * Pi * (i + j / 2.0) / toothCount; + GLdouble angle = (i + j / 2.0) * toothAngle; GLdouble s1 = r1; GLdouble s2 = r2; if (j == 1) @@ -257,7 +255,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUAD_STRIP); for (int i = 0; i <= toothCount; ++i) { - GLdouble angle = i * 2.0 * Pi / toothCount; + GLdouble angle = i * toothAngle; glNormal3d(-cos(angle), -sin(angle), 0.0); glVertex3d(r0 * cos(angle), r0 * sin(angle), +z); glVertex3d(r0 * cos(angle), r0 * sin(angle), -z); diff --git a/examples/opengl/legacy/pbuffers2/glwidget.cpp b/examples/opengl/legacy/pbuffers2/glwidget.cpp index c99f9e40fa..c710d03cab 100644 --- a/examples/opengl/legacy/pbuffers2/glwidget.cpp +++ b/examples/opengl/legacy/pbuffers2/glwidget.cpp @@ -49,10 +49,9 @@ ****************************************************************************/ #include <QtGui/QImage> +#include <qmath.h> #include "glwidget.h" -#include <math.h> - #ifndef GL_MULTISAMPLE #define GL_MULTISAMPLE 0x809D #endif @@ -291,8 +290,6 @@ void GLWidget::restoreGLState() glPopAttrib(); } -#define PI 3.14159 - void GLWidget::timerEvent(QTimerEvent *) { if (QApplication::mouseButtons() != 0) @@ -305,31 +302,27 @@ void GLWidget::timerEvent(QTimerEvent *) else if (!scale_in && scale < .5f) scale_in = true; - scale = scale_in ? scale + scale*0.01f : scale-scale*0.01f; + scale *= scale_in ? 1.01f : 0.99f; 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]; + static float wt = 0.0; + wt += 0.1f; + const int width = logo.width(); + const int dx = width >> 1, dy = dx; // disturbance point + const float v = -4; // wave speed + const float W = .3f; 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; + 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] = AMP * sin(2 * PI * W * (wt[i][j] + t)) / (0.2*(s + 2)); + wave[i * width + j] = raw / (0.2 * (s + 2)); else - wave[i*width + j] = AMP * sin(2 * PI * W * (wt[i][j] + t)); + wave[i * width + j] = raw; } } } diff --git a/examples/opengl/legacy/samplebuffers/glwidget.cpp b/examples/opengl/legacy/samplebuffers/glwidget.cpp index 14c59c9143..da30de4d55 100644 --- a/examples/opengl/legacy/samplebuffers/glwidget.cpp +++ b/examples/opengl/legacy/samplebuffers/glwidget.cpp @@ -49,7 +49,7 @@ ****************************************************************************/ #include "glwidget.h" -#include <math.h> +#include <qmath.h> #ifndef GL_MULTISAMPLE #define GL_MULTISAMPLE 0x809D @@ -116,7 +116,6 @@ void GLWidget::timerEvent(QTimerEvent *) void GLWidget::makeObject() { QColor qtGreen(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0)); - const double Pi = 3.14159265358979323846; const int NumSectors = 15; GLdouble x1 = +0.06; GLdouble y1 = -0.14; @@ -130,18 +129,19 @@ void GLWidget::makeObject() list = glGenLists(1); glNewList(list, GL_COMPILE); { + const double sectorAngle = 2 * M_PI / NumSectors; for (int i = 0; i < NumSectors; ++i) { - double angle1 = (i * 2 * Pi) / NumSectors; - GLdouble x5 = 0.30 * sin(angle1); - GLdouble y5 = 0.30 * cos(angle1); - GLdouble x6 = 0.20 * sin(angle1); - GLdouble y6 = 0.20 * cos(angle1); - - double angle2 = ((i + 1) * 2 * Pi) / NumSectors; - GLdouble x7 = 0.20 * sin(angle2); - GLdouble y7 = 0.20 * cos(angle2); - GLdouble x8 = 0.30 * sin(angle2); - GLdouble y8 = 0.30 * cos(angle2); + double angle = i * sectorAngle; + GLdouble x5 = 0.30 * sin(angle); + GLdouble y5 = 0.30 * cos(angle); + GLdouble x6 = 0.20 * sin(angle); + GLdouble y6 = 0.20 * cos(angle); + + angle += sectorAngle; + GLdouble x7 = 0.20 * sin(angle); + GLdouble y7 = 0.20 * cos(angle); + GLdouble x8 = 0.30 * sin(angle); + GLdouble y8 = 0.30 * cos(angle); qglColor(qtGreen); quad(GL_QUADS, x5, y5, x6, y6, x7, y7, x8, y8); diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp index 21d922d713..40a1258dd5 100644 --- a/examples/opengl/qopenglwidget/glwidget.cpp +++ b/examples/opengl/qopenglwidget/glwidget.cpp @@ -54,13 +54,17 @@ #include <QOpenGLShaderProgram> #include <QOpenGLTexture> #include <QCoreApplication> -#include <math.h> +#include <qmath.h> #include "mainwindow.h" #include "bubble.h" const int bubbleNum = 8; +#ifndef GL_SRGB8_ALPHA8 +#define GL_SRGB8_ALPHA8 0x8C43 +#endif + GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background) : m_mainWindow(mw), m_showBubbles(true), @@ -75,6 +79,8 @@ GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background) m_background(background) { setMinimumSize(300, 250); + if (QCoreApplication::arguments().contains(QStringLiteral("--srgb"))) + setTextureFormat(GL_SRGB8_ALPHA8); } GLWidget::~GLWidget() @@ -449,21 +455,21 @@ void GLWidget::createGeometry() extrude(x4, y4, y4, x4); extrude(y4, x4, y3, x3); - const qreal Pi = 3.14159f; const int NumSectors = 100; + const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors; for (int i = 0; i < NumSectors; ++i) { - qreal angle1 = (i * 2 * Pi) / NumSectors; - qreal x5 = 0.30 * sin(angle1); - qreal y5 = 0.30 * cos(angle1); - qreal x6 = 0.20 * sin(angle1); - qreal y6 = 0.20 * cos(angle1); - - qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors; - qreal x7 = 0.20 * sin(angle2); - qreal y7 = 0.20 * cos(angle2); - qreal x8 = 0.30 * sin(angle2); - qreal y8 = 0.30 * cos(angle2); + qreal angle = i * sectorAngle; + qreal x5 = 0.30 * sin(angle); + qreal y5 = 0.30 * cos(angle); + qreal x6 = 0.20 * sin(angle); + qreal y6 = 0.20 * cos(angle); + + angle += sectorAngle; + qreal x7 = 0.20 * sin(angle); + qreal y7 = 0.20 * cos(angle); + qreal x8 = 0.30 * sin(angle); + qreal y8 = 0.30 * cos(angle); quad(x5, y5, x6, y6, x7, y7, x8, y8); diff --git a/examples/opengl/qopenglwidget/main.cpp b/examples/opengl/qopenglwidget/main.cpp index ea90dca62f..42fc772445 100644 --- a/examples/opengl/qopenglwidget/main.cpp +++ b/examples/opengl/qopenglwidget/main.cpp @@ -69,11 +69,15 @@ int main( int argc, char ** argv ) parser.addVersionOption(); QCommandLineOption multipleSampleOption("multisample", "Multisampling"); parser.addOption(multipleSampleOption); + QCommandLineOption srgbOption("srgb", "Use sRGB Color Space"); + parser.addOption(srgbOption); parser.process(a); QSurfaceFormat format; format.setDepthBufferSize(24); format.setStencilBufferSize(8); + if (parser.isSet(srgbOption)) + format.setColorSpace(QSurfaceFormat::sRGBColorSpace); if (parser.isSet(multipleSampleOption)) format.setSamples(4); QSurfaceFormat::setDefaultFormat(format); diff --git a/examples/opengl/qopenglwindow/background.frag b/examples/opengl/qopenglwindow/background.frag index eecb6d3120..4af85aae8e 100644 --- a/examples/opengl/qopenglwindow/background.frag +++ b/examples/opengl/qopenglwindow/background.frag @@ -1,4 +1,4 @@ -#define M_PI 3.1415926535897932384626433832795 +#define M_PI 3.14159265358979323846 #define SPEED 10000.0 uniform int currentTime; diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp index f9738db2e5..cc528a734a 100644 --- a/examples/opengl/threadedqopenglwidget/glwidget.cpp +++ b/examples/opengl/threadedqopenglwidget/glwidget.cpp @@ -49,7 +49,7 @@ ****************************************************************************/ #include "glwidget.h" -#include <math.h> +#include <qmath.h> #include <QGuiApplication> GLWidget::GLWidget(QWidget *parent) @@ -282,21 +282,21 @@ void Renderer::createGeometry() extrude(x4, y4, y4, x4); extrude(y4, x4, y3, x3); - const qreal Pi = 3.14159f; const int NumSectors = 100; + const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors; for (int i = 0; i < NumSectors; ++i) { - qreal angle1 = (i * 2 * Pi) / NumSectors; - qreal x5 = 0.30 * sin(angle1); - qreal y5 = 0.30 * cos(angle1); - qreal x6 = 0.20 * sin(angle1); - qreal y6 = 0.20 * cos(angle1); - - qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors; - qreal x7 = 0.20 * sin(angle2); - qreal y7 = 0.20 * cos(angle2); - qreal x8 = 0.30 * sin(angle2); - qreal y8 = 0.30 * cos(angle2); + qreal angle = i * sectorAngle; + qreal x5 = 0.30 * sin(angle); + qreal y5 = 0.30 * cos(angle); + qreal x6 = 0.20 * sin(angle); + qreal y6 = 0.20 * cos(angle); + + angle += sectorAngle; + qreal x7 = 0.20 * sin(angle); + qreal y7 = 0.20 * cos(angle); + qreal x8 = 0.30 * sin(angle); + qreal y8 = 0.30 * cos(angle); quad(x5, y5, x6, y6, x7, y7, x8, y8); |