S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CSimpleCubePixmap Class Reference

#include <SimpleCubePixmap.h>

List of all members.

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


Detailed Description

Class that does the actual OpenGL ES rendering.

Definition at line 36 of file SimpleCubePixmap.h.


Constructor & Destructor Documentation

CSimpleCubePixmap::~CSimpleCubePixmap (   )  [virtual]
 

Destructor. Does nothing.

Definition at line 127 of file SimpleCubePixmap.cpp.

00128     {
00129     }

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 120 of file SimpleCubePixmap.cpp.

00120                                                                   : 
00121     iScreenWidth( aWidth ),
00122     iScreenHeight( aHeight )
00123     {
00124     }


Member Function Documentation

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

Factory method for creating a new CSimpleCubePixmap object.

Definition at line 100 of file SimpleCubePixmap.cpp.

References CSimpleCubePixmap().

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

void CSimpleCubePixmap::AppInit (  void   ) 
 

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

Definition at line 152 of file SimpleCubePixmap.cpp.

References iScreenHeight, and iScreenWidth.

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

void CSimpleCubePixmap::AppExit (  void   ) 
 

Called upon application exit. Does nothing.

Definition at line 200 of file SimpleCubePixmap.cpp.

00201     {
00202     }

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 213 of file SimpleCubePixmap.cpp.

00214     {
00215     glScalef( aSizeX, aSizeY, aSizeZ );
00216 
00217     glDrawElements( GL_TRIANGLES, 12 * 3, GL_UNSIGNED_BYTE, triangles );
00218     }

void CSimpleCubePixmap::AppCycle (  TInt  aFrame  ) 
 

Renders one frame.

Parameters:
aFrame Number of the frame to be rendered.

Definition at line 229 of file SimpleCubePixmap.cpp.

References DrawBox().

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

void CSimpleCubePixmap::FlatShading (  void   ) 
 

Sets the shading mode to flat.

Definition at line 256 of file SimpleCubePixmap.cpp.

00257     {
00258     glShadeModel( GL_FLAT );
00259     }

void CSimpleCubePixmap::SmoothShading (  void   ) 
 

Sets the shading to smooth (gradient).

Definition at line 269 of file SimpleCubePixmap.cpp.

00270     {
00271     glShadeModel( GL_SMOOTH );
00272     }

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 280 of file SimpleCubePixmap.cpp.

References iScreenHeight, and iScreenWidth.

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

void CSimpleCubePixmap::ConstructL (  void   )  [protected]
 

Second phase contructor. Does nothing.

Definition at line 139 of file SimpleCubePixmap.cpp.

00140     {
00141     }


Member Data Documentation

TUint CSimpleCubePixmap::iScreenWidth [private]
 

Width of the screen

Definition at line 113 of file SimpleCubePixmap.h.

TUint CSimpleCubePixmap::iScreenHeight [private]
 

Height of the screen

Definition at line 116 of file SimpleCubePixmap.h.


© Nokia 2006

Back to top