Changeset 846 for trunk/examples/opengl/hellogl_es/glwidget.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/examples/opengl/hellogl_es/glwidget.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 7 7 ** This file is part of the examples of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE:LGPL$ 10 ** Commercial Usage 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 15 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 23 ** 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. 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 have questions regarding the use of this file, please contact 37 ** Nokia at [email protected]. 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." 38 37 ** $QT_END_LICENSE$ 39 38 ** … … 45 44 46 45 #include "bubble.h" 47 #include "cl_helper.h"48 46 49 47 … … 115 113 glDisable(GL_TEXTURE_2D); 116 114 glEnableClientState(GL_VERTEX_ARRAY); 117 glVertexPointer(3, q_vertexTypeEnum,0, createdVertices);115 glVertexPointer(3,,0, createdVertices); 118 116 glEnableClientState(GL_NORMAL_ARRAY); 119 glNormalPointer( q_vertexTypeEnum,0,createdNormals);117 glNormalPointer(,0,createdNormals); 120 118 glDrawArrays(GL_TRIANGLES, 0, m_vertexNumber / 3); 121 119 } … … 126 124 glEnable(GL_TEXTURE_2D); 127 125 glBindTexture(GL_TEXTURE_2D, m_uiTexture); 128 q_vertexTypeafVertices[] = {129 f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(0.5),130 f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(-0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),131 f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),132 f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),133 134 f2vt(0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),f2vt(-0.5),135 f2vt(0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5),f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(0.5),136 f2vt(-0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(-0.5),137 f2vt(-0.5), f2vt(-0.5), f2vt(0.5), f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(0.5),f2vt(0.5),138 139 f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(-0.5),140 f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5),141 f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5),142 f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5)126 afVertices[] = { 127 , 128 , 129 , 130 , 131 132 , 133 , 134 , 135 , 136 137 , 138 , 139 , 140 143 141 }; 144 142 glEnableClientState(GL_VERTEX_ARRAY); 145 glVertexPointer(3, q_vertexTypeEnum,0,afVertices);146 147 q_vertexTypeafTexCoord[] = {148 f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),149 f2vt(1.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),150 f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),151 f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),152 153 f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),154 f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),155 f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),156 f2vt(1.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),157 158 f2vt(0.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f),159 f2vt(1.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f),160 f2vt(1.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f),161 f2vt(0.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f)143 glVertexPointer(3,,0,afVertices); 144 145 afTexCoord[] = { 146 , 147 , 148 , 149 , 150 151 , 152 , 153 , 154 , 155 156 , 157 , 158 , 159 162 160 }; 163 161 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 164 glTexCoordPointer(2, q_vertexTypeEnum,0,afTexCoord);165 166 q_vertexTypeafNormals[] = {167 168 f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1),169 f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1),170 f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1),171 f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1),172 173 f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0),174 f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0),175 f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0),176 f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0),177 178 f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0),179 f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0),180 f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0),181 f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0)162 glTexCoordPointer(2,,0,afTexCoord); 163 164 afNormals[] = { 165 166 , 167 , 168 , 169 , 170 171 , 172 , 173 , 174 , 175 176 , 177 , 178 , 179 182 180 }; 183 181 glEnableClientState(GL_NORMAL_ARRAY); 184 glNormalPointer( q_vertexTypeEnum,0,afNormals);182 glNormalPointer(,0,afNormals); 185 183 186 184 glDrawArrays(GL_TRIANGLES, 0, 36); … … 189 187 void GLWidget::initializeGL () 190 188 { 191 q_glClearColor(f2vt(0.1f), f2vt(0.1f), f2vt(0.2f), f2vt(1.0f));189 ); 192 190 193 191 glEnable(GL_TEXTURE_2D); … … 195 193 m_uiTexture = bindTexture(QImage(":/qt.png")); 196 194 197 q_glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );198 q_glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );195 (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 196 (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 199 197 glEnable(GL_LIGHTING); 200 198 glEnable(GL_LIGHT0); 201 199 202 q_vertexType aLightPosition[] = {f2vt(0.0f),f2vt(0.3f),f2vt(1.0f),f2vt(0.0f)};203 204 q_glLightv(GL_LIGHT0, GL_SPOT_DIRECTION, aLightPosition);200 }; 201 202 v(GL_LIGHT0, GL_SPOT_DIRECTION, aLightPosition); 205 203 m_fAngle = 0; 206 204 m_fScale = 1; … … 231 229 //we have to take care of the states ourselves 232 230 233 q_glClearColor(f2vt(0.1f), f2vt(0.1f), f2vt(0.2f), f2vt(1.0f));231 ); 234 232 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 235 233 glEnable(GL_TEXTURE_2D); 236 234 237 q_glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );238 q_glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );235 (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 236 (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 239 237 glEnable(GL_LIGHTING); 240 238 glEnable(GL_LIGHT0); … … 249 247 glLoadIdentity(); 250 248 251 q_glRotate(f2vt(m_fAngle), f2vt(0.0), f2vt(1.0), f2vt(0.0));252 q_glRotate(f2vt(m_fAngle), f2vt(1.0), f2vt(0.0), f2vt(0.0));253 q_glRotate(f2vt(m_fAngle), f2vt(0.0), f2vt(0.0), f2vt(1.0));254 q_glScale(f2vt(m_fScale), f2vt(m_fScale),f2vt(m_fScale));255 q_glTranslate(f2vt(0),f2vt(-0.2),f2vt(0));256 257 q_vertexType matDiff[] = {f2vt(0.40), f2vt(1.0), f2vt(0.0), f2vt(1.0)};258 q_glMaterialv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiff);249 ); 250 ); 251 ); 252 ); 253 ); 254 255 }; 256 v(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiff); 259 257 260 258 if (qtLogo) … … 377 375 //! [1] 378 376 m_vertexNumber = vertices.size(); 379 createdVertices = new q_vertexType[m_vertexNumber];380 createdNormals = new q_vertexType[m_vertexNumber];377 createdVertices = new [m_vertexNumber]; 378 createdNormals = new [m_vertexNumber]; 381 379 for (int i = 0;i < m_vertexNumber;i++) { 382 createdVertices[i] = f2vt(vertices.at(i) * 2);383 createdNormals[i] = f2vt(normals.at(i));380 createdVertices[i] = ; 381 createdNormals[i] = ); 384 382 } 385 383 vertices.clear();
Note:
See TracChangeset
for help on using the changeset viewer.