Nokia N97 SDK
Example Applications Guide

BumpMap.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : BumpMap.h
00004  *  Part of     : OpenGLEx / Bumpmap
00005  *
00006  *  Copyright (c) 2005-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 __BUMPMAPPINGH__
00014 #define __BUMPMAPPINGH__
00015 
00016 //  INCLUDES
00017 
00018 #include <e32base.h> // for CBase definition
00019 #include <GLES\gl.h>      // OpenGL ES header file
00020 #include "Textureutils.h"
00021 #include "Glutils.h"      // gluLookAt() function
00022 #include "firefly.h"
00023 
00024 // FORWARD DECLARATIONS
00025 
00026 /**
00027  * Class that does the actual OpenGL ES rendering.
00028  * Subclass of CFiniteStateMachine because the application
00029  * needs to handle loading textures and running states.
00030  */
00031 class CBumpMap
00032         : public CFiniteStateMachine, public MTextureLoadingListener
00033         {
00034         public: // Constructors and destructor
00035 
00036         /**
00037          * Factory method for creating a new CBumpMap object.
00038                  * Calls the hidden constructors.
00039          */
00040                 static CBumpMap* NewL( GLuint aWidth, GLuint aHeight );
00041 
00042         /**
00043          * Destructor. Does nothing.
00044          */
00045                 virtual ~CBumpMap();
00046 
00047         protected: // Hidden constructors
00048 
00049         /**
00050          * Standard constructor that must never Leave.
00051          * Stores the given screen width and height.
00052          * @param aWidth Width of the screen.
00053          * @param aHeight Height of the screen.
00054          */
00055                 CBumpMap( GLuint aWidth, GLuint aHeight );
00056 
00057         /**
00058          * Second phase constructor that can call methods that may leave. Does nothing.
00059          */
00060                 void ConstructL( void );
00061 
00062 
00063         public: // New methods
00064 
00065         /**
00066          * Initializes OpenGL ES, sets the vertex and color
00067          * arrays and pointers. Also selects the shading mode and
00068          * creates the CTextureManager instance and starts loading
00069          * of required textures.
00070          */
00071                 void AppInitL( void );
00072 
00073         /**
00074          * Called upon application exit. Destroys the CTextureManager
00075          * instance that was created in AppInitL() method.
00076          */
00077                 void AppExit( void );
00078 
00079         /**
00080          * Renders one frame.
00081          * @param aFrame Number of the frame to be rendered.
00082                  * @param aTimeSecs Seconds elapsed since the application started running.
00083                  * @param aDeltaTimeSecs Seconds elapsed since last call to AppCycle().
00084          */
00085                 void AppCycle( GLuint aFrame, GLfloat aTimeSecs, GLfloat aDeltaTimeSecs );
00086 
00087         /**
00088          * Called when the finite state machine enters a new state.
00089          * Does nothing in this implementation.
00090          * @param aState State that is about to be entered.
00091          */
00092                 void OnEnterStateL( TInt aState);
00093 
00094         /**
00095          * Called when texture manager starts loading the textures.
00096          * Sets the current state to "loading textures".
00097          */
00098                 void OnStartLoadingTexturesL();
00099 
00100         /**
00101          * Called when texture manager has completed texture loading.
00102          * Changes the current state to "running".
00103          */
00104                 void OnEndLoadingTexturesL();
00105 
00106         /**
00107          * Notifies that the screen size has dynamically changed during execution of
00108          * this program. Resets the viewport to this new size and sets this size
00109          * to the CTextureManager.
00110          * @param aWidth New width of the screen.
00111          * @param aHeight New height of the screen.
00112          */
00113         void SetScreenSize( GLuint aWidth, GLuint aHeight );
00114 
00115     private: // New methods
00116 
00117                 /**
00118                  * Draws the bumpmapped rectangle.
00119                  */
00120                 void DrawBumpmappedRect();
00121 
00122         /**
00123          * Generates the vertices for drawing the bumpmapped rectangle to the screen.
00124          */
00125         void GenerateBumpmapVerticesL();
00126 
00127 
00128         public: // Data
00129 
00130         /**
00131          * Application states:
00132          * ELoadingTextures - indicates that the app. is loading textures.
00133          * ERunning - indicates that the app. is running.
00134          */
00135                 enum
00136                 {
00137                 ELoadingTextures,
00138                 ERunning
00139                 };
00140 
00141         private: // Data
00142 
00143         /** Texture manager that is used to load the used textures. */
00144                 CTextureManager * iTextureManager;
00145 
00146                 /** Firefly that also acts as the light source. */
00147         CFireFly* iLightSource;
00148         /** Width of the screen */
00149         GLuint iScreenWidth;
00150         /** Height of the screen */
00151         GLuint iScreenHeight;
00152         /** Bumpmapping texture. */
00153         TTexture iBumpmapTexture;
00154         /** Normal color texture. */
00155         TTexture iTexture;
00156 
00157         /** Vertices for the bumpmap rectangle. */
00158         GLfloat* iBumpmapVertices;
00159         /** Color values for the vertices in the bumpmap rectangle. */
00160         GLfloat* iBumpmapColors;
00161         /** Texture coordinates for the bumpmap rectangle. */
00162         GLfloat* iBumpmapTexCoords;
00163         /** Indices for drawing the bumpmap rectangle. */
00164         GLubyte* iBumpmapIndices;
00165 
00166                 /** Camera. */
00167                 TCamera iCamera;
00168         };
00169 
00170 #endif
00171 
00172 // End of File
00173 

© Nokia 2009

Back to top