Sign in to follow this  
medevilenemy

A Space Shooter Engine

Recommended Posts

Hi, I recently started writing an OpenGL Top-Down Space Shooter Engine and I have, so far, implemented Texture Mapping, a basic (obviously temporary) image for the player's ship, controls for said ship, and a menu system. I'm not sure yet, but i believe i will need the ability to render DXF models, play some rather simple WAV audio (not 3D audio, just BG music, Voices, and sound effects without complicated filters, etc). Can anyone tell me of any tutorials which will teach these things, also, is there anything anyone thinks I should add besides these things?

Share this post


Link to post
Share on other sites
Use DirectMusic for the sound, it's simple.


//Here's how to set up DirectMusic and the sounds you want to play

IDirectMusicLoader8* Loader;
IDirectMusicPerformance8* Performance;
//Create a segment pointer for each sound effect/music track you have
IDirectMusicSegment8* BGMusic;
IDirectMusicSegment8* SoundEffect;

CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
IID_IDirectMusicLoader8,(void**)&Loader);

CoCreateInstance(CLSID_DirectMusicPerformance, NULL,CLSCTX_INPROC,
IID_IDirectMusicPerformance8,(void**)&Performance);

Performance->InitAudio(
NULL, // IDirectMusic interface not needed.
NULL, // IDirectSound interface not needed.
hWnd, // Window handle.
DMUS_APATH_SHARED_STEREOPLUSREVERB, // Default audiopath type.
64, // Number of performance channels.
DMUS_AUDIOF_ALL, // Features on synthesizer.
NULL // Audio parameters; use defaults.
);

Loader->SetSearchDirectory(
GUID_DirectMusicAllTypes,
//L"C:\\Program Files\\KaZaA\\My Shared Folder"
NULL, // Where to look. Null for default
FALSE // Don't clear object data.
);

BGMusic = loadSound("bgtitlescreen.mid");
SoundEffect = loadSound("explosion.wav");

//You can set this flag for your music if you want it to repeat forever
BGMusic->SetRepeats(DMUS_SEG_REPEAT_INFINITE);

//Here's the loadSound function definition
IDirectMusicSegment8* Audio::loadSound(char* filename)
{
DMUS_OBJECTDESC desc;
IDirectMusicSegment8* seg;
ZeroMemory(&desc,sizeof(LPDMUS_OBJECTDESC));
desc.dwSize = sizeof(DMUS_OBJECTDESC);
desc.guidClass = CLSID_DirectMusicSegment;
desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH;
mbstowcs(desc.wszFileName, filename, MAX_PATH);
Loader->GetObject(&desc, IID_IDirectMusicSegment8, (LPVOID*)&seg);
return seg;
}

//Here's how to play your sounds, I wrapped up each of my sounds into a function
void playBGMusic()
{
BGMusic->Download(Performance);

Performance->PlaySegmentEx(
BGMusic, // Segment to play.
NULL, // Used for songs; not implemented.
NULL, // For transitions.
NULL, // Flags.
0, // Start time; 0 is immediate.
NULL, // Pointer that receives segment state.
NULL, // Object to stop.
NULL // Audiopath, if not default.
);

//For sound effects, you're gonna want the sound effect to play while the
//background music is playing right? Just set the extra flag in the 4 argument
//to let the Performance object know it's a secondary sound like this:
void Audio::playWallHit()
{
SoundEffect->Download(Performance);

Performance->PlaySegmentEx(
SoundEffect, // Segment to play.
NULL, // Used for songs; not implemented.
NULL, // For transitions.
DMUS_SEGF_SECONDARY, // Flags. This is the flag!
0, // Start time; 0 is immediate.
NULL, // Pointer that receives segment state.
NULL, // Object to stop.
NULL // Audiopath, if not default.
);
}




I wrapped up all my audio into a class. Remember to clean up:
Performance->Stop(
NULL, // Stop all segments.
NULL, // Stop all segment states.
0, // Do it immediately.
0 // Flags.
);
Performance->CloseDown();
BGMusic->Release();
SoundEffect->Release();

Remember to include <dmusici.h>.

This should get you started.

Share this post


Link to post
Share on other sites
Quote:
Original post by medevilenemy
thanks, but i'm not using DX in this program -- sticking with good ol' OpenGL and whatever else i can find.


How about OpenAL for sound? Those two API's (OGL and OAL) looks very simliar in terms of code structure, so you shouldn't have a hard time learning the API and OAL can do the same as DirectSound (I'm not entisure how many features OAL has, but professional games like JK:JA III and SoF II use it, so it must contain the relevant features :-P) and is crossplatform, so you can make 3D sound or whatever with it in future projects.

Share this post


Link to post
Share on other sites
For sound I would recomend either OpenAL or FMOD (my pick).

To load models you'll have to write your own code. Pick a model format (try something simple to start with, like the wavefront OBJ format) and google it's file format. e.g. Some model loading tutorials (including the OBJ format) or Nehe's Milkshape model loader tutorial .

Hope this helps.

edit: beaten in OpenAL.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this