HGE:Tutorials:Setup
From GDWiki
[edit] Setting up the build environment
To set up your build environment for HGE, please visit the following link:
[edit] A minimal HGE program
After you have performed the initial setup, create a blank file named main.cpp and add it to the project (if it hasn't been added already).
The first thing that needs to be done for any HGE program is including the windows.h and hge.h header files. Then we initialize a global pointer to the HGE interface.
#include <windows.h> #include <hge.h> HGE *hge = 0;
Create a frame function, a function that will be called every frame. The frame function is a user-defined function that will be called by HGE once per frame. The game loop code will go here. When the frame function returns true, HGE stops execution of the game loop. For now, we will leave it empty and just return true.
bool FrameFunc() { return true; }
Next, we write the WinMain function, the standard entry point for windows applications.
hgeCreate(): Returns a pointer to the HGE interface; HGE_VERSION is always passed.
hge->System_SetState(): Sets the various internal HGE system states. The first parameter is the state you wish to set, and the second parameter is the value for that state.
- HGE_WINDOWED indicates windowed mode if true or fullscreen mode if false.
- HGE_FRAMEFUNC indicates the name of the frame function that is used.
- HGE_TITLE is used to indicate that we want to set the window title.
For a complete listing of these states, visit the following link: HGE System States
hge->System_Initiate(): Initializes all hardware and software needed to run the engine and creates the application window. Returns true if successful, otherwise we will display a message box with the error.
The following functions are called when the frame function returns true:
hge->System_Shutdown(): Restores video mode and frees allocated resources.
hge->Release(): Frees the HGE interface and deletes HGE object if needed.
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial"); if(hge->System_Initiate()) { hge->System_Start(); } else { MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); } //when the frame function returns true, the following code is executed: hge->System_Shutdown(); hge->Release(); return 0; }
This program doesn't actually do anything other than initialize the engine. It just shuts down right away after the HGE logo appears.
Important: You must have hge.dll in the folder with your project (simple) or in the system path (advanced) for the program to run.
You can download the source file for this tutorial here: Tutorial 1 source
Next Section: The Resource Manager

