S60 3rd Edition SDK for Symbian OS
Example Applications Guide

SimpleCube.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : SimpleCube.h
00004 *  Part of     : OpenGLEx / SimpleCube
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2004-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 #ifndef SIMPLECUBE_H
00017 #define SIMPLECUBE_H
00018 
00019 //  INCLUDES
00020 #include <e32base.h> // for CBase definition
00021 #include <GLES/gl.h> // OpenGL ES header file
00022 
00023 /** Enumerated rendering mode for triangle and triangle fan based rendering. */
00024 typedef enum { ETriangles, ETriangleFans } TRenderingMode;
00025 
00026 
00027 // MACROS
00028 #define FRUSTUM_LEFT   -1.f     //left vertical clipping plane
00029 #define FRUSTUM_RIGHT   1.f     //right vertical clipping plane
00030 #define FRUSTUM_BOTTOM -1.f     //bottom horizontal clipping plane
00031 #define FRUSTUM_TOP     1.f     //top horizontal clipping plane
00032 #define FRUSTUM_NEAR    3.f     //near depth clipping plane
00033 #define FRUSTUM_FAR  1000.f     //far depth clipping plane
00034 
00035 // CLASS DECLARATION
00036 
00037 /**
00038  * Class that does the actual OpenGL ES rendering.
00039  */
00040 class CSimpleCube : public CBase
00041     {
00042     public:  // Constructors and destructor
00043   
00044         /**
00045          * Factory method for creating a new CSimpleCube object.
00046          */
00047         static CSimpleCube* NewL( TUint aWidth, TUint aHeight);
00048 
00049         /**
00050          * Destructor. Does nothing.
00051          */
00052         virtual ~CSimpleCube();
00053 
00054     public: // New functions
00055         
00056         /**
00057          * Initializes OpenGL ES, sets the vertex and color
00058          * arrays and pointers. Also selects the shading mode.
00059          */
00060         void AppInit( void );
00061         
00062         /**
00063          * Called upon application exit. Does nothing.
00064          */
00065         void AppExit( void );
00066         
00067         /**
00068          * Draws a 3D box with triangles or triangle fans depending
00069          * on the current rendering mode.Scales the box to the given size using glScalef.
00070          * @param  aSizeX X-size of the box.
00071          * @param  aSizeY Y-size of the box.
00072          * @param  aSizeZ Z-size of the box.
00073          */
00074         void DrawBox( GLfloat aSizeX, GLfloat aSizeY, GLfloat aSizeZ );
00075         
00076         /**
00077          * Renders one frame.
00078          * @param aFrame Number of the frame to be rendered.
00079          */
00080         void AppCycle( TInt aFrame );
00081         
00082         /**
00083          * Sets the shading mode to flat.
00084          */
00085         void FlatShading( void );
00086         
00087         /**
00088          * Sets the shading to smooth (gradient).
00089          */
00090         void SmoothShading( void );
00091         
00092         /**
00093          * Sets the rendering to use triangles.
00094          */
00095         void TriangleMode( void );
00096         
00097         /**
00098          * Sets the rendering to use triangle fans.
00099          */
00100         void TriangleFanMode( void );
00101         
00102         /**
00103          * Notifies that the screen size has dynamically changed during execution of
00104          * this program. Resets the viewport to this new size.
00105          * @param aWidth New width of the screen.
00106          * @param aHeight New height of the screen.
00107          */
00108         void SetScreenSize( TUint aWidth, TUint aHeight );
00109         
00110     protected: // New functions
00111         
00112         /**
00113          * Standard constructor that must never Leave.
00114          * Stores the given screen width and height.
00115          * @param aWidth Width of the screen.
00116          * @param aHeight Height of the screen.
00117          */
00118         CSimpleCube( TUint aWidth, TUint aHeight);
00119         
00120         /**
00121          * Second phase contructor. Does nothing.
00122          */
00123         void ConstructL( void );
00124         
00125     private: // Data
00126         
00127         /** Width of the screen */
00128         TUint           iScreenWidth;
00129         
00130         /** Height of the screen */
00131         TUint           iScreenHeight;
00132         
00133         /** The current rendering mode */
00134         TRenderingMode  iDrawingMode;
00135     };
00136 #endif // SIMPLECUBE_H
00137 
00138 // End of File

© Nokia 2006

Back to top