Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/examples/opengl/hellogl/glwidget.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4646
    4747#include "glwidget.h"
     48
     49
     50
     51
     52
    4853
    4954//! [0]
    5055GLWidget::GLWidget(QWidget *parent)
    51     : QGLWidget(parent)
    52 {
    53     object = 0;
     56    : QGLWidget(parent)
     57{
     58    = 0;
    5459    xRot = 0;
    5560    yRot = 0;
    5661    zRot = 0;
    5762
    58     trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
    59     trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
     63    Green = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
     64    Purple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
    6065}
    6166//! [0]
     
    6469GLWidget::~GLWidget()
    6570{
    66     makeCurrent();
    67     glDeleteLists(object, 1);
    6871}
    6972//! [1]
     
    8487//! [4]
    8588
     89
     90
     91
     92
     93
     94
     95
     96
    8697//! [5]
    8798void GLWidget::setXRotation(int angle)
    8899{
    89     normalizeAngle(&angle);
     100    angle);
    90101    if (angle != xRot) {
    91102        xRot = angle;
     
    98109void GLWidget::setYRotation(int angle)
    99110{
    100     normalizeAngle(&angle);
     111    angle);
    101112    if (angle != yRot) {
    102113        yRot = angle;
     
    108119void GLWidget::setZRotation(int angle)
    109120{
    110     normalizeAngle(&angle);
     121    angle);
    111122    if (angle != zRot) {
    112123        zRot = angle;
     
    119130void GLWidget::initializeGL()
    120131{
    121     qglClearColor(trolltechPurple.dark());
    122     object = makeObject();
    123     glShadeModel(GL_FLAT);
     132    qglClearColor(qtPurple.dark());
     133
     134    logo = new QtLogo(this, 64);
     135    logo->setColor(qtGreen.dark());
     136
    124137    glEnable(GL_DEPTH_TEST);
    125138    glEnable(GL_CULL_FACE);
     139
     140
     141
     142
     143
     144
    126145}
    127146//! [6]
     
    132151    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    133152    glLoadIdentity();
    134     glTranslated(0.0, 0.0, -10.0);
    135     glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
    136     glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
    137     glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
    138     glCallList(object);
     153    glTranslate(0.0, 0.0, -10.0);
     154    glRotate(xRot / 16.0, 1.0, 0.0, 0.0);
     155    glRotate(yRot / 16.0, 0.0, 1.0, 0.0);
     156    glRotate(zRot / 16.0, 0.0, 0.0, 1.0);
     157    );
    139158}
    140159//! [7]
     
    148167    glMatrixMode(GL_PROJECTION);
    149168    glLoadIdentity();
    150     glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
     169#ifdef QT_OPENGL_ES_1
     170    glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
     171#else
     172    glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
     173#endif
    151174    glMatrixMode(GL_MODELVIEW);
    152175}
     
    176199}
    177200//! [10]
    178 
    179 GLuint GLWidget::makeObject()
    180 {
    181     GLuint list = glGenLists(1);
    182     glNewList(list, GL_COMPILE);
    183 
    184     glBegin(GL_QUADS);
    185 
    186     GLdouble x1 = +0.06;
    187     GLdouble y1 = -0.14;
    188     GLdouble x2 = +0.14;
    189     GLdouble y2 = -0.06;
    190     GLdouble x3 = +0.08;
    191     GLdouble y3 = +0.00;
    192     GLdouble x4 = +0.30;
    193     GLdouble y4 = +0.22;
    194 
    195     quad(x1, y1, x2, y2, y2, x2, y1, x1);
    196     quad(x3, y3, x4, y4, y4, x4, y3, x3);
    197 
    198     extrude(x1, y1, x2, y2);
    199     extrude(x2, y2, y2, x2);
    200     extrude(y2, x2, y1, x1);
    201     extrude(y1, x1, x1, y1);
    202     extrude(x3, y3, x4, y4);
    203     extrude(x4, y4, y4, x4);
    204     extrude(y4, x4, y3, x3);
    205 
    206     const double Pi = 3.14159265358979323846;
    207     const int NumSectors = 200;
    208 
    209     for (int i = 0; i < NumSectors; ++i) {
    210         double angle1 = (i * 2 * Pi) / NumSectors;
    211         GLdouble x5 = 0.30 * sin(angle1);
    212         GLdouble y5 = 0.30 * cos(angle1);
    213         GLdouble x6 = 0.20 * sin(angle1);
    214         GLdouble y6 = 0.20 * cos(angle1);
    215 
    216         double angle2 = ((i + 1) * 2 * Pi) / NumSectors;
    217         GLdouble x7 = 0.20 * sin(angle2);
    218         GLdouble y7 = 0.20 * cos(angle2);
    219         GLdouble x8 = 0.30 * sin(angle2);
    220         GLdouble y8 = 0.30 * cos(angle2);
    221 
    222         quad(x5, y5, x6, y6, x7, y7, x8, y8);
    223 
    224         extrude(x6, y6, x7, y7);
    225         extrude(x8, y8, x5, y5);
    226     }
    227 
    228     glEnd();
    229 
    230     glEndList();
    231     return list;
    232 }
    233 
    234 void GLWidget::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
    235                     GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
    236 {
    237     qglColor(trolltechGreen);
    238 
    239     glVertex3d(x1, y1, -0.05);
    240     glVertex3d(x2, y2, -0.05);
    241     glVertex3d(x3, y3, -0.05);
    242     glVertex3d(x4, y4, -0.05);
    243 
    244     glVertex3d(x4, y4, +0.05);
    245     glVertex3d(x3, y3, +0.05);
    246     glVertex3d(x2, y2, +0.05);
    247     glVertex3d(x1, y1, +0.05);
    248 }
    249 
    250 void GLWidget::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
    251 {
    252     qglColor(trolltechGreen.dark(250 + int(100 * x1)));
    253 
    254     glVertex3d(x1, y1, +0.05);
    255     glVertex3d(x2, y2, +0.05);
    256     glVertex3d(x2, y2, -0.05);
    257     glVertex3d(x1, y1, -0.05);
    258 }
    259 
    260 void GLWidget::normalizeAngle(int *angle)
    261 {
    262     while (*angle < 0)
    263         *angle += 360 * 16;
    264     while (*angle > 360 * 16)
    265         *angle -= 360 * 16;
    266 }
Note: See TracChangeset for help on using the changeset viewer.