S60 3rd Edition SDK for Symbian OS
Example Applications Guide

MultiTex.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : MultiTex.h
00004 *  Part of     : OpenGLEx / MultiTex
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 MULTITEX_H
00017 #define MULTITEX_H
00018 
00019 //  INCLUDES
00020 #include <e32base.h>  // for CBase definition
00021 #include <GLES/gl.h>  // OpenGL ES header file
00022 #include <GLES/egl.h> // OpenGL ES header file
00023 #include "utils.h"    // Utilities (state machine, texture manager etc.)
00024 
00025 // MACROS
00026 #define FRUSTUM_LEFT   -1.f     //left vertical clipping plane
00027 #define FRUSTUM_RIGHT   1.f     //right vertical clipping plane
00028 #define FRUSTUM_BOTTOM -1.f     //bottom horizontal clipping plane
00029 #define FRUSTUM_TOP     1.f     //top horizontal clipping plane
00030 #define FRUSTUM_NEAR    3.f     //near depth clipping plane
00031 #define FRUSTUM_FAR  1000.f     //far depth clipping plane
00032 
00033 // CLASS DECLARATION
00034 
00035 /**
00036  * Class that does the actual OpenGL ES rendering.
00037  * Subclass of CFiniteStateMachine because the application
00038  * needs to handle loading textures and running states.
00039  */
00040 class CMultiTex : public CFiniteStateMachine, public MTextureLoadingListener
00041     {
00042     public:  // Constructors and destructor
00043   
00044         /**
00045          * Factory method for creating a new CMultiTex object.
00046          */
00047         static CMultiTex* NewL( TUint aWidth, TUint aHeight);
00048 
00049         /**
00050          * Destructor. Does nothing.
00051          */
00052         virtual ~CMultiTex();
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 and
00059          * creates the CTextureManager instance and starts loading
00060          * of required textures.
00061          */
00062         void AppInitL( TAny* aInstance );
00063         
00064         /**
00065          * Called upon application exit. Destroys the CTextureManager
00066          * instance that was created in AppInitL() method.
00067          */
00068         void AppExit( void );
00069         
00070         /**
00071          * Renders one frame with Pbuffer context to Ppbuffer surface.
00072          * @param aFrame Number of the frame to be rendered.
00073          */
00074         void AppCyclePbuffer( TInt aFrame );
00075 
00076         /**
00077          * Renders one frame with Window context to Window surface.
00078          * @param aFrame Number of the frame to be rendered.
00079          */
00080         void AppCycleWindow( TInt aFrame );
00081 
00082         /**
00083          * Called when the finite state machine enters a new state.
00084          * Does nothing in this implementation.
00085          * @param aState State that is about to be entered.
00086          */
00087         void OnEnterStateL( TInt aState );
00088 
00089         /**
00090          * Called when texture manager starts loading the textures.
00091          * Sets the current state to "loading textures".
00092          */
00093         void OnStartLoadingTexturesL();
00094 
00095         /**
00096          * Called when texture manager has completed texture loading.
00097          * Changes the current state to "running".
00098          */
00099         void OnEndLoadingTexturesL();
00100 
00101         /**
00102          * Calculate light texture for environment map lights.
00103          */
00104         void CalculateLightsL( void );
00105 
00106         /**
00107         * Draws lights with given dimensions.
00108         * @param  iFrame The current frame number
00109         */
00110         void DrawLights( TInt iFrame );
00111         
00112         /**
00113          * Notifies that the screen size has dynamically changed during execution of
00114          * this program. Resets the viewport to this new size and sets this size
00115          * to the CTextureManager.
00116          * @param aWidth New width of the screen.
00117          * @param aHeight New height of the screen.
00118          */
00119         void SetScreenSize( TUint aWidth, TUint aHeight );
00120 
00121     protected: // New functions
00122         
00123         /**
00124          * Standard constructor that must never Leave.
00125          * Stores the given screen width and height.
00126          * @param aWidth Width of the screen.
00127          * @param aHeight Height of the screen.
00128          */
00129         CMultiTex( TUint aWidth, TUint aHeight);
00130         
00131         /**
00132          * Second phase contructor. Does nothing.
00133          */
00134         void ConstructL( void );
00135 
00136     public:  // Data
00137 
00138         /**
00139          * Application states:
00140          * ELoadingTextures - indicates that the app. is loading textures.
00141          * ERunning - indicates that the app. is running.
00142          */
00143         enum 
00144                 {
00145                 ELoadingTextures, 
00146                 ERunning
00147                 };
00148 
00149         
00150     private: // Data
00151 
00152         /** Texture manager that is used to load the used textures. */
00153         CTextureManager * iTextureManager;
00154         /** Width of the screen */
00155         TUint iScreenWidth;
00156         /** Height of the screen */
00157         TUint iScreenHeight;
00158         /** Aspect ratio of the screen (iScreenHeight / iScreenWidth). */
00159         GLfloat iAspectRatio;
00160 
00161         /** World texture. */
00162         TTexture iWorldTexture;
00163         /** Pointer to the light texture data. */
00164         TUint8* iLightTex;
00165         /** List for light and env map texture objects. */
00166         GLuint iLightTexObjects[2];
00167         /** Camera distance. */
00168         GLint iCameraDistance;
00169     };
00170 #endif // MULTITEX_H
00171 
00172 // End of File

© Nokia 2006

Back to top