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/overpainting/glwidget.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    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 have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4747
    4848#include "bubble.h"
     49#include "qtlogo.h"
    4950#include "glwidget.h"
    5051
     
    6061    qsrand(midnight.secsTo(QTime::currentTime()));
    6162
    62     object = 0;
     63    logo = 0;
    6364    xRot = 0;
    6465    yRot = 0;
    6566    zRot = 0;
    6667
    67     trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
    68     trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
     68    qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
     69    qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
    6970
    7071    animationTimer.setSingleShot(false);
     
    8182GLWidget::~GLWidget()
    8283{
    83     makeCurrent();
    84     glDeleteLists(object, 1);
    8584}
    8685//! [1]
    8786
     87static void qNormalizeAngle(int &angle)
     88{
     89    while (angle < 0)
     90        angle += 360 * 16;
     91    while (angle > 360 * 16)
     92        angle -= 360 * 16;
     93}
     94
    8895void GLWidget::setXRotation(int angle)
    8996{
    90     normalizeAngle(&angle);
     97    qNormalizeAngle(angle);
    9198    if (angle != xRot)
    9299        xRot = angle;
     
    95102void GLWidget::setYRotation(int angle)
    96103{
    97     normalizeAngle(&angle);
     104    qNormalizeAngle(angle);
    98105    if (angle != yRot)
    99106        yRot = angle;
     
    102109void GLWidget::setZRotation(int angle)
    103110{
    104     normalizeAngle(&angle);
     111    qNormalizeAngle(angle);
    105112    if (angle != zRot)
    106113        zRot = angle;
     
    110117void GLWidget::initializeGL()
    111118{
    112     object = makeObject();
     119    glEnable(GL_MULTISAMPLE);
     120
     121    logo = new QtLogo(this);
     122    logo->setColor(qtGreen.dark());
    113123}
    114124//! [2]
     
    143153
    144154//! [6]
    145     qglClearColor(trolltechPurple.dark());
     155    qglClearColor(qtPurple.dark());
    146156    glShadeModel(GL_SMOOTH);
    147157    glEnable(GL_DEPTH_TEST);
     
    159169    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    160170    glLoadIdentity();
    161     glTranslated(0.0, 0.0, -10.0);
    162     glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
    163     glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
    164     glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
    165     glCallList(object);
     171    glTranslatef(0.0, 0.0, -10.0);
     172    glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
     173    glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
     174    glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
     175
     176    logo->draw();
    166177//! [7]
    167178
    168179//! [8]
     180    glShadeModel(GL_FLAT);
     181    glDisable(GL_CULL_FACE);
     182    glDisable(GL_DEPTH_TEST);
     183    glDisable(GL_LIGHTING);
     184
    169185    glMatrixMode(GL_MODELVIEW);
    170186    glPopMatrix();
     
    203219}
    204220
    205 GLuint GLWidget::makeObject()
    206 {
    207     GLuint list = glGenLists(1);
    208     glNewList(list, GL_COMPILE);
    209 
    210     glEnable(GL_NORMALIZE);
    211     glBegin(GL_QUADS);
    212 
    213     static GLfloat logoDiffuseColor[4] = {trolltechGreen.red()/255.0,
    214                                           trolltechGreen.green()/255.0,
    215                                           trolltechGreen.blue()/255.0, 1.0};
    216     glMaterialfv(GL_FRONT, GL_DIFFUSE, logoDiffuseColor);
    217 
    218     GLdouble x1 = +0.06;
    219     GLdouble y1 = -0.14;
    220     GLdouble x2 = +0.14;
    221     GLdouble y2 = -0.06;
    222     GLdouble x3 = +0.08;
    223     GLdouble y3 = +0.00;
    224     GLdouble x4 = +0.30;
    225     GLdouble y4 = +0.22;
    226 
    227     quad(x1, y1, x2, y2, y2, x2, y1, x1);
    228     quad(x3, y3, x4, y4, y4, x4, y3, x3);
    229 
    230     extrude(x1, y1, x2, y2);
    231     extrude(x2, y2, y2, x2);
    232     extrude(y2, x2, y1, x1);
    233     extrude(y1, x1, x1, y1);
    234     extrude(x3, y3, x4, y4);
    235     extrude(x4, y4, y4, x4);
    236     extrude(y4, x4, y3, x3);
    237 
    238     const double Pi = 3.14159265358979323846;
    239     const int NumSectors = 200;
    240 
    241     for (int i = 0; i < NumSectors; ++i) {
    242         double angle1 = (i * 2 * Pi) / NumSectors;
    243         GLdouble x5 = 0.30 * sin(angle1);
    244         GLdouble y5 = 0.30 * cos(angle1);
    245         GLdouble x6 = 0.20 * sin(angle1);
    246         GLdouble y6 = 0.20 * cos(angle1);
    247 
    248         double angle2 = ((i + 1) * 2 * Pi) / NumSectors;
    249         GLdouble x7 = 0.20 * sin(angle2);
    250         GLdouble y7 = 0.20 * cos(angle2);
    251         GLdouble x8 = 0.30 * sin(angle2);
    252         GLdouble y8 = 0.30 * cos(angle2);
    253 
    254         quad(x5, y5, x6, y6, x7, y7, x8, y8);
    255 
    256         extrude(x6, y6, x7, y7);
    257         extrude(x8, y8, x5, y5);
    258     }
    259 
    260     glEnd();
    261 
    262     glEndList();
    263     return list;
    264 }
    265 
    266 void GLWidget::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
    267                     GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
    268 {
    269     glNormal3d(0.0, 0.0, -1.0);
    270     glVertex3d(x1, y1, -0.05);
    271     glVertex3d(x2, y2, -0.05);
    272     glVertex3d(x3, y3, -0.05);
    273     glVertex3d(x4, y4, -0.05);
    274 
    275     glNormal3d(0.0, 0.0, 1.0);
    276     glVertex3d(x4, y4, +0.05);
    277     glVertex3d(x3, y3, +0.05);
    278     glVertex3d(x2, y2, +0.05);
    279     glVertex3d(x1, y1, +0.05);
    280 }
    281 
    282 void GLWidget::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
    283 {
    284     qglColor(trolltechGreen.dark(250 + int(100 * x1)));
    285 
    286     glNormal3d((x1 + x2)/2.0, (y1 + y2)/2.0, 0.0);
    287     glVertex3d(x1, y1, +0.05);
    288     glVertex3d(x2, y2, +0.05);
    289     glVertex3d(x2, y2, -0.05);
    290     glVertex3d(x1, y1, -0.05);
    291 }
    292 
    293 void GLWidget::normalizeAngle(int *angle)
    294 {
    295     while (*angle < 0)
    296         *angle += 360 * 16;
    297     while (*angle > 360 * 16)
    298         *angle -= 360 * 16;
    299 }
    300 
    301221void GLWidget::createBubbles(int number)
    302222{
     
    333253    glMatrixMode(GL_PROJECTION);
    334254    glLoadIdentity();
    335     glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
     255#ifdef QT_OPENGL_ES
     256    glOrthof(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0);
     257#else
     258    glOrtho(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0);
     259#endif
    336260    glMatrixMode(GL_MODELVIEW);
    337261}
Note: See TracChangeset for help on using the changeset viewer.