Code:
// INCLUDE FILES
#include <e32std.h>
#include <e32math.h>
#include "game01.h"
GLbyte nokTexCoords[4 * 2] =
{
255,255,
255,0,
0,0,
0,255
};
CGame01* CGame01::NewL( TUint aWidth, TUint aHeight )
{
CGame01* self = new (ELeave) CGame01( aWidth, aHeight );
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop();
return self;
}
CGame01::CGame01( TUint aWidth, TUint aHeight ) : iScreenWidth( aWidth ),iScreenHeight( aHeight )
{
}
CGame01::~CGame01()
{
}
void CGame01::ConstructL( void )
{
}
void CGame01::ToggleLighting( void )
{
}
void setLighting (void) {
//lighting code
}
void CGame01::AppInit( TUint8 *tex1 )
{
const GLvoid *texPtr = tex1;
// Set the screen background color.
glClearColorx( 0<<16, 0<<16, 0<<16, 1<<16 );
//glEnable( GL_CULL_FACE );
glEnable( GL_TEXTURE_2D );
glEnable( GL_NORMALIZE );
glEnable( GL_DEPTH_TEST );
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glViewport( 0, 0, iScreenWidth, iScreenHeight );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustumf( -2.f, 2.f, -2.f, 2.f, 3.f, 1000.f );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
setLighting();
iLightingMode = 1;
glShadeModel( GL_SMOOTH );
glGenTextures( 1, iNokTexObjects );
glBindTexture( GL_TEXTURE_2D, iNokTexObjects[0] );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, texPtr );
glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
}
void CGame01::AppExit( void )
{
glDeleteTextures( 1, iNokTexObjects );
}
void drawGround(void) {
GLbyte groundVerts[4 * 3] =
{
40, -2, -40,
-40, -2, -40,
-40, -2, 40,
40, -2, 40
};
GLbyte groundTris[2 * 3] =
{
1,0,3,
1,3,2,
};
GLbyte groundNorms[4 * 3] =
{
0,1,0,
0,1,0,
0,1,0,
0,1,0,
};
GLbyte texCoords[4 * 2] =
{
0,1,
0,0,
1,1,
1,0
};
glVertexPointer( 3, GL_BYTE, 0, groundVerts );
glTexCoordPointer( 2, GL_BYTE, 0, texCoords );
glNormalPointer( GL_BYTE, 0, groundNorms );
glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, groundTris );
}
void drawCube(void) {
//draw cube code here - no texturing
}
void createWorld(void) {
glColor4f(0.f, 1.f, 0.f, 1.f);
drawGround();
//other cubes drawn here
}
void CGame01::AppCycle( TInt iFrame )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
TReal xtrans = -xpos;
TReal ztrans = -zpos;
TReal ytrans = -0.25;
TReal sceneroty = 360.0 - yrot;
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glRotatef((GLfloat)sceneroty,0,1.0f,0);
glTranslatef((GLfloat)xtrans, (GLfloat)ytrans, (GLfloat)ztrans);
glBindTexture( GL_TEXTURE_2D, iNokTexObjects[0] );
//drawGround();
createWorld();
glLoadIdentity();
//player
glTranslatef( 0.f, -1.5f, -8.0f );
glScalef(0.4f, 0.3f, 0.4f);
glColor4x(1<<16, 0<<16, 0<<16, 1<<16);
glRotatex(lean<<16, 0<<16, 0<<16, 1<<16);
drawCube();
}
If anyone needs to see the code form the appUI or container class let me know.