blob: e4a889f441e28410d7dcfa90ae34db8dbd873fd0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtQuick3D documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** 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 Technology Preview License Agreement accompanying
** this package.
**
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of this
** file.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\example teapot
\title Teapot Example
The Teapot example shows how Qt/3D can be used to draw a simple
teapot object with a perspective camera view in C++. There is
also a \l{Teapot Example in QML/3D}{QML/3D version} of the teapot
example.
We start by defining a class that inherits from QGLView, which
provides some basic scene setup logic and 3D camera navigation:
\snippet teapot/teapotview.h class-defn
\dots
\quotefromfile teapot/main.cpp
\skipuntil [main]
\printto [main-args]
\skipuntil [main-args-end]
\printto [main]
When the application starts up, we set up some scene parameters
in the \c{initializeGL()} function:
\quotefromfile teapot/teapotview.cpp
\skipuntil [initialize]
\printto [create-display-list]
The first line of the function selects a standard rendering
effect that lights material colors with the default OpenGL
two-sided lighting algorithm and the default light.
The \c{teapot} member variable is an instance of QGLSceneNode,
which we create using QGLBuilder during \c{initializeGL()}:
\quotefromfile teapot/teapotview.cpp
\skipuntil [create-display-list]
\printto [initialize]
The QGLTeapot class represents the geometry for the teapot,
which is added to the builder with the \c{<<} operator.
We then call QGLBuilder::finalizedSceneNode() to finalize the
object, prepare it to be uploaded to the GL server as a
vertex buffer, and hand over ownership of the scene node.
We have to take care to clean up our scene after we're done with it
and here that is done in the destructor:
\snippet teapot/teapotview.cpp destructor
Finally, we paint the teapot every time the window is refreshed:
\snippet teapot/teapotview.cpp paint
The QGLView class has in-built support for camera navigation
using the mouse and keyboard. By clicking and dragging the mouse,
the teapot can be rotated into any position. The image on the
left shows the view in its startup default position, and the
image on the right shows the view after rotation using the mouse:
\raw HTML
<center><table><tr><td>
\endraw
\image teapot-screenshot.png
\raw HTML
</td><td>
\endraw
\image teapot-rotated.png
\raw HTML
</td></tr></table></center>
\endraw
\l{qt3d-examples.html}{Return to Examples}.
*/
|