source: trunk/examples/opengl/pbuffers2/glwidget.cpp@ 52

Last change on this file since 52 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 10.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
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.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui/QImage>
43#include "glwidget.h"
44
45#include <math.h>
46
47#ifndef GL_MULTISAMPLE
48#define GL_MULTISAMPLE 0x809D
49#endif
50
51GLWidget::GLWidget(QWidget *parent)
52 : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
53{
54 setWindowTitle(tr("OpenGL pbuffers 2"));
55
56 pbuffer = new QGLPixelBuffer(1024, 1024, format(), this);
57
58 rot_x = rot_y = rot_z = 0.0f;
59 scale = 0.1f;
60 anim = new QTimeLine(750, this);
61 anim->setUpdateInterval(20);
62 connect(anim, SIGNAL(valueChanged(qreal)), SLOT(animate(qreal)));
63 connect(anim, SIGNAL(finished()), SLOT(animFinished()));
64
65 svg_renderer = new QSvgRenderer(QLatin1String(":/res/bubbles.svg"), this);
66 connect(svg_renderer, SIGNAL(repaintNeeded()), this, SLOT(draw()));
67
68 logo = QImage(":/res/designer.png");
69 logo = logo.convertToFormat(QImage::Format_ARGB32);
70
71 makeCurrent(); // need a current context to create the display list
72 tile_list = glGenLists(1);
73 glNewList(tile_list, GL_COMPILE);
74 glBegin(GL_QUADS);
75 {
76 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
77 glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
78 glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
79 glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
80
81 glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
82 glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
83 glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
84 glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
85
86 glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
87 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
88 glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
89 glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
90
91 glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
92 glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
93 glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
94 glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
95
96 glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
97 glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
98 glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
99 glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
100
101 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
102 glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
103 glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
104 glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
105}
106 glEnd();
107 glEndList();
108
109 wave = new GLfloat[logo.width()*logo.height()];
110 memset(wave, 0, logo.width()*logo.height());
111 startTimer(30); // wave timer
112
113 pbuffer->makeCurrent();
114 dynamicTexture = pbuffer->generateDynamicTexture();
115
116 // bind the dynamic texture to the pbuffer - this is a no-op under X11
117 hasDynamicTextureUpdate = pbuffer->bindToDynamicTexture(dynamicTexture);
118}