Nokia N97 SDK
Example Applications Guide

CSimpleCubePixmap Class Reference

#include <SimpleCubePixmap.h>

Inheritance diagram for CSimpleCubePixmap:

List of all members.

Detailed Description

Class that does the actual OpenGL ES rendering.

Definition at line 33 of file SimpleCubePixmap.h.


Public Member Functions

virtual  ~CSimpleCubePixmap ()
void  AppInit (void)
void  AppExit (void)
void  DrawBox (GLfloat aSizeX, GLfloat aSizeY, GLfloat aSizeZ)
void  AppCycle (TInt aFrame)
void  FlatShading (void)
void  SmoothShading (void)
void  SetScreenSize (TUint aWidth, TUint aHeight)

Static Public Member Functions

static CSimpleCubePixmap *  NewL (TUint aWidth, TUint aHeight)

Protected Member Functions

  CSimpleCubePixmap (TUint aWidth, TUint aHeight)
void  ConstructL (void)

Private Attributes

TUint  iScreenWidth
TUint  iScreenHeight


Constructor & Destructor Documentation

CSimpleCubePixmap::~CSimpleCubePixmap (   )  [virtual]
 

Destructor. Does nothing.

Definition at line 124 of file SimpleCubePixmap.cpp.

00125     {
00126     }

CSimpleCubePixmap::CSimpleCubePixmap (  TUint  aWidth,
TUint  aHeight
)  [protected]
 

Standard constructor that must never Leave. Stores the given screen width and height.

Parameters:
aWidth  Width of the screen.
aHeight  Height of the screen.

Definition at line 117 of file SimpleCubePixmap.cpp.

Referenced by NewL().

00117                                                                   : 
00118     iScreenWidth( aWidth ),
00119     iScreenHeight( aHeight )
00120     {
00121     }


Member Function Documentation

CSimpleCubePixmap * CSimpleCubePixmap::NewL (  TUint  aWidth,
TUint  aHeight
)  [static]
 

Factory method for creating a new CSimpleCubePixmap object.

Definition at line 97 of file SimpleCubePixmap.cpp.

References CSimpleCubePixmap().

Referenced by CSimpleCubePixmapContainer::ConstructL().

00098     {
00099     /* Symbian 2-phase constructor. Calls both the default 
00100        C++ constructor and Symbian ConstructL methods */
00101     CSimpleCubePixmap* self = new (ELeave) CSimpleCubePixmap( aWidth, aHeight );
00102     CleanupStack::PushL( self );
00103     self->ConstructL();
00104     CleanupStack::Pop();
00105 
00106     return self;
00107     }

void CSimpleCubePixmap::AppInit (  void   ) 
 

Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode.

Definition at line 149 of file SimpleCubePixmap.cpp.

References iScreenHeight, and iScreenWidth.

Referenced by CSimpleCubePixmapContainer::ConstructL().

00150     {
00151     // Set the screen background color. 
00152     glClearColor( 0.f, 0.f, 0.f, 1.f );
00153 
00154     // Enable back face culling. 
00155     glEnable( GL_CULL_FACE  );
00156 
00157     // Initialize viewport and projection. 
00158     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00159     glMatrixMode( GL_PROJECTION );
00160 
00161     // Calculate the view frustrum
00162     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00163     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00164                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00165                 FRUSTUM_NEAR, FRUSTUM_FAR );
00166 
00167     glMatrixMode( GL_MODELVIEW );
00168 
00169     // Enable vertex arrays. 
00170     glEnableClientState( GL_VERTEX_ARRAY );
00171 
00172     // Set array pointers. 
00173     glVertexPointer( 3, GL_BYTE, 0, vertices );
00174 
00175     // Enable color arrays.
00176     glEnableClientState( GL_COLOR_ARRAY );
00177 
00178     // Set color pointers. 
00179     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colors );
00180 
00181     // Set the initial shading mode 
00182     glShadeModel( GL_FLAT ); 
00183 
00184     // Do not use perspective correction 
00185     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
00186 
00187     
00188     }

void CSimpleCubePixmap::AppExit (  void   ) 
 

Called upon application exit. Does nothing.

Definition at line 197 of file SimpleCubePixmap.cpp.

Referenced by CSimpleCubePixmapContainer::~CSimpleCubePixmapContainer().

00198     {
00199     }

void CSimpleCubePixmap::DrawBox (  GLfloat  aSizeX,
GLfloat  aSizeY,
GLfloat  aSizeZ
) 
 

Draws a 3D box. Scales the box to the given size using glScalef.

Parameters:
aSizeX  X-size of the box.
aSizeY  Y-size of the box.
aSizeZ  Z-size of the box.

Definition at line 210 of file SimpleCubePixmap.cpp.

Referenced by AppCycle().

00211     {
00212     glScalef( aSizeX, aSizeY, aSizeZ );
00213 
00214     glDrawElements( GL_TRIANGLES, 12 * 3, GL_UNSIGNED_BYTE, triangles );
00215     }

void CSimpleCubePixmap::AppCycle (  TInt  aFrame  ) 
 

Renders one frame.

Parameters:
aFrame  Number of the frame to be rendered.

Definition at line 226 of file SimpleCubePixmap.cpp.

References DrawBox().

Referenced by CSimpleCubePixmapContainer::DrawCallBack().

00227     {
00228 
00229     glClear( GL_COLOR_BUFFER_BIT );
00230 
00231     // Animate and draw box 
00232     glLoadIdentity();
00233     glTranslatex( 0 , 0 , -cameraDistance << 16 );
00234     glRotatex( aFrame << 16, 1 << 16,    0   ,    0    );
00235     glRotatex( aFrame << 15,    0   , 1 << 16,    0    );
00236     glRotatex( aFrame << 14,    0   ,    0   , 1 << 16 );
00237     DrawBox( 15.f, 15.f, 15.f );
00238     }

void CSimpleCubePixmap::FlatShading (  void   ) 
 

Sets the shading mode to flat.

Definition at line 253 of file SimpleCubePixmap.cpp.

Referenced by CSimpleCubePixmapAppUi::HandleCommandL().

00254     {
00255     glShadeModel( GL_FLAT );
00256     }

void CSimpleCubePixmap::SmoothShading (  void   ) 
 

Sets the shading to smooth (gradient).

Definition at line 266 of file SimpleCubePixmap.cpp.

Referenced by CSimpleCubePixmapAppUi::HandleCommandL().

00267     {
00268     glShadeModel( GL_SMOOTH );
00269     }

void CSimpleCubePixmap::SetScreenSize (  TUint  aWidth,
TUint  aHeight
) 
 

Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size.

Parameters:
aWidth  New width of the screen.
aHeight  New height of the screen.

Definition at line 277 of file SimpleCubePixmap.cpp.

References iScreenHeight, and iScreenWidth.

Referenced by CSimpleCubePixmapContainer::SizeChanged().

00278     {
00279     iScreenWidth  = aWidth;
00280     iScreenHeight = aHeight;
00281 
00282     // Set the screen background color. 
00283     glClearColor( 0.f, 0.f, 0.f, 1.f );
00284 
00285     // Reinitialize OpenGL ES rendering. Needed because context has been changed.
00286 
00287     // Enable back face culling. 
00288     glEnable( GL_CULL_FACE  );
00289 
00290     // Initialize viewport and projection. 
00291     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00292     glMatrixMode( GL_PROJECTION );
00293 
00294     GLfloat ar = (GLfloat)(iScreenHeight) / (GLfloat)(iScreenWidth);
00295     glFrustumf( -1.f, 1.f, -1.f*ar, 1.f*ar, 3.f, 1000.f );
00296 
00297 
00298     glFrustumf( -1.f, 1.f, -1.f, 1.f, 3.f, 1000.f );
00299     glMatrixMode( GL_MODELVIEW );
00300 
00301     // Enable vertex arrays. 
00302     glEnableClientState( GL_VERTEX_ARRAY );
00303 
00304     // Set array pointers. 
00305     glVertexPointer( 3, GL_BYTE, 0, vertices );
00306 
00307     // Enable color arrays.
00308     glEnableClientState( GL_COLOR_ARRAY );
00309 
00310     // Set color pointers. 
00311     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colors );
00312 
00313     // Set the initial shading mode 
00314     glShadeModel( GL_FLAT ); 
00315 
00316     // Do not use perspective correction 
00317     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
00318 
00319     // Recalculate the view frustrum
00320     glMatrixMode( GL_PROJECTION );
00321     glLoadIdentity();
00322     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00323     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00324                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00325                 FRUSTUM_NEAR, FRUSTUM_FAR );
00326     glMatrixMode( GL_MODELVIEW );
00327     }

void CSimpleCubePixmap::ConstructL (  void   )  [protected]
 

Second phase contructor. Does nothing.

Definition at line 136 of file SimpleCubePixmap.cpp.

00137     {
00138     }


Member Data Documentation

TUint CSimpleCubePixmap::iScreenWidth [private]
 

Width of the screen

Definition at line 110 of file SimpleCubePixmap.h.

Referenced by AppInit(), and SetScreenSize().

TUint CSimpleCubePixmap::iScreenHeight [private]
 

Height of the screen

Definition at line 113 of file SimpleCubePixmap.h.

Referenced by AppInit(), and SetScreenSize().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top