void Reshape( int width, int height )
{
game.gameMenu.hScreenWidth = width / 2;
game.gameMenu.hScreenHeight = height / 2;
glEnable( GL_BLEND ); // code for transparency
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glViewport(0, 0, width, height);
glMatrixMode( GL_PROJECTION ); // Change to 1 pixel per gl unit
glLoadIdentity();
glOrtho( -width/2, width/2, height/2, -height/2, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
void GamePlay::draw( )
{
glLoadIdentity( );
glRotatef( angle, 0.0, 0.0, 1.0 );
glScalef( scaleFactor, scaleFactor, 0.0 );
glTranslatef( -players[ myIndex ].position.x, -players[ myIndex ].position.y, -200.0f );
for( int i = 0; i < numTris; i++ )
{
glBindTexture( GL_TEXTURE_2D, texs[ tris[ i ].texIndex ] );
glBegin( GL_TRIANGLES );
glTexCoord2f( 0.0, 1.0 );
glVertex2f( tris[ i ].v[ 0 ].x, tris[ i ].v[ 0 ].y );
glTexCoord2f( 1.0, 1.0 );
glVertex2f( tris[ i ].v[ 1 ].x, tris[ i ].v[ 1 ].y );
glTexCoord2f( 0.0, 0.0 );
glVertex2f( tris[ i ].v[ 2 ].x, tris[ i ].v[ 2 ].y );
glEnd( );
}
for( int i = 0; i < players.size( ); i++ )
{
players[ i ].draw( );
}
}
void GamePlay::loadMap ( char * filename )
{
ifstream mapFile( filename );
mapFile >> numTris;
tris = new Triangle [ numTris ];
mapFile >> numTexs;
mapFile.get();
filenames = new char * [ numTexs ];
for( int i = 0; i < numTexs; i++ )
{
filenames[ i ] = new char [ 32 ];
mapFile.getline( filenames[ i ], 32, '\n' );
}
for( int i = 0; i < numTris; i++ )
{
for( int j = 0; j < 3; j++ )
{
mapFile >> tris[ i ].v[ j ].x;
mapFile >> tris[ i ].v[ j ].y;
}
mapFile >> tris[ i ].texIndex;
}
mapFile.close( );
}
void GamePlay::loadTexs ( )
{
Bitmap24Bit bmp;
texs = new GLuint [ numTexs ];
glGenTextures( numTexs, &texs[ 0 ] );
for( int i = 0; i < numTexs; i++ )
{
bmp.loadBMP( filenames[ i ] );
glBindTexture( GL_TEXTURE_2D, texs[ i ] );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bmp.width, bmp.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bmp.imageData );
bmp.releaseData();
}
}
int main(int argc, char **argv)
{
glutInit( &argc, argv );
Init();
// Declare the display, idle, reshape, and keyboard functions
glutDisplayFunc( Draw );
glutKeyboardFunc( Keyboard );
glutKeyboardUpFunc( KeyboardUp );
glutMouseFunc( Mouse );
glutPassiveMotionFunc( MouseMotion );
glutReshapeFunc( Reshape );
glutIdleFunc( Idle );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LESS );
glEnable( GL_TEXTURE_2D );
// Start the Main Loop
glutMainLoop();
return true;
}