1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#include "LUtil.h"
#include <IL/il.h>
#include <IL/ilu.h>
#include "LTexture.h"
int gViewportMode = VIEWPORT_MODE_C;
//Sprite texture
LTexture gArrowTexture;
//Sprite area
LFRect gArrowClips[ 4 ];
bool initGL()
{
//Set the viewport
glViewport( 0.f, 0.f, SCREEN_WIDTH, SCREEN_HEIGHT );
//Initialize Projection Matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0, 1.0, -1.0 );
//Initialize Modelview Matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//Initialize clear color
glClearColor( 0.f, 0.f, 0.f, 1.f );
//Enable texturing
glEnable( GL_TEXTURE_2D );
//Check for error
GLenum error = glGetError();
if( error != GL_NO_ERROR )
{
printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
return false;
}
//Initialize DevIL
ilInit();
ilClearColour( 255, 255, 255, 000 );
//Check for error
ILenum ilError = ilGetError();
if( ilError != IL_NO_ERROR )
{
printf( "Error initializing DevIL! %s\n", iluErrorString( ilError ) );
return false;
}
return true;
}
bool loadMedia()
{
//Set clip rectangles
if ( gViewportMode == VIEWPORT_MODE_C) {
gArrowClips[ 0 ].x = 0.f;
gArrowClips[ 0 ].y = 0.f;
gArrowClips[ 0 ].w = 330.f;
gArrowClips[ 0 ].h = 355.f;
gArrowClips[ 1 ].x = 330.f;
gArrowClips[ 1 ].y = 0.f;
gArrowClips[ 1 ].w = 310.f;
gArrowClips[ 1 ].h = 480.f;
gArrowClips[ 2 ].x = 0.f;
gArrowClips[ 2 ].y = 355.f;
gArrowClips[ 2 ].w = 330.f;
gArrowClips[ 2 ].h = 125.f;
}
else if ( gViewportMode == VIEWPORT_MODE_N) {
gArrowClips[ 0 ].x = 0.f;
gArrowClips[ 0 ].y = 480.f;
gArrowClips[ 0 ].w = 330.f;
gArrowClips[ 0 ].h = 355.f;
gArrowClips[ 1 ].x = 330.f;
gArrowClips[ 1 ].y = 480.f;
gArrowClips[ 1 ].w = 310.f;
gArrowClips[ 1 ].h = 480.f;
gArrowClips[ 2 ].x = 0.f;
gArrowClips[ 2 ].y = 835.f;
gArrowClips[ 2 ].w = 330.f;
gArrowClips[ 2 ].h = 125.f;
}
//Load texture
if( !gArrowTexture.loadTextureFromFile( "SpriteSheet.png" ) )
{
printf( "Unable to load texture!\n" );
return false;
}
return true;
}
void update()
{
}
void render()
{
//Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
//Render arrows
gArrowTexture.render( 0.f, 0.f, &gArrowClips[ 0 ] );
gArrowTexture.render( SCREEN_WIDTH - gArrowClips[ 1 ].w, 0.f, &gArrowClips[ 1 ] );
gArrowTexture.render( 0.f, SCREEN_HEIGHT - gArrowClips[ 2 ].h, &gArrowClips[ 2 ] );
//Update screen
glutSwapBuffers();
}
void handleKeys( unsigned char key, int x, int y )
{
//If the user presses q
if( key == 'q' )
{
gViewportMode++;
if ( gViewportMode > VIEWPORT_MODE_N )
{
gViewportMode == VIEWPORT_MODE_C;
}
}
}
|