| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the examples of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:BSD$
|
|---|
| 10 | ** You may use this file under the terms of the BSD license as follows:
|
|---|
| 11 | **
|
|---|
| 12 | ** "Redistribution and use in source and binary forms, with or without
|
|---|
| 13 | ** modification, are permitted provided that the following conditions are
|
|---|
| 14 | ** met:
|
|---|
| 15 | ** * Redistributions of source code must retain the above copyright
|
|---|
| 16 | ** notice, this list of conditions and the following disclaimer.
|
|---|
| 17 | ** * Redistributions in binary form must reproduce the above copyright
|
|---|
| 18 | ** notice, this list of conditions and the following disclaimer in
|
|---|
| 19 | ** the documentation and/or other materials provided with the
|
|---|
| 20 | ** distribution.
|
|---|
| 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
|---|
| 22 | ** the names of its contributors may be used to endorse or promote
|
|---|
| 23 | ** products derived from this software without specific prior written
|
|---|
| 24 | ** permission.
|
|---|
| 25 | **
|
|---|
| 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
|---|
| 37 | ** $QT_END_LICENSE$
|
|---|
| 38 | **
|
|---|
| 39 | ****************************************************************************/
|
|---|
| 40 |
|
|---|
| 41 | /****************************************************************************
|
|---|
| 42 | **
|
|---|
| 43 | ** This is a simple QGLWidget displaying an openGL wireframe box
|
|---|
| 44 | **
|
|---|
| 45 | ** The OpenGL code is mostly borrowed from Brian Pauls "spin" example
|
|---|
| 46 | ** in the Mesa distribution
|
|---|
| 47 | **
|
|---|
| 48 | ****************************************************************************/
|
|---|
| 49 |
|
|---|
| 50 | #include "glbox.h"
|
|---|
| 51 | #include <QAxAggregated>
|
|---|
| 52 | #include <QUuid>
|
|---|
| 53 | //! [0]
|
|---|
| 54 | #include <objsafe.h>
|
|---|
| 55 | //! [0]
|
|---|
| 56 |
|
|---|
| 57 | #if defined(Q_CC_MSVC)
|
|---|
| 58 | #pragma warning(disable:4305) // init: truncation from const double to float
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | /*!
|
|---|
| 62 | Create a GLBox widget
|
|---|
| 63 | */
|
|---|
| 64 |
|
|---|
| 65 | GLBox::GLBox( QWidget* parent, const char* name )
|
|---|
| 66 | : QGLWidget( parent )
|
|---|
| 67 | {
|
|---|
| 68 | xRot = yRot = zRot = 0.0; // default object rotation
|
|---|
| 69 | scale = 1.25; // default object scale
|
|---|
| 70 | object = 0;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | /*!
|
|---|
| 75 | Release allocated resources
|
|---|
| 76 | */
|
|---|
| 77 |
|
|---|
| 78 | GLBox::~GLBox()
|
|---|
| 79 | {
|
|---|
| 80 | makeCurrent();
|
|---|
| 81 | glDeleteLists( object, 1 );
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | /*!
|
|---|
| 86 | Paint the box. The actual openGL commands for drawing the box are
|
|---|
| 87 | performed here.
|
|---|
| 88 | */
|
|---|
| 89 |
|
|---|
| 90 | void GLBox::paintGL()
|
|---|
| 91 | {
|
|---|
| 92 | glClear( GL_COLOR_BUFFER_BIT );
|
|---|
| 93 |
|
|---|
| 94 | glLoadIdentity();
|
|---|
| 95 | glTranslatef( 0.0, 0.0, -10.0 );
|
|---|
| 96 | glScalef( scale, scale, scale );
|
|---|
| 97 |
|
|---|
| 98 | glRotatef( xRot, 1.0, 0.0, 0.0 );
|
|---|
| 99 | glRotatef( yRot, 0.0, 1.0, 0.0 );
|
|---|
| 100 | glRotatef( zRot, 0.0, 0.0, 1.0 );
|
|---|
| 101 |
|
|---|
| 102 | glCallList( object );
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | /*!
|
|---|
| 107 | Set up the OpenGL rendering state, and define display list
|
|---|
| 108 | */
|
|---|
| 109 |
|
|---|
| 110 | void GLBox::initializeGL()
|
|---|
| 111 | {
|
|---|
| 112 | qglClearColor(Qt::black); // Let OpenGL clear to black
|
|---|
| 113 | object = makeObject(); // Generate an OpenGL display list
|
|---|
| 114 | glShadeModel( GL_FLAT );
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 | /*!
|
|---|
| 120 | Set up the OpenGL view port, matrix mode, etc.
|
|---|
| 121 | */
|
|---|
| 122 |
|
|---|
| 123 | void GLBox::resizeGL( int w, int h )
|
|---|
| 124 | {
|
|---|
| 125 | glViewport( 0, 0, (GLint)w, (GLint)h );
|
|---|
| 126 | glMatrixMode( GL_PROJECTION );
|
|---|
| 127 | glLoadIdentity();
|
|---|
| 128 | glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
|
|---|
| 129 | glMatrixMode( GL_MODELVIEW );
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
|
|---|