Get the minapp code: minapp.zip

Setting up minapp.cfg
With Notepad, open up minapp.cfg file that is supplied with minapp.zip. The first line has the "(" character. 
This is for specifying the D3D driver. If you do not have a D3D video driver installed, then minapp will fail to 
load. Here is a listing of chars used to indicate the preferred driver for you minapp session. Edit and save 
your minapp.cfg according to your system's features.

( = D3D
G = Glide
S = Software

/*******************************************************************************************************/

/*******************************************************************************************************/

/*								Genesis 3D v1.1 Minimum Application V1								   */

/*								July 23, 2000																	   */

/*  This minimum application is designed to show new people how to start writing a game from scratch   */

/*  using the Genesis 3D v1.1 SDK.  In no way is this or will ever be a complete game.  That would be  */

/*  up to you.																						   */

/*																									   */

/*  Anthony Rufrano																					   */

/*  Programming Director																			   */

/*  Paradox Software																				   */

/*******************************************************************************************************/

/*******************************************************************************************************/
// minapp.h
#ifndef MINAPP_H

#define MINAPP_H
//Includes

#include <windows.h>		//Always include this before genesis.h

#include "genesis.h"		//The Genesis SDK include header
//Ok here we go...First thing we need to do is declare some varibles.  These variables reflect the different

//objects in Genesis.

HWND			hWnd;			//The window

geEngine		*Engine;		//The engine object

geDriver_System		*DrvSys;		//Genesis Driver System

geDriver		*Driver;		//Your driver (DirectX, Glide, or Software)

geDriver_Mode		*Mode;			//The mode you selected
geSound_System		*SoundSys;		//The Genesis Sound System
geCamera		*Camera;		//The camera object

GE_Rect			Rect;			//For the camera object's rectangular view

geXForm3d		XForm;			//Camera's XForm
geWorld			*World;			//World Object
char			ourdriver;		//Driver we want to use

int			Width;			//Width of the mode

int			Height;			//Height of the mode
//Here are the prototypes of some functions we are going to create

geBoolean		InitEngine(HWND hWnd);

void			FindDriver();

void			LoadPrefs(char *drv, int *width, int *height);

void			LoadLevel(char *FileName);

void			Shutdown();
#endif
//===========================================================================
/*******************************************************************************************************/

/*******************************************************************************************************/

/*								Genesis 3D v1.1 Minimum Application V1								   */

/*																									   */

/*  This minimum application is designed to show new people how to start writing a game from scratch   */

/*  using the Genesis 3D v1.1 SDK.  In no way is this or will ever be a complete game.  That would be  */

/*  up to you.																						   */

/*																									   */

/*  Anthony Rufrano																					   */

/*  Programming Director																			   */

/*  Paradox Software																				   */

/*******************************************************************************************************/

/*******************************************************************************************************/
// init.c

//This file will have the initialization routines for the Genesis engine
//Includes

#include <windows.h>

#include <stdio.h>  //for LoadPrefs()

#include "genesis.h"

#include "minapp.h"
void LoadPrefs(char *drv, int *width, int *height)

{

	FILE		*f;
	//Open the minapp.cfg file

	if ((f = fopen("minapp.cfg", "r+")) == NULL)

	{

		MessageBox(hWnd, "Failed to read minapp.cfg", "No Prefs", MB_OK);

		_exit(-1);

	}
	//read in the driver

	fscanf(f, "%s", drv);
	//read in the width

	fscanf(f, "%d", width);
	//read in the height

	fscanf(f, "%d", height);

	
	//close the file

	fclose(f);

}
geBoolean InitEngine(HWND hWnd)

{

	//This function creates the engine.  The first parameter is the window that the engine will use

	//the second parameter is a name for your game. You can use anything.  The third parameter is the

	//path of the genesis drivers (d3ddrv.dll, glidedrv.dll, etc...).  I use "." to specify the current

	//directory.  You can use something like "c:\\Genesis3d11\\" if you want.

	Engine = geEngine_Create(hWnd, "MinApp", ".");

	if (!Engine)

	{

		MessageBox(hWnd, "Could not create engine object!", "MinApp Error...", 48);

		return GE_FALSE;

	}
	//This function will enable you to use sound with your program through the Genesis API.

	SoundSys = geSound_CreateSoundSystem(hWnd);

	if (!SoundSys)

		MessageBox(hWnd, "Could not create Sound System!  There will be no sound!", "No Sound...", 48);

	
	DrvSys = geEngine_GetDriverSystem(Engine);

	if (!DrvSys)

	{

		MessageBox(hWnd, "Could not get the Genesis Driver System!", "MinApp Error...", 48);

		return GE_FALSE;

	}

	
	//Set the driver you want to use

	FindDriver();

	
	//Setup the camera rect

	Rect.Left = 0;				//The far left of the screen

	Rect.Right = Width - 1;		//The far right of the screen

	Rect.Top = 0;				//The very top of the screen

	Rect.Bottom = Height - 1;	//The very bottom of the screen
	//Create the camera object.  The first parameter is the FOV (Field of View).  2.0f represents a 90 

	//degree FOV.  The second is the rectangle we just setup.

	Camera = geCamera_Create(2.0f, &Rect);

	
	//We can't work without a camera.  If it doesn't exist, exit the program

	if (!Camera)

	{

		MessageBox(hWnd, "Could not create camera object!", "MinApp Error...", 48);

		_exit(-1);

	}
	//Set up the XForm for the camera.  XForms determine your place in the world.

	//Clear the transform

	geXForm3d_SetIdentity(&XForm);
	//Setup the rotation

	geXForm3d_RotateX(&XForm, 0.0f);

	geXForm3d_RotateY(&XForm, 0.0f);

	geXForm3d_RotateZ(&XForm, 0.0f);
	//Set the XForm to the camera

	geCamera_SetWorldSpaceXForm(Camera, &XForm);
	//Load the level

	LoadLevel("levels\\default.bsp");
	return GE_TRUE;

}
void FindDriver()

{

	char			*drvname;

	int			tempwidth;

	int			tempheight;
	//Get the first driver

	Driver = geDriver_SystemGetNextDriver(DrvSys, NULL);
	//Loop through the driver list and find the driver that matches what we loaded into our variables before.

	while (1)

	{

		//If there is no first driver then break the loop

		if (!Driver)

		{

			MessageBox(hWnd, "Could not find a valid driver!", "MinApp Error...", 48);

			_exit(-1);

		}
		//Get the name of the driver

		geDriver_GetName(Driver, &drvname);
		//Check and see if the first character matches the driver we loaded into our variable before.  If

		//it is, then break the loop.

		if (drvname[0] == ourdriver)

			break;
		//If not, get the next one

		Driver = geDriver_SystemGetNextDriver(DrvSys, Driver);

	}
	//Get the first mode

	Mode = geDriver_GetNextMode(Driver, NULL);
	//Loop through the mode list and find the mode that matches the width and height of our variables

	while (1)

	{

		//If there is no mode, break the loop and exit the program

		if (!Mode)

		{

			MessageBox(hWnd, "Could not find a valid mode!", "MinApp Error...", 48);

			_exit(-1);

		}
		//Get the width and height of the mode

		geDriver_ModeGetWidthHeight(Mode, &tempwidth, &tempheight);
		//See if the width and height match the variables.  If it does, break the loop

		if (tempwidth == Width && tempheight == Height)

			break;
		//If not, get the next mode

		Mode = geDriver_GetNextMode(Driver, Mode);

	}
	//We have the Driver and Mode we want, now tell the engine to start

	if (!geEngine_SetDriverAndMode(Engine, Driver, Mode))

	{

		MessageBox(hWnd, "Could not start the engine!", "MinApp Error...", 48);

		_exit(-1);

	}

}
void LoadLevel(char *FileName)

{

	geVFile			*Level;
	//Load the bsp file

	Level = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_DOS, FileName, NULL, GE_VFILE_OPEN_READONLY);

	
	//Can't work without a level, so exit the program.

	if (!Level)

	{

		MessageBox(hWnd, "Could not load file!", "MinApp Error...", 48);

		_exit(-1);

	}
	//Create the world

	World = geWorld_Create(Level);

	if (!World)

	{

		MessageBox(hWnd, "Could not create world!", "MinApp Error...", 48);

		_exit(-1);

	}
	//Add the world to the engine

	if (!geEngine_AddWorld(Engine, World))

	{

		MessageBox(hWnd, "Could not add world to engine!", "MinApp Error...", 48);

		_exit(-1);

	}

}
void Shutdown()

{

	if (World)

	{

		geEngine_RemoveWorld(Engine, World);

		geWorld_Free(World);

	}
	if (Camera)

		geCamera_Destroy(&Camera);
	if (SoundSys)

		geSound_DestroySoundSystem(SoundSys);
	if (Engine)

	{

		geEngine_ShutdownDriver(Engine);

		geEngine_Free(Engine);

	}

}
//===========================================================================
// main.c
//This file will have the WinMain and WndProc functions

#include <windows.h>

#include "genesis.h"
#include "minapp.h"
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

{

	WNDCLASS			wc;

	MSG					msg;

	int					run;

	
	LoadPrefs(&ourdriver, &Width, &Height);
	//Initialize the window class

	wc.cbClsExtra = 0;

	wc.cbWndExtra = 0;

	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

	wc.hCursor = LoadCursor(NULL, IDC_ARROW);

	wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);

	wc.lpfnWndProc = WndProc;

	wc.lpszClassName = "MinApp";

	wc.lpszMenuName = NULL;

	wc.style = CS_HREDRAW | CS_VREDRAW;

	wc.hInstance = hInstance;
	//Register the window class

	RegisterClass(&wc);

	
	//Create the window

	hWnd = CreateWindowEx(0, wc.lpszClassName, "Genesis 3D v1.1 Minimum App", 0, CW_USEDEFAULT, CW_USEDEFAULT, Width, Height, NULL, NULL, hInstance, NULL);

	if (!hWnd)

	{

		MessageBox(NULL, "Could not create main window!", "MinApp Error...", 48);

		_exit(-1);

	}

	
	//Make the window appear and update it

	ShowWindow(hWnd, nShowCmd);

	UpdateWindow(hWnd);

	
	//Initialize the Genesis engine

	InitEngine(hWnd);

	
	//Main game loop

	run = 1;
	while (run)

	{

		if (!geEngine_BeginFrame(Engine, Camera, GE_FALSE))

			run = 0;
		if (!geEngine_RenderWorld(Engine, World, Camera, 0.0f))

			run = 0;
		if (!geEngine_EndFrame(Engine))

			run = 0;
		// let window poll for messages

		while (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))

		{
			if (!GetMessage(&msg, NULL, 0, 0 ))

			{

				run = 0;

				break;

			}
			TranslateMessage(&msg); 

			DispatchMessage(&msg);

		}

	}
	//Shutdown the Genesis engine and clean up the memory	

	Shutdown();

	
	//End Program

	return 1;

}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)

{

	switch (iMessage)

	{

	case WM_KEYDOWN:

		{

			switch (wParam)

			{

			case VK_ESCAPE:

				{

					PostMessage(hWnd, WM_QUIT, 0, 0);

				}

			}

		}

	default:

		return DefWindowProc(hWnd, iMessage, wParam, lParam);

	}
	return 1;

}
//=============================================================================