By Tom Morris
tommorris@planetarybiology.com
www.planetarybiology.com
This tutorial includes paste-in code that will allow your Gtest app to play a wav sound file
of your choice and to display a bitmap image file of your choice -- as an introduction to your
game. I have documented much of the code so you can begin to understand what the heck is going on.
I hope it works for you first time.
INSTRUCTIONS:
1. Open Genvs.c. Find the WinMain function. In the declarations section of the WinMain
function insert my code as shown.
//=====================================================================================
// WinMain
//=====================================================================================
#pragma warning (disable: 4028)
int WINAPI WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
#pragma warning (default: 4028)
geDriver *Driver = NULL;
geDriver_Mode *DriverMode = NULL;
/*MY CODE STARTS HERE=====================================================
ADD THIS CODE TO DECLARATIONS SECTION OF WINMAIN TO SUPPORT
INTRO SOUND AND INTRO BITMAPS
==========================================================================*/
// This is for your Intro Sound stuff.
geSound_Def *IntroSound;
geVFile *IntroSound_File;
extern geVFile *MainFS;
// This is for your intro bitmaps.
geBitmap *Bitmap;
geCamera *Camera;
/*=========================================================================
END OF DECLARATION CODE TO SUPPORT INTRO SOUND AND INTRO BITMAPS
MY CODE ENDS HERE===========================================================*/
SYSTEMTIME SystemTime;
MSG Msg;
char *CmdLine = lpszCmdParam;
int32 i;
LARGE_INTEGER Freq, OldTick, CurTick;
char TempName[256];
int32 TempNameLength;
geBoolean ManualPick=GE_FALSE;
MainTime = 0.0f;
AdjustPriority(THREAD_PRIORITY_NORMAL);
.
.
.
2. Scroll down in the WinMain function until you find the beginning of the While(Running) loop.
Here is the standard Genvs.c code that immediately precedes the While(Running) loop.
}
#endif
Running = TRUE;
VidMode = GameMgr_GetVidMode(GMgr);
hWnd = GameMgr_GethWnd(GMgr);
After this code and just before the While(Running) loop, insert the following code.
/*MY CODE STARTS HERE=====================================================
ADD MUSIC AND IMAGES TO THE INTRODUCTION OF YOUR GAME
BY TOM MORRIS
========================================================================*/
//***********FIRST-- THE MOOOZIC****************************************
// Get the sound system from Game Manager
SoundSys = GameMgr_GetSoundSystem(GMgr);
// Make double sure the sound system is up
assert(SoundSys);
//Make double sure the sound system volume is not set to zero
geSound_SetMasterVolume(SoundSys, 1.0f );
// Tell genesis3d to open a sound file, and where to find it.
// This wav file will now be addressed as IntroSound_File.
IntroSound_File = geVFile_Open(MainFS, "wav\\yourintro.wav",GE_VFILE_OPEN_READONLY);
//Issue a report to the screen if genesis was unable
//to find or open your sound file
if (!IntroSound_File)
GenVS_Error("Failed to geVFile the IntroSound_File");
//Tell genesis to load the IntroSound_File (your wav file) into memory
//and prepare to play it.
//This loaded file will now be addressed as IntroSound.
IntroSound = geSound_LoadSoundDef(SoundSys,IntroSound_File);
//Issue a report to the screen if genesis was unable
//to load IntroSound_File into memory.
if (!IntroSound)
GenVS_Error("Failed to geSound_LoadSoundDef IntroSound");
//Tell genesis to play IntroSound from memory.
//Use the GE_FALSE parameter to specify play ONCE.
geSound_PlaySoundDef(SoundSys,IntroSound,1.0f,0.0f,1.0f,GE_FALSE);
//Issue a report to the screen if genesis was unable
//to play IntroSound using the Sound System.
if (!geSound_PlaySoundDef)
GenVS_Error("Failed to play the IntroSound");
//Stop the sytem from processing additional code while
//the sound file plays. Otherwise, you won't hear a t'ing.
// Only the code in the below do-while loop will be processed.
// When the sound file has completed, genesis will continue to initialize.
do {
//**********NOW -- THE PRETTY PICTURES*******************************************
//While the IntroSound is playing, load some bitmaps onto the screen.
//Get the camera.
Camera = GameMgr_GetCamera(GMgr);
//FIRST BITMAP
//Tell genesis to open your bitmap file and where to find it.
Bitmap = geBitmap_CreateFromFileName(MainFS,"bmp\\yourintro.bmp");
//Load the bitmap into memory and get ready to render.
geEngine_AddBitmap(Engine,Bitmap);
//Establish some screen real estate for your bitmap image.
geEngine_BeginFrame(Engine, Camera, GE_TRUE);
//Draw the bitmap to the screen.
geEngine_DrawBitmap(Engine,Bitmap,NULL,113,114);
//Done. leave it there.
geEngine_EndFrame(Engine);
//Use 'Sleep' if you are putting up more than one bitmap image.
//Sleep(6000); // Pause for 6 seconds
//SECOND BITMAP?
/*
// Open Bitmap
Bitmap = geBitmap_CreateFromFileName(MainFS,"bmp\\your_secondintro.bmp");
// add the bitmap
geEngine_AddBitmap(Engine,Bitmap);
// now render the bitmap:
geEngine_BeginFrame(Engine, Camera, GE_TRUE);
geEngine_DrawBitmap(Engine,Bitmap,NULL,113,114);
geEngine_EndFrame(Engine);
*/
//**********NOW CLEANUP AND GET OUT!*****************************
//Happy time. Your introSound got played and
//your intro bitmaps got seen while we listened to
// the boootiful music.
} while (geSound_SoundIsPlaying(SoundSys,IntroSound));
//Now cleanup your mess. Close and abandon your wav file.
geVFile_Close(IntroSound_File);
//Dump the IntroSound out of memory and free up these resouces.
geSound_FreeSoundDef(SoundSys,IntroSound);
//Just so's everybody understands, IntroSound ain't squat no more.
IntroSound = NULL;
//Now, we ready for the big game.
/*======================================================================
END OF ADD MUSIC AND IMAGES TO THE INTRODUCTION OF YOUR GAME
BY TOM MORRIS
MY CODE ENDS HERE=========================================================*/
while (Running)
{
LARGE_INTEGER DeltaTick;
float ElapsedTime;
geWorld *World;
geCamera *Camera;
GameRunning =TRUE;
3. That's it. Now, you have to specify which wav and bmp files you want to hear and display.
Make sure you have placed them in the wav subdirectory of the src directory, and in the bmp
subdirectory of the src directory for your app. Compile link and go. Ignore warning C4133.