S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CSimpleCubePbuffer Class Reference

#include <SimpleCubePbuffer.h>

List of all members.

Public Member Functions

virtual ~CSimpleCubePbuffer ()
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 CSimpleCubePbuffer * NewL (TUint aWidth, TUint aHeight)

Protected Member Functions

 CSimpleCubePbuffer (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 SimpleCubePbuffer.h.


Constructor & Destructor Documentation

CSimpleCubePbuffer::~CSimpleCubePbuffer (   )  [virtual]
 

Destructor. Does nothing.

Definition at line 127 of file SimpleCubePbuffer.cpp.

00128     {
00129     }

CSimpleCubePbuffer::CSimpleCubePbuffer (  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 SimpleCubePbuffer.cpp.

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


Member Function Documentation

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

Factory method for creating a new CSimpleCubePbuffer object.

Definition at line 100 of file SimpleCubePbuffer.cpp.

References CSimpleCubePbuffer().

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

void CSimpleCubePbuffer::AppInit (  void   ) 
 

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

Definition at line 151 of file SimpleCubePbuffer.cpp.

References iScreenHeight, and iScreenWidth.

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

void CSimpleCubePbuffer::AppExit (  void   ) 
 

Called upon application exit. Does nothing.

Definition at line 199 of file SimpleCubePbuffer.cpp.

00200     {
00201     }

void CSimpleCubePbuffer::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 212 of file SimpleCubePbuffer.cpp.

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

void CSimpleCubePbuffer::AppCycle (  TInt  aFrame  ) 
 

Renders one frame.

Parameters:
aFrame Number of the frame to be rendered.

Definition at line 228 of file SimpleCubePbuffer.cpp.

References DrawBox().

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

void CSimpleCubePbuffer::FlatShading (  void   ) 
 

Sets the shading mode to flat.

Definition at line 255 of file SimpleCubePbuffer.cpp.

00256     {
00257     glShadeModel( GL_FLAT );
00258     }

void CSimpleCubePbuffer::SmoothShading (  void   ) 
 

Sets the shading to smooth (gradient).

Definition at line 268 of file SimpleCubePbuffer.cpp.

00269     {
00270     glShadeModel( GL_SMOOTH );
00271     }

void CSimpleCubePbuffer::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 279 of file SimpleCubePbuffer.cpp.

References iScreenHeight, and iScreenWidth.

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

void CSimpleCubePbuffer::ConstructL (  void   )  [protected]
 

Second phase contructor. Does nothing.

Definition at line 139 of file SimpleCubePbuffer.cpp.

00140     {
00141     }


© Nokia 2006

Back to top