示例#1
1
void TextureManager::Preload()
{

#ifdef USE_DEVIL
	ILuint image;
	ilGenImages(1, &image);
	ilBindImage(image);
	ilLoadL(IL_TYPE_UNKNOWN,(ILvoid*) M_data, M_bytes);
	GLuint tex = ilutGLBindTexImage();
#else
	 unsigned int tex = SOIL_load_OGL_texture_from_memory(
					  M_data,
					  M_bytes,
					  SOIL_LOAD_AUTO,
					  SOIL_CREATE_NEW_ID,

					    SOIL_FLAG_POWER_OF_TWO
					  |  SOIL_FLAG_MULTIPLY_ALPHA
					 // |  SOIL_FLAG_COMPRESS_TO_DXT
					  );
#endif

  textures["M.tga"]=tex;

#ifdef USE_DEVIL
  ilLoadL(IL_TYPE_UNKNOWN,(ILvoid*) project_data,project_bytes);
  tex = ilutGLBindTexImage();
#else
  tex = SOIL_load_OGL_texture_from_memory(
					  project_data,
					  project_bytes,
					  SOIL_LOAD_AUTO,
					  SOIL_CREATE_NEW_ID,

					  SOIL_FLAG_POWER_OF_TWO
					  |  SOIL_FLAG_MULTIPLY_ALPHA
					  //|  SOIL_FLAG_COMPRESS_TO_DXT
					  );
#endif

  textures["project.tga"]=tex;

#ifdef USE_DEVIL
  ilLoadL(IL_TYPE_UNKNOWN,(ILvoid*) headphones_data, headphones_bytes);
  tex = ilutGLBindTexImage();
#else
  tex = SOIL_load_OGL_texture_from_memory(
					  headphones_data,
					  headphones_bytes,
					  SOIL_LOAD_AUTO,
					  SOIL_CREATE_NEW_ID,

					  SOIL_FLAG_POWER_OF_TWO
					  |  SOIL_FLAG_MULTIPLY_ALPHA
					 // |  SOIL_FLAG_COMPRESS_TO_DXT
					  );
#endif

  textures["headphones.tga"]=tex;
}
void ViewSimple2D::initGraphics( unsigned int fontId )
{
	GameView::initGraphics( fontId );

	// Load the images for the Pumpkin icons
	ilGenImages( 1, &m_ilPumpkinIcons );
	if (!ilLoadImage( "gamedata/pumpkin-icons.png" )) 
		printf("Loading pumpkin-icons.png image failed\n");
		
	m_texPumpkinIcons = ilutGLBindTexImage();	

	// Load the images for the particles
	ilGenImages( 1, &m_ilParticles );
	if (!ilLoadImage( "gamedata/particles.png" )) 
		printf("Loading particles.png image failed\n");
		
	m_texParticles = ilutGLBindTexImage();	

	// group colors
	m_groupColor.push_back( vec3f( 1.0, 217.0/255.0, 147.0/255.0 ) );
	m_groupColor.push_back( vec3f( 232.0/255.0, 192.0/255.0, 1.0 ) );
	m_groupColor.push_back( vec3f( 0.5, 1.0, 1.0 ) );
	m_groupColor.push_back( vec3f( 1.0, 1.0, 1.0 ) );
	m_groupColor.push_back( vec3f( 1.0, 0.5, 0.5 ) );

	m_burntime = 0.0;
	m_lastComboAge = 100.0;
}
示例#3
0
int Sprite::LoadImage(char *filename)
{
	// IL image ID
	ILuint ImgId = 0;

	// Generate the main image name to use
	ilGenImages(1, &ImgId);
	// Bind this image name
	ilBindImage(ImgId);
	// Loads the image specified by File into the ImgId image
	if (!ilLoadImage(filename))
	{
		ILenum err = ilGetError();
		printf("An error occured while loading %s: %d (%s)\n", filename, err, iluErrorString(err));
		return 0;
	}
	
	// Get image width and height
	width = (int) ilGetInteger(IL_IMAGE_WIDTH);
	height = (int) ilGetInteger(IL_IMAGE_HEIGHT);
	bpp = (int) ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);

	// Enable texturing
	glEnable(GL_TEXTURE_2D);

	// Goes through all steps of sending the image to OpenGL
	TexName = ilutGLBindTexImage();

	// We're done with our image, so we go ahead and delete it
	ilDeleteImages(1, &ImgId);

	isDefined = true;

	return 1;
}
示例#4
0
Texture::Texture(QString n) {
    valid=false;
    name=NULL;
    ERRCHK;
    QByteArray ba = n.toLocal8Bit();
    const char *fname = ba.constData();
    
    if(strlen(fname)<3)
        throw Exception().set("silly texture file name '%s'",fname);
    
    ILuint img;
    ilGenImages(1,&img);
    ilBindImage(img);
    
    if(!ilLoadImage(fname)){
        handleDevilErrors(fname);
        return;
    }
    
    mWidth = ilGetInteger(IL_IMAGE_WIDTH);
    mHeight = ilGetInteger(IL_IMAGE_HEIGHT);
    
    id = ilutGLBindTexImage();
    handleDevilErrors(fname);
    ilDeleteImages(1,&img);
    
    glBindTexture(GL_TEXTURE_2D,id);
    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 );
    name = strdup(fname);
    valid=true;
}
void World::init()
{
	//bg = new BGMondrian();

	glDisable( GL_CULL_FACE );
//	glFillMode( GL_SOLID );
	
	glEnable( GL_TEXTURE_2D );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );		
	
	// fretboard image
	ilGenImages( 1, &ilFretboard );
	if (!ilLoadImage( (ILstring)"gamedata/fretboard.png" ))
	{
		printf("Loading fretboard image failed.\n" );
	}	
	texFretboard = ilutGLBindTexImage();

	// gem image
	ilGenImages( 1, &ilGem );
	if (!ilLoadImage( (ILstring)"gamedata/gem.png" ))
	{
		printf("Loading gem image failed.\n" );
	}

	texGem = ilutGLBindTexImage();

	// target image
	ilGenImages( 1, &ilTarget );
	if (!ilLoadImage( (ILstring)"gamedata/target.png" ))
	{
		printf("Loading target image failed.\n" );
	}

	texTarget = ilutGLBindTexImage();

	// background image
	ilGenImages( 1, &ilBackground );
	if (!ilLoadImage( (ILstring)"gamedata/bg.png" ))
	{
		printf("Loading bg image failed.\n" );
	}

	texBackground = ilutGLBindTexImage();
}
示例#6
0
		GLuint LoadImage(std::string name)
		{
			ILuint ImageName;
			if((ImageName=ImagePrivate::DevilLoadImage(name))==0)
				return 0;
			GLuint ID = ilutGLBindTexImage();
			ilDeleteImages(1, &ImageName);
			return ID;
		}
示例#7
0
/***********************************************************
load a texture in memory
***********************************************************/
bool TextWritter::LoadGLTextures(const std::string & textureName, unsigned int & textureHandler)
{
	ILuint ImgId = 0;
	ilGenImages(1, &ImgId);
	ilBindImage(ImgId);
	ilLoadImage(const_cast<char *>(textureName.c_str()));
	textureHandler = ilutGLBindTexImage();
	ilDeleteImages(1, &ImgId);

	return true;
}
示例#8
0
		GLuint LoadImage(std::string name, unsigned int& width, unsigned int& height)
		{
			ILuint ImageName;
			if((ImageName=ImagePrivate::DevilLoadImage(name))==0)
				return 0;
			width = ilGetInteger(IL_IMAGE_WIDTH);
			height = ilGetInteger(IL_IMAGE_HEIGHT);
			GLuint ID = ilutGLBindTexImage();
			ilDeleteImages(1, &ImageName);
			return ID;
		}
void initGraphics() {
		ilGenImages( 1, &ImageName );

		ilBindImage( ImageName );
		glEnable( GL_TEXTURE_2D );
		glEnable( GL_BLEND );
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
		if (!ilLoadImage( "gamedata/bg-art.png" )) {
			printf("Loading image bg-art failed\n");
		}

		
		gl_tex_id = ilutGLBindTexImage();
		//ilutGLTexImage( gl_tex_id );

		initGamepadDiagram();				
}
示例#10
0
//
// Setup OpenGL to use our image.
//
ILboolean Setup()
{
	glEnable       (GL_TEXTURE_2D);  // Enable texturing.
	glMatrixMode   (GL_PROJECTION);  // We want to use the projection matrix.
	glLoadIdentity ();  // Loads the identity matrix into the current matrix.

	// Lets ILUT know to use its OpenGL functions.
	ilutRenderer (ILUT_OPENGL);
	
	// Goes through all steps of sending the image to OpenGL.
	TexID = ilutGLBindTexImage();
	
	// We're done with our image, so we go ahead and delete it.
	ilDeleteImages(1, &ImgId);

	glOrtho(0, Width, Height, 0, -1, 1);  // Set up an orthographic projection with OpenGL.

	return IL_TRUE;
}
GLuint getTexture( const std::string &filename, int *xsize, int *ysize )
{
	GLuint texId;

	// See if the texture is already loaded
	TextureDB::iterator ti;
	ti = g_textureDB.find( filename );
	if (ti == g_textureDB.end() )
	{
		// Load the font image
		ILuint ilImgId;
		ilGenImages( 1, &ilImgId );
		ilBindImage( ilImgId );		
	
		if (!ilLoadImage( (ILstring)filename.c_str() )) {
			printf("Loading font image failed\n");
		}
//		printf("Loaded Texture %s\n", filename.c_str() );
	
		// Make a GL texture for it
		texId = ilutGLBindTexImage();		

		// and remember it
		g_textureDB[ filename ] = texId;
	}
	else
	{
		// found the texture
		texId = (*ti).second;
	}

	// now get the size if they asked for it
	if ((xsize) && (ysize))
	{
		glBindTexture( GL_TEXTURE_2D, texId );
		glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, xsize );
		glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, ysize );
	}

	return texId;
}
示例#12
0
文件: Texture.hpp 项目: Tycheo/r3e
	virtual bool Load(const char* pathV){
		static bool hasInitIL = false;
		if(!hasInitIL){
			ilInit();
			ilutRenderer(ILUT_OPENGL);
			hasInitIL = true;
		}

		String path = pathV;
		FILE_SYS()->GetFullPath(path);
		ILuint ilTex;
		ilGenImages(1, &ilTex);
		ilBindImage(ilTex);
		if(!ilLoadImage(path)) return false;
		mWidth = ilGetInteger(IL_IMAGE_WIDTH);
		mHeight = ilGetInteger(IL_IMAGE_HEIGHT);
		iluFlipImage();

		mTexID = ilutGLBindTexImage();
		ilDeleteImages(1, &ilTex);

		return true;
	}
示例#13
0
GLuint ilOgl::BindTex(ilImage &Image)
{
	Image.Bind();
	return ilutGLBindTexImage();
}
示例#14
0
文件: 3dtest.c 项目: AMDmi3/DevIL
ILboolean GenSides()
{
	ILubyte	*Buffer, *Data, Bpp, Bpc;
	ILuint	TempImage;
	ILenum	Format, Type;
	ILint	SizePlane, Bps, c, y, z, i;

	ilActiveImage(ActiveImage);
	Bpp = ilGetInteger(IL_IMAGE_BPP);
	Bpc = ilGetInteger(IL_IMAGE_BPC);
	Format = ilGetInteger(IL_IMAGE_FORMAT);
	Type = ilGetInteger(IL_IMAGE_TYPE);

	// Front
	TexID1 = ilutGLBindTexImage();
	Width = ilGetInteger(IL_IMAGE_WIDTH);
	Height = ilGetInteger(IL_IMAGE_HEIGHT);
	Depth = ilGetInteger(IL_IMAGE_DEPTH);
	ilGenImages(1, &TempImage);

	SizePlane = ilGetInteger(IL_IMAGE_PLANESIZE);

	SizePlane = Width * Height * Bpp * Bpc;
	Bps = Width * Bpp * Bpc;
	Data = ilGetData();

	// Left
	i = 0;
	Buffer = (ILubyte*)malloc(Height * Depth * Bpp * Bpc);
	for (y = 0; y < Height; y++) {
		for (z = 0; z < Depth; z++) {
			for (c = 0; c < Bpp * Bpc; c++) {
				Buffer[i++] = Data[z * SizePlane + y * Bps + c];
			}
		}
	}
	ilBindImage(TempImage);
	ilTexImage(Depth, Height, 1, Bpp, Format, Type, Buffer);
	TexID2 = ilutGLBindTexImage();
	free(Buffer);

	// Right
	ilBindImage(ImgId);
	ilActiveImage(ActiveImage);
	i = 0;
	Buffer = (ILubyte*)malloc(Height * Depth * Bpp * Bpc);
	for (y = 0; y < Height; y++) {
		for (z = 0; z < Depth; z++) {
			for (c = 0; c < Bpp * Bpc; c++) {
				Buffer[i++] = Data[z * SizePlane + y * Bps + (Width - 1) * Bpp * Bpc + c];
			}
		}
	}
	ilBindImage(TempImage);
	ilTexImage(Depth, Height, 1, Bpp, Format, Type, Buffer);
	TexID3 = ilutGLBindTexImage();
	free(Buffer);

	// Back
	ilBindImage(ImgId);
	ilActiveImage(ActiveImage);
	Buffer = (ILubyte*)malloc(Width * Height * Bpp * Bpc);
	ilCopyPixels(0, 0, Depth-1, Width, Height, 1, Format, Type, Buffer);
	ilBindImage(TempImage);
	ilTexImage(Width, Height, 1, Bpp, Format, Type, Buffer);
	TexID4 = ilutGLBindTexImage();
	free(Buffer);

	//ilDeleteImages(1, &ImgId);
	ilDeleteImages(1, &TempImage);

	ilBindImage(ImgId);

	return IL_TRUE;
}
int main( int argc, char *argv[]) {

// this was a quick test of InetOpenURL
#if 0
	HINTERNET hnet = InternetOpen( "Game", INTERNET_OPEN_TYPE_PRECONFIG, 
									NULL, NULL, 0 );
	HINTERNET hfile = InternetOpenUrl( hnet, "http://www.yahoo.com", 
										NULL, 0, 
										INTERNET_FLAG_DONT_CACHE, 0);
	char buff[5000];
	unsigned long nread;
	InternetReadFile( hfile, buff, 5000, &nread );
	buff[nread] = 0;
	printf( buff );
#endif

	if ( SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_AUDIO|SDL_INIT_VIDEO |SDL_INIT_JOYSTICK) < 0 ) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }

	if( SDL_SetVideoMode( 800, 600, 16, SDL_OPENGL /*| SDL_FULLSCREEN */ ) == 0 ) {
		fprintf(stderr,	"Unable to set video mode: %s\n", SDL_GetError());
        exit(1);
	}

	SDL_WM_SetCaption( "The Halloween Machine", NULL );

	// Init SDL_Mixer
	if (Mix_OpenAudio( 22050, AUDIO_S16, 2,  4096 )) {
		fprintf(stderr,	"Unable to open audio\n");
        exit(1);
	}

	// Initialize Joysticks/Gamepads
	printf("%d Controllers found.\n", SDL_NumJoysticks() );
	for (int i=0; i < SDL_NumJoysticks(); i++) {
		printf( "Controller %d: %s\n", i, SDL_JoystickName(i) );
	}
	gamepad.name = "No gamepad detected.";
	gamepad.sdlinfo = NULL;
	gamepad.stick = vec2f(0.0, 0.0 );
	gamepad.stick2 = vec2f(0.0, 0.0 );

	// Only use the first controller
	if (SDL_NumJoysticks() > 0 ) {
		gamepad.sdlinfo = SDL_JoystickOpen(0);
	}

	// init highscores
	readHighScores();	

	if (gamepad.sdlinfo) {
		gamepad.name = strdup( SDL_JoystickName(0) );
		printf( "Gamepad: Number of axes: %d\n", SDL_JoystickNumAxes(gamepad.sdlinfo) );
		printf( "Gamepad: Number of buttons: %d\n", SDL_JoystickNumButtons(gamepad.sdlinfo) );
		printf( "Gamepad: Number of balls: %d\n", SDL_JoystickNumBalls(gamepad.sdlinfo) );
		printf( "Gamepad: Number of hats: %d\n", SDL_JoystickNumHats(gamepad.sdlinfo) );
	}

	

	// initialize DevIL
	ilInit();
	ilutRenderer( ILUT_OPENGL );

	// Setup glgameFont
	
	// Load the font image
	ilGenImages( 1, &ilFontId );
	ilBindImage( ilFontId );		
	
	if (!ilLoadImage( "gamedata/magic.png" )) {
		printf("Loading font image failed\n");
	}
	
	// Make a GL texture for it
	glFontTexId = ilutGLBindTexImage();

	// Create a font by passing in an opengl texture id
	fntFontId = gfCreateFont( glFontTexId );

	// A .finfo file contains the metrics for a font. These
	// are generated by the Fontpack utility.
	gfLoadFontMetrics( fntFontId, "gamedata/magic.finfo");

	printf("font has %d chars\n", gfGetFontMetric( fntFontId, GF_FONT_NUMCHARS ) );
	gfEnableFont( fntFontId, 25 );		

	sfx[0] = Mix_LoadWAV("gamedata/whiit.wav");
	sfx[1] = Mix_LoadWAV("gamedata/didge.wav");
	sfx[2] = Mix_LoadWAV("gamedata/sfx_boom.wav");
	sfx[3] = Mix_LoadWAV("gamedata/harp.wav");
	sfx[4] = Mix_LoadWAV("gamedata/secret.wav");

	music_title = Mix_LoadMUS( "gamedata/AutumnLeft.ogg" );
	music_gameover = Mix_LoadMUS( "gamedata/YouDiedLoser.ogg" );
	music_ingame = Mix_LoadMUS( "gamedata/ingame.ogg" );

	if (!music_title) {
		printf("Error loading music %s\n", Mix_GetError() );
	} else {
		printf("Music loaded\n");
	}
	Mix_PlayMusic( music_title, -1 );

	
	// Start up the game
	g_game = new GameState();
	g_game->init();

	g_game->loadLevels( "gamedata/levels.txt" );

	g_view = new ViewSimple2D( g_game );
	g_game->setView( g_view );	

	//////////////////////
	// Event Loop
	//////////////////////
	while (1) {		
    SDL_Event event;

    /* Grab all the events off the queue. */
    while( SDL_PollEvent( &event ) ) {
		
        switch( event.type ) {
        case SDL_KEYDOWN:

			// are we reading highscore??
			if (ndxGetName >=0 ) {
				char buff[10];
				if ( ((event.key.keysym.sym >= SDLK_a) && (event.key.keysym.sym <= SDLK_z)) ||					 
					 ((event.key.keysym.sym >= SDLK_0) && (event.key.keysym.sym <= SDLK_9))) {
					sprintf( buff, "%c", (char)event.key.keysym.sym );

					if (event.key.keysym.mod & (KMOD_LSHIFT|KMOD_RSHIFT)) {
						buff[0] = toupper(buff[0]);
					}

					if (!strcmp(g_highScoreTable[ndxGetName].m_name.c_str(), HISCORE_PROMPT)) {
						g_highScoreTable[ndxGetName].m_name = "";
					}

					g_highScoreTable[ndxGetName].m_name.append( buff);

				} else if ( (event.key.keysym.sym==SDLK_BACKSPACE) ) {
					if (g_highScoreTable[ndxGetName].m_name.length()){ 
						g_highScoreTable[ndxGetName].m_name.erase( 
											g_highScoreTable[ndxGetName].m_name.end()-1 );
					}
				} else if ( (event.key.keysym.sym==SDLK_RETURN) ||
					      (event.key.keysym.sym==SDLK_ESCAPE) ) {

					if (!g_highScoreTable[ndxGetName].m_name.length()) {
						g_highScoreTable[ndxGetName].m_name = "Anonymous";
					}

					ndxGetName = -1;


					writeHighScores();
				}

				break;
			} 

            switch( event.key.keysym.sym ) {

				case SDLK_ESCAPE:				
					if ( (g_state==STATE_TITLE) &&
						(g_menuState == MENU_MAINMENU)) {
						do_quit();
					} else {
						backToTitleScreen();
					}
					break;

				case SDLK_a:
					g_view->toggleAnim();
					break;

				case SDLK_p:
					paused = !paused;
					break;

// Cheat codes.. enable for testing
#if 0
				case SDLK_z:
					if (g_state==STATE_GAMEOVER) {
						ndxGetName = 3;
						break;
					}
	
					

				case SDLK_1:
					g_game->dbgNextPumpkin( PUMPKIN );
					break;
				case SDLK_2:
					g_game->dbgNextPumpkin( PUMPKIN_ORANGE );
					break;
				case SDLK_3:
					g_game->dbgNextPumpkin( PUMPKIN_YELLOW );
					break;
				case SDLK_4:
					g_game->dbgNextPumpkin( PUMPKIN_RED );
					break;
				case SDLK_5:
					g_game->dbgNextPumpkin( SKULL );
					break;
				case SDLK_6:
					g_game->dbgNextPumpkin( FISH_HEAD );
					break;
				case SDLK_7:
					g_game->dbgNextPumpkin( BLACKBIRD );
					break;

				case SDLK_8:
					g_game->dbgClearQueue();
					break;
#endif


				case SDLK_s:
					ilutGLScreenie();
					break; 

				case SDLK_d:
					bDrawGamepad = !bDrawGamepad;
					break;

				case SDLK_m:					

					if (!musicOn) {
						printf("Playing\n");
						if (g_state==STATE_TITLE) {
							Mix_PlayMusic( music_title, -1 );
						} else if (g_state==STATE_PLAYING) {
							Mix_PlayMusic( music_ingame, -1 );
						} else if (g_state==STATE_GAMEOVER) {
							// easter egg.. kindof.. you get to hear the
							// game over music again. woo.
							Mix_PlayMusic( music_gameover, 0 );
						}
						musicOn = 1;
					} else {
						printf("Halting\n");
						Mix_HaltMusic();
						musicOn = 0;
					}


				case SDLK_LEFT:
					g_view->nextStation();
					break;
				case SDLK_RIGHT:
					g_view->prevStation();
					break;

				case SDLK_SPACE:
				case SDLK_RETURN:
					if (g_state == STATE_PLAYING) {
						doActivateStation();
					} else {
						doStartButton();
					}
					
					break;

				case SDLK_UP:
					if (g_state==STATE_PLAYING) {
						//g_view->activateStation();
						doActivateStation();
					} else if (g_state==STATE_TITLE ) {
						prevMenuItem();						
					}
					break;

				case SDLK_DOWN:
					if (g_state==STATE_TITLE ) {
						nextMenuItem();						
					}
					break;

				default:
					break;
				}
			break;

		

		case SDL_JOYAXISMOTION:  /* Handle Joystick Motion */
			if ( ( event.jaxis.value < -3200 ) || (event.jaxis.value > 3200 ) ) 
			{				

				switch(event.jaxis.axis) {				
				case 0:
					gamepad.stick[0] = (float)(event.jaxis.value) / 32768.0f;
					break;
				case 1:
					gamepad.stick[1] = (float)(event.jaxis.value) / 32768.0f;
					break;
				case 2:
					gamepad.throttle = (float)(event.jaxis.value) / 32768.0f;
					break;
				case 3:
					gamepad.stick2[0] = (float)(event.jaxis.value) / 32768.0f;
					break;
				case 4:															
					gamepad.stick2[1] = (float)(event.jaxis.value) / 32768.0f;					
					break;						
				}				
				
			} else {
				// prevent jitter near the center positions
				switch(event.jaxis.axis) {
				case 0:
					gamepad.stick[0] = 0.0;
					break;
				case 1:
					gamepad.stick[1] = 0.0;
					break;
				case 2:
					gamepad.throttle = 0.0;
					break;
				case 3:
					gamepad.stick2[0] = 0.0;
					break;
				case 4:
					gamepad.stick2[1] = 0.0;
					break;				
				}
			}
			break;

		case SDL_JOYBUTTONDOWN:  /* Handle Joystick Button Presses */
			gamepad.button[event.jbutton.button] = true;
			
			switch (event.jbutton.button) {
			case 0:				
				//g_view->activateStation();
				if (g_state==STATE_PLAYING) {
					doActivateStation();
				} else {
					doStartButton();
				}
				break;
			//case 1:
			//	sfx_chan[1] = Mix_PlayChannel(-1, sfx[1], 0);
			//	break;
			//case 2:
			//	sfx_chan[2] = Mix_PlayChannel(-1, sfx[2], 0);
			//	break;

			case 8: // start button 
				doStartButton();				
				break;

			}
			break;

		case SDL_JOYBUTTONUP:  /* Handle Joystick Button Release */
			gamepad.button[event.jbutton.button] = false;			
			break;

		case SDL_JOYHATMOTION:  /* Handle Hat Motion */			
			gamepad.hat = event.jhat.value;			

			if (g_state==STATE_PLAYING) {
	
				if (gamepad.hat & SDL_HAT_LEFT) {
				
					g_view->nextStation();
				}

				if (gamepad.hat & SDL_HAT_RIGHT) {
					g_view->prevStation();
				}				
			} else {
				if (gamepad.hat & SDL_HAT_UP) {
				
					prevMenuItem();
				}

				if (gamepad.hat & SDL_HAT_DOWN) {
					nextMenuItem();
				}
			}

			break;
			case SDL_QUIT:
				/* Handle quit requests (like Ctrl-c). */
				if ( (g_state==STATE_TITLE) &&
					(g_menuState == MENU_MAINMENU)) {
					do_quit();
				} else {
					backToTitleScreen();
				}
				break;
			}	
		}
		redraw();
	}
	return 0;
} 
void IslandGame::initGraphics( )
{
	// Load Font	
	ilGenImages( 1, &m_ilFontId );
	ilBindImage( m_ilFontId );		
	
	if (!ilLoadImage( (ILstring)"gamedata/digistrip.png" )) {
		errorMessage("Loading font image failed\n");
	}
	
	// Make a GL texture for it
	m_glFontTexId = ilutGLBindTexImage();
	m_fntFontId = gfCreateFont( m_glFontTexId );

	// A .finfo file contains the metrics for a font. These
	// are generated by the Fontpack utility.
	gfLoadFontMetrics( m_fntFontId, "gamedata/digistrip.finfo");

	_RPT1( _CRT_WARN, "font has %d chars\n", 
		gfGetFontMetric( m_fntFontId, GF_FONT_NUMCHARS ) );					

	// Load the player sprite
	m_playerTex = loadTexture( "gamedata/npc_player.png", 4 );
	m_personMesh = load_obj( "gamedata/person.obj");

	// Load critters	
	m_critterMesh = load_obj( "gamedata/hemi_critter.obj");

	// Load the tiles
	m_terrainTilesTexId  = loadTexture( "gamedata/tiles.png", 4 );

	m_waterTexId  = loadTexture( "gamedata/water.png", 4 );

	// Load sounds while we're at it
	FMOD_RESULT res;
	res = m_fmod->createSound(  "gamedata/wall.wav", FMOD_HARDWARE, 0, &sfx_wall );
	ERRCHECK( res );

	res = m_fmod->createSound(  "gamedata/blang.wav", FMOD_HARDWARE, 0, &sfx_blahblah );
	ERRCHECK( res );

	res = m_fmod->createStream( "gamedata/galapagos.mp3", 
		FMOD_HARDWARE |FMOD_LOOP_NORMAL | FMOD_2D,
									0, &m_music );
	ERRCHECK( res );

	FMOD::Channel *chan=0;
	res = m_fmod->playSound(FMOD_CHANNEL_FREE, m_music, false, &chan);
	ERRCHECK( res );

	//sfx_blahblah = FSOUND_Sample_Load( FSOUND_UNMANAGED, "gamedata/sfxr_blang.wav", FSOUND_NORMAL, 0, 0 );

	// Set up simple lighting	
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = { 50.0 };
	GLfloat light_direction[] = { -0.5, 1.0, 0.5, 0.0 };
	GLfloat light_ambient[] = { 2.0, 2.0, 2.0, 1.0 };
	GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };

	vec3f lightDir( -0.5, 1.0, 0.5 );
	lightDir.Normalize();
	light_direction[0] = lightDir.x;
	light_direction[1] = lightDir.y;
	light_direction[2] = lightDir.z;


	//glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	//glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glLightfv(GL_LIGHT0, GL_POSITION, light_direction);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);

	glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);	

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);

	glEnable(GL_DEPTH_TEST);

}
void TransIcelandicExpress::redraw( void ) {	

	static tex_init = 0;	

	
	if (!tex_init) {		

		ilutRenderer( ILUT_OPENGL );

		ilGenImages( 1, &ImageName );

		ilBindImage( ImageName );
		glEnable( GL_TEXTURE_2D );
		glEnable( GL_BLEND );
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
		if (!ilLoadImage( "ludum48.png" )) {
			printf("Loading image failed\n");
		}

		
		gl_tex_id = ilutGLBindTexImage();
		ilutGLTexImage( 0 );

		tex_init = 1;
	} 

	glBindTexture (GL_TEXTURE_2D, gl_tex_id );

	glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	//glEnable( GL_CULL_FACE );
	glEnable( GL_DEPTH_TEST );

	// 3d part
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 60.0, 800.0/600.0, 0.05, 100.0 );



	gluLookAt(	player->pos[0]+cameraPos[0], 
				player->pos[1]+cameraPos[1]+c_PlayerHeight, 
				player->pos[2]+cameraPos[2],

				player->pos[0], 
				player->pos[1]+ c_PlayerHeight, 
				player->pos[2],

				0.0, 1.0, 0.0 );
				

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	// apply some of the camera xform to the light just to make
	// it more shiny
	glPushMatrix();
	float viewHead = atan2( cameraPos[2], cameraPos[0] );	
	glRotated( viewHead * SG_RADIANS_TO_DEGREES, 0.0f, 1.0f, 0.0f );
	setupLights();
	glPopMatrix();

	draw3d();

	// 2d part
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();	
	gluOrtho2D( 0, 800, 0, 600 ) ;

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glDisable( GL_LIGHTING );
	draw2d();

	SDL_GL_SwapBuffers();

}