Nokia N97 SDK
Example Applications Guide

Texture.h

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

© Nokia 2009

Back to top