Soon to come - DJGPP stuff - code, links, etc... Come back soon.
My beginner's guide to game programming
This page is for people who want
to find out about how to program games in Windows and gives some examples
of how you can achieve some difficult things with as little fuss as possible.
I'm creating this page because I've found it very hard to find certain things
on the Internet to do with game programming especially playing MIDI files,
and when I did eventually find how to play MIDI files in Windows(At the time
I couldn't find it in the Borland C++ 5.0 help files) it was allot easier than
I thought and when I searched in the Borland C++ help files for one of the API
functions that it called - There was the code that I had spend countless hours
looking for on the Internet - The exact same code, word for word, even
though I had searched through the Borland C++ help files time and time again for
it.
As you have probebly gathered by now, I program in Borland C++
so naturally all of the code here is written in Borland C++ although I think
that most of the code should work with Microsoft Visual C++ since the MIDI
code was found on Microsoft's site(And in the Borland C++ help files) and I
would presume that Miscosoft wouldn't have code on their web pages that didn't
work with their own software, you know Microsoft. Even though I think it should
work with Microsoft Visual C++ and other Windows C++ compilers I wouldn't guarantee
it, but if it doesn't I would like to know so that I can make a special note
about it here and it would be great if you could give me code that does, thanks.
Well that is enough bitching and complaining here is what I've got here:
How to play MIDI files in Windows
Well believe it or not it is
very easy to play a MIDI file in Windows and when I first saw the
code I thought that it couldn't possibly work, but it does! So here is
an edited version of the code that I got from Microsoft:
// PlayMIDI.cpp
// An edited version of a file found on Microsoft's
// Web site.
#define STRICT
#include
#pragma hdrstop
// Plays a specified MIDI file by using MCI_OPEN and MCI_PLAY. Returns
// as soon as playback begins. The window procedure function for the
// specified window will be notified when playback is complete.
// Returns 0L on success; otherwise, it returns an MCI error code.
DWORD playMIDIFile(HWND hWndNotify, LPSTR lpszMIDIFileName)
{
UINT wDeviceID;
DWORD dwReturn;
MCI_OPEN_PARMS mciOpenParms;
MCI_PLAY_PARMS mciPlayParms;
MCI_STATUS_PARMS mciStatusParms;
MCI_SEQ_SET_PARMS mciSeqSetParms;
// Open the device by specifying the device and filename.
// MCI will attempt to choose the MIDI mapper as the output port.
mciOpenParms.lpstrDeviceType = "sequencer";
mciOpenParms.lpstrElementName = lpszMIDIFileName;
if (dwReturn = mciSendCommand(NULL, MCI_OPEN,
MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, // Continued if statement
(DWORD)(LPVOID) &mciOpenParms)) // Continued if statement
{
// Failed to open device. Don't close it; just return error.
return (dwReturn);
}
// The device opened successfully; get the device ID.
wDeviceID = mciOpenParms.wDeviceID;
// Check if the output port is the MIDI mapper.
mciStatusParms.dwItem = MCI_SEQ_STATUS_PORT;
if (dwReturn = mciSendCommand(wDeviceID, MCI_STATUS,
MCI_STATUS_ITEM, (DWORD)(LPVOID) &mciStatusParms)) // Continued if
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}
// The output port is not the MIDI mapper.
// Ask if the user wants to continue.
if (LOWORD(mciStatusParms.dwReturn) != MIDI_MAPPER)
{
// The following code has been commented
// out because on my computer it always
// say's that the MIDI mapper isn't
// available, found out why, the above if
// statement is out of bounds - MIDI_MAPPER.
/*
if (MessageBox(hWndNotify,
"The MIDI mapper is not available. Continue?", // Continued if
"MIDI Mapper", MB_YESNO|MB_ICONQUESTION) == IDNO) // Continued if
{
// User does not want to continue. Not an error;
// just close the device and return.
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (0L);
}
*/
}
// Begin playback. The window procedure function for the parent
// window will be notified with an MM_MCINOTIFY message when
// playback is complete. At this time, the window procedure closes
// the device.
mciPlayParms.dwCallback = (DWORD) hWndNotify;
if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY,
(DWORD)(LPVOID) &mciPlayParms)) // Continued if statement
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}
mciSeqSetParms;
return (0L);
}
See now that's not anywhere near as hard as it say's it is on those nasty
newsgroups or other proaramming pages is it?
If you have problems with this code or don't understand something about
it you can contact me and ask me, but I too probebly won't know either
since I'm just a beginner Windows game programmer.
How to play WAVE files in Windows
This IS easy,
sndPlaySound(hWnd, SoundFileName);
hWnd - A handle to your apps window.
SoundFileName - Duh, a wave file name i.e. "hello.wav" : The quotes ARE necessary.
Setting Priority
Again, easy,
HANDLE hProc;
hProc = GetCurrentProcess();
SetPriorityClass(hProc, REALTIME_PRIORITY_CLASS);
How to load a bitmap from in a .exe or .dll file.
This is to load a DIB since Window's LoadBitmap won't work for DIB's or files that aren't
16 colours???
Here are two functions from Lary L Myers book on 3D game programming,
Amazing 3D Games Adventure Set, I've edited them a bit though...
LPVOID LoadDIBBitmap(HINSTANCE hInst, LPCSTR lpszResName)
{
HRSRC hRsrc;
HGLOBAL hGlobal;
LPVOID lpDIB = 0;
hRsrc = FindResource(hInst, lpszResName, BITMAP);
if (hRsrc != 0)
{
hGlobal = LoadResource(hInst, hRsrc);
if (hGlobal != 0)
lpDIB = LockResource(hGlobal);
}
return lpDIB;
}
void FreeDIBBitmapRes(LPVOID lpDIB)
{
HGLOBAL hGlobal;
hGlobal = LOWORD(GetHandle(SELECTOROF(lpDIB)));
UnlockResource(hGlobal);
FreeResource(hGlobal);
}
Note: This should work...but I haven't tried it yet.
!!!Links!!!
ACK-3D Bug Fixes for Watcom C++.
The famous 3D engines list - Over 280 3D engines(Some with source)
The C/C++ Game Programming Megasite
Allegro - A game programming library for DJGPP.
Avalon - Free 3D Models.
Plush 3D - A 3D Thinginy...
The Official DJGPP Site
A great resource of information on Game Programming!
Fast Game Programming, a great page.
Floting Points Game Programming Resources.
Game Programming Tips.
Grant's Lair 3DS Max Page
TPU - Teen Programmer's Unite
Windows Game Programming
POV Ray Homepage - Free 3D Renderer
A add-on for POV Ray.
Back to my main page
Contacting Me
To contact me just send e-mail to me at:
nutter_ras@geocities.com
When you send me e-mail could you also tell me what you thought
about my page and if you think I should add something that it
is greatly lacking thanks, Nutter.
Copyright© 1997 Nutter, most recent revision: 19th of June, 1997.