S60 3rd Edition SDK for Symbian OS
Example Applications Guide

Texture.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : TextureContainer.cpp
00004 *  Part of     : OpenGLEx / Texture
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 TEXTURE_H
00017 #define TEXTURE_H
00018 
00019 // INCLUDES
00020 #include <e32base.h> // for CBase definition
00021 #include <GLES/gl.h> // OpenGL ES header file
00022 #include "Utils.h"   // Utilities (texmanager, textures etc.)
00023 
00024 // MACROS
00025 #define TEX_WIDTH     256 // Texture size must be power of two and max size
00026 #define TEX_HEIGHT    256 // for textures is 256 x 256
00027 
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  * Subclass of CFiniteStateMachine because the application
00040  * needs to handle loading textures and running states.
00041  */
00042 class CTexture : public CFiniteStateMachine, public MTextureLoadingListener
00043     {
00044     public:  // Constructors and destructor
00045 
00046         /**
00047          * Factory method for creating a new CSimpleCube object.
00048          */
00049         static CTexture* NewL( TUint aWidth, TUint aHeight );
00050 
00051         /**
00052          * Destructor. Does nothing.
00053          */
00054         virtual ~CTexture();
00055 
00056     public:  // New functions
00057 
00058         /**
00059          * Initializes OpenGL ES, sets the vertex and color
00060          * arrays and pointers. Also selects the shading mode and
00061          * creates the CTextureManager instance and starts loading
00062          * of required textures.
00063          */
00064         void AppInitL( void );
00065 
00066 
00067         /**
00068          * Called upon application exit. Destroys the CTextureManager
00069          * instance that was created in AppInitL() method.
00070          */
00071         void AppExit( void );
00072 
00073 
00074         /**
00075          * Renders one frame.
00076          * @param aFrame Number of the frame to be rendered.
00077          */
00078         void AppCycle( TInt aFrame );
00079         
00080         /**
00081          * Called when the finite state machine enters a new state.
00082          * Does nothing in this implementation.
00083          * @param aState State that is about to be entered.
00084          */
00085         void OnEnterStateL( TInt aState );
00086 
00087         /**
00088          * Called when texture manager starts loading the textures.
00089          * Sets the current state to "loading textures".
00090          */
00091         void OnStartLoadingTexturesL();
00092 
00093         /**
00094          * Called when texture manager has completed texture loading.
00095          * Changes the current state to "running".
00096          */
00097         void OnEndLoadingTexturesL();
00098 
00099 
00100         /**
00101          * Toggles perspective correction on and off.
00102          */
00103         void TogglePerspective( void );
00104 
00105 
00106         /**
00107          * Toggles texture wrapping on and off.
00108          */
00109         void ToggleWrapping( void );
00110 
00111 
00112         /**
00113          * Toggles lighting on and off.
00114          */
00115         void ToggleLighting( void );
00116 
00117 
00118         /**
00119          * Toggles blending enabled and disabled.
00120          */
00121         void ToggleBlending( void );
00122 
00123         /**
00124          * Notifies that the screen size has dynamically changed during execution of
00125          * this program. Resets the viewport to this new size and sets this size
00126          * to the CTextureManager.
00127          * @param aWidth New width of the screen.
00128          * @param aHeight New height of the screen.
00129          */
00130         void SetScreenSize( TUint aWidth, TUint aHeight );
00131 
00132     protected:
00133 
00134         /**
00135          * Standard constructor that must never Leave.
00136          * Stores the given screen width and height.
00137          * @param aWidth Width of the screen.
00138          * @param aHeight Height of the screen.
00139          */
00140         CTexture( TUint aWidth, TUint aHeight );
00141         
00142         /**
00143          * Second phase contructor. Does nothing.
00144          */
00145         void ConstructL( void );
00146 
00147     public:  // Data
00148 
00149         /**
00150          * Application states:
00151          * ELoadingTextures - indicates that the app. is loading textures.
00152          * ERunning - indicates that the app. is running.
00153          */
00154         enum 
00155                 {
00156                 ELoadingTextures, 
00157                 ERunning
00158                 };
00159 
00160         /** Whether perspective correction is used or not. */
00161         TBool iPerspectiveCorrEnabled;
00162 
00163         /** Whether texture wrapping is on or off. */
00164         TBool iTextureWrapEnabled;
00165 
00166         /** Whether lighting is on or off. */
00167         TBool iLightingEnabled;
00168 
00169         /** Whether blending is enabled or disabled. */
00170         TBool iBlendingEnabled;
00171 
00172     private:  // Data
00173 
00174         /** Texture manager that is used to load the used textures. */
00175         CTextureManager * iTextureManager;
00176         /** Width of the screen */
00177         TUint iScreenWidth;
00178         /** Height of the screen */
00179         TUint iScreenHeight;
00180         /** Nasa Hubble space telescope texture. */
00181         TTexture iNasaHubble;
00182         /** "OpenGL ES" texture. */
00183         TTexture iOpenGLES;
00184     };
00185 
00186 #endif

© Nokia 2006

Back to top