By Tom Morris
tommorris@planetarybiology.com
www.planetarybiology.com


Download the zipped up tutorial and sources HERE.


=================================================================
INSTRUCTIONS FOR INSTALLING SOUNDMANAGER INTO PROJECTX
=================================================================

1. Open up ProjectX dsw in MSVC++

2. In ProjectX.h, add the following INCLUDE:

#include "SoundMgr.h"

3. In ProjectX.h, at the top, add the following declaration to support Introduction().

geBoolean Introduction(void); //added to support introduction

4. In ProjectX.c, add the following INCLUDES:

#include "bitmap.h"
#include "SoundMgr.h"
#include "Errorlog.h"
#include <direct.h> //_chdir()


5. In ProjectX.c, at the top, add the following declarations to support GenVS_Error

geBoolean PopupD3DLog = GE_FALSE;
void GenVS_Error(const char *Msg, ...);


6. In ProjectX.c, add the following code for Introduction()


//===================================================================================
//FUNCTION ADDED BY TOM TO SUPPORT INTRODUCTION
//====================================================================================
geBoolean Introduction()
{
geBitmap *Bitmap;
geCamera *Camera;

//this call feeds the soundfile to SMgr and SMgr plays it and closes it out.
SoundMgr_DoSound(SMgr, "wav\\yourintro.wav");


//While the SoundDef is playing, load some bitmaps onto the screen.

//Get the camera.
Camera = geCamera_Create(2.0f, &Rect);

if (!Camera) // check for errors
GenVS_Error("Failed to get camera");

//FIRST BITMAP
//Tell genesis to open your bitmap file and where to find it.
Bitmap = geBitmap_CreateFromFileName(NULL, "graphics\\yourbitmap.bmp");

if (!geBitmap_CreateFromFileName) // check for errors
GenVS_Error("Failed to get bitmap");

//Load the bitmap into memory and get ready to render.
geEngine_AddBitmap(Engine,Bitmap);

if (!geEngine_AddBitmap) // check for errors
GenVS_Error("Failed to add bitmap");

//Establish some screen real estate for your bitmap image.
geEngine_BeginFrame(Engine, Camera, GE_TRUE);

if (!geEngine_BeginFrame) // check for errors
GenVS_Error("Failed to begin frame");

//Draw the bitmap to the screen.
geEngine_DrawBitmap(Engine,Bitmap,NULL,113,114);

if (!geEngine_DrawBitmap) // check for errors
GenVS_Error("Failed to draw bitmap");

//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(NULL,"graphics\\yourbitmap.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);
*/

return(GE_TRUE);
}

//Now, we ready for the big game.

/*======================================================================
END OF INTRODUCTION FUNCTION
BY TOM MORRIS
========================================================================*/


7. In ProjectX.c, in the WINMAIN function, add the Introduction() call after LoadHud() and
before MainLoop()...like so:


// initialize the hud
LoadHUD (Engine, CWidth, CHeight);
if (!LoadHUD)
GenVS_Error("Failed to loadHUD");

// play an introduction with sound and pictures
Introduction();


// do everything
MainLoop();

7.5 In ProjectX.c, in the KillApp() function, add the following line of
code:

SoundMgr_Destroy(SMgr);

8. If you are having trouble with the HUD load like I am, comment the LoadHud call out.

9. In ProjectX.c, add the following code for the GenVS_Error function. Put it at the end if you want.

Obviously, I stole this from the Gtest source - so sue me.

// INCLUDE A WAY TO CHECK AND REPORT ERRORS
//=====================================================================================
// GenVS_Error
//=====================================================================================
extern geBoolean PopupD3DLog;
static geBoolean ErrorHandled = GE_FALSE;

void GenVS_Error(const char *Msg, ...)
{
va_list ArgPtr;
char TempStr[1024];
char TempStr2[1024];
FILE *f;

if (ErrorHandled)
return;

ErrorHandled = GE_TRUE;

va_start (ArgPtr, Msg);
vsprintf (TempStr, Msg, ArgPtr);
va_end (ArgPtr);

KillApp();

f = fopen("GTest.Log", "wt");

if (f)
{
int32 i, NumErrors;

NumErrors = geErrorLog_Count();

fprintf(f, "Error#:%3i, Code#:%3i, Info: %s\n", NumErrors, 0, TempStr);

for (i=0; i<NumErrors; i++)
{
geErrorLog_ErrorClassType Error;
char *String;

if (geErrorLog_Report(NumErrors-i-1, &Error, &String))
{
fprintf(f, "Error#:%3i, Code#:%3i, Info:%s\n", NumErrors-i-1, Error, String);
}
}

fclose(f);

sprintf(TempStr2, "%s\nPlease refer to GTest.Log for more info.", TempStr);

MessageBox(0, TempStr2, "** Genesis3D Virtual System Error **", MB_OK);
WinExec( "Notepad GTest.Log", SW_SHOW );
if (PopupD3DLog)
{
WinExec( "Notepad d3ddrv.log", SW_SHOW);
}
}
else
{
sprintf(TempStr2, "%s\nCould NOT output GTest.log!!!", TempStr);

MessageBox(0, TempStr2, "** Genesis3D Virtual System Error **", MB_OK);
}

_exit(1);
}

//=====================================================================================
// End of GenVS_Error
//=====================================================================================


10. In InitGenesis.c, make sure you have the following includes

#include <windows.h>
#include "procedurals\proceng.h"
#include "projectx.h"
#include "SoundMgr.h"


11. In InitGenesis.c, add the following declaration near the top for error handling (for now)

extern int GenVS_Error();

12. In InitGenesis.c, near the end of the InitGenesis() function, add the call for SMgr
after Camera and before LoadLevel, like so...


// create a camera into our world
Camera = geCamera_Create(2.0f, &Rect);
if (!Camera)
{
MessageBox(mainwindowhandle,"No Camera","Error", MB_OK);
_exit(-1);
}

//initialize SoundMgr and link it to the the game window
SMgr = SoundMgr_Create(mainwindowhandle);

//Load up a good starting level
// LoadLevel("levels\\genvs.bsp");
LoadLevel("levels\\genvX.bsp");

// load a figure model and insert into the game
LoadPlayerActor();


13. In Global.c, add the following declaration (this might not be necessary):

geSound_System *SoundSys;

14. Exract SoundMgr.h and SoundMgr.c from the SoundMgr.zip file. Place them both in the
ProjectX root directory along with your other src and header files. Then, in MSVC add
them to the 'Source Files' and 'Header Files' directories in your ProjectX workspace.

15. You need to place your own wav (*.wav) sound files into the ProjectX\wav directory. And you need
to place your own bitmap (*.bmp) picture files into the ProjectX\graphics directory.

16. Adjust the code in Introduction() (in ProjectX.c) to reflect the names of your wav and bitmap files.

17. Compile and go.

18. I hope this works right for you the first time. And I hope I haven't forgotten anything.