HGE游戏引擎是一个基于directX的游戏引擎,它的渲染及逻辑是基于帧回调的框架模式,其提供一些基本的图像操作和输入控制功能。
项目如图:
fontconv测试代码(参数二:文件路径):
int main(int argc, char* argv[]) { HANDLE hSearch; WIN32_FIND_DATA SearchData; int nfiles=0; bool done=false; char *buf, filename[256]; filelist *newFile, *nextFile; printf("\nHGE Font 1.XX -> 1.6 converter\nCopyright (C) 2003-2006, Relish Games\n\n"); if(argc!=2) { printf("Usage: FONTCONV.EXE <wildcard>\n\n"); printf("All files found by the specified wildcard will\n"); printf("be automatically converted to newer format. Bitmap files\n"); printf("should be available along with font description files.\n\n"); return 0; } else { hSearch=FindFirstFile(argv[1], &SearchData); nextFile=0; for(;;) { if(hSearch==INVALID_HANDLE_VALUE || done) { FindClose(hSearch); break; } if(!(SearchData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { strcpy(filename, argv[1]); buf=strrchr(filename, '\\'); if(!buf) buf=filename; else buf++; strcpy(buf,SearchData.cFileName); newFile=new filelist; strcpy(newFile->filename,filename); newFile->next=0; if(nextFile) nextFile->next=newFile; else files=newFile; nextFile=newFile; } done=!FindNextFile(hSearch, &SearchData); } hge=hgeCreate(HGE_VERSION); hge->System_SetState(HGE_USESOUND, false); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, 640); hge->System_SetState(HGE_SCREENHEIGHT, 480); if(!hge->System_Initiate()) { hge->Release(); printf("\nCan't initiate HGE.\n\n",nfiles); return 0; } newFile=files; while(newFile) { if(convert(newFile->filename)) nfiles++; nextFile=newFile->next; delete newFile; newFile=nextFile; } hge->System_Shutdown(); hge->Release(); printf("\n%d file(s) successfully converted.\n\n",nfiles); return 0; } }
fonted测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_INIFILE, "fonted.ini"); hge->System_SetState(HGE_LOGFILE, "fonted.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Bitmap Font Builder"); hge->System_SetState(HGE_SCREENWIDTH, 800); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENBPP, 32); hge->System_SetState(HGE_USESOUND, false); if(hge->Ini_GetInt("HGE", "FullScreen",0)) hge->System_SetState(HGE_WINDOWED, false); else hge->System_SetState(HGE_WINDOWED, true); if(hge->System_Initiate()) { InitEditor(); hge->System_Start(); DoneEditor(); } else MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_TASKMODAL); hge->System_Shutdown(); hge->Release(); return 0; }
hge 和hgehelp是引擎动态库!~
particleed测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_INIFILE, "particleed.ini"); hge->System_SetState(HGE_LOGFILE, "particleed.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Particle Systems Editor"); hge->System_SetState(HGE_SCREENWIDTH, 800); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENBPP, 32); hge->System_SetState(HGE_USESOUND, false); if(hge->Ini_GetInt("HGE", "FullScreen",0)) hge->System_SetState(HGE_WINDOWED, false); else hge->System_SetState(HGE_WINDOWED, true); if(hge->System_Initiate()) { InitEditor(); hge->System_Start(); DoneEditor(); } else MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); hge->System_Shutdown(); hge->Release(); return 0; }
pngopt测试代码:
int main(int argc, char* argv[]) { HANDLE hSearch; WIN32_FIND_DATA SearchData; int nfiles=0; bool done=false; char *buf, filename[256]; filelist *newFile, *nextFile; printf("\nPNG Optimizer v0.2\nCopyright (C) 2003-2008, Relish Games\n\n"); if(argc!=2) { printf("Usage: PNGOPT.EXE <wildcard>\n\n"); printf("The image data of all files found by the specified wildcard\n"); printf("will be expanded beneath the alpha channel boundary.\n"); printf("So images will render without artifacts when scaled, stretched,\n"); printf("rotated or rendered into not integer coordinates.\n\n"); return 0; } else { hSearch=FindFirstFile(argv[1], &SearchData); nextFile=0; for(;;) { if(hSearch==INVALID_HANDLE_VALUE || done) { FindClose(hSearch); break; } if(!(SearchData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { strcpy(filename, argv[1]); buf=strrchr(filename, '\\'); if(!buf) buf=filename; else buf++; strcpy(buf,SearchData.cFileName); newFile=new filelist; strcpy(newFile->filename,filename); newFile->next=0; if(nextFile) nextFile->next=newFile; else files=newFile; nextFile=newFile; } done=!FindNextFile(hSearch, &SearchData); } hge=hgeCreate(HGE_VERSION); hge->System_SetState(HGE_USESOUND, false); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, 320); hge->System_SetState(HGE_SCREENHEIGHT, 200); hge->System_SetState(HGE_SHOWSPLASH, false); if(!hge->System_Initiate()) { hge->Release(); printf("\nCan't initiate HGE.\n\n",nfiles); return 0; } newFile=files; while(newFile) { if(convert(newFile->filename)) nfiles++; nextFile=newFile->next; delete newFile; newFile=nextFile; } hge->System_Shutdown(); hge->Release(); printf("\n%d image(s) successfully optimized.\n\n",nfiles); return 0; } }
hge_tut01测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { // Here we use global pointer to HGE interface. // Instead you may use hgeCreate() every // time you need access to HGE. Just be sure to // have a corresponding hge->Release() // for each call to hgeCreate() hge = hgeCreate(HGE_VERSION); // Set our frame function hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); // Set the window title hge->System_SetState(HGE_TITLE, "HGE Tutorial 01 - Minimal HGE application"); // Run in windowed mode // Default window size is 800x600 hge->System_SetState(HGE_WINDOWED, true); // Don't use BASS for sound hge->System_SetState(HGE_USESOUND, false); // Tries to initiate HGE with the states set. // If something goes wrong, "false" is returned // and more specific description of what have // happened can be read with System_GetErrorMessage(). if(hge->System_Initiate()) { // Starts running FrameFunc(). // Note that the execution "stops" here // until "true" is returned from FrameFunc(). hge->System_Start(); } else { // If HGE initialization failed show error message MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); } // Now ESC has been pressed or the user // has closed the window by other means. // Restore video mode and free // all allocated resources hge->System_Shutdown(); // Release the HGE interface. // If there are no more references, // the HGE object will be deleted. hge->Release(); return 0; }
hge_tut02测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { // Get HGE interface hge = hgeCreate(HGE_VERSION); // Set up log file, frame function, render function and window title hge->System_SetState(HGE_LOGFILE, "hge_tut02.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial 02 - Using input, sound and rendering"); // Set up video mode hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, 800); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENBPP, 32); if(hge->System_Initiate()) { // Load sound and texture snd=hge->Effect_Load("menu.wav"); quad.tex=hge->Texture_Load("particles.png"); if(!snd || !quad.tex) { // If one of the data files is not found, display // an error message and shutdown. MessageBox(NULL, "Can't load MENU.WAV or PARTICLES.PNG", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); hge->System_Shutdown(); hge->Release(); return 0; } // Set up quad which we will use for rendering sprite quad.blend=BLEND_ALPHAADD | BLEND_COLORMUL | BLEND_ZWRITE; for(int i=0;i<4;i++) { // Set up z-coordinate of vertices quad.v[i].z=0.5f; // Set up color. The format of DWORD col is 0xAARRGGBB quad.v[i].col=0xFFFFA000; } // Set up quad's texture coordinates. // 0,0 means top left corner and 1,1 - // bottom right corner of the texture. quad.v[0].tx=96.0/128.0; quad.v[0].ty=64.0/128.0; quad.v[1].tx=128.0/128.0; quad.v[1].ty=64.0/128.0; quad.v[2].tx=128.0/128.0; quad.v[2].ty=96.0/128.0; quad.v[3].tx=96.0/128.0; quad.v[3].ty=96.0/128.0; // Let's rock now! hge->System_Start(); // Free loaded texture and sound hge->Texture_Free(quad.tex); hge->Effect_Free(snd); } else MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); // Clean up and shutdown hge->System_Shutdown(); hge->Release(); return 0; }
hge_tut03测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_LOGFILE, "hge_tut03.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial 03 - Using helper classes"); hge->System_SetState(HGE_FPS, 100); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, 800); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENBPP, 32); if(hge->System_Initiate()) { // Load sound and texture snd=hge->Effect_Load("menu.wav"); tex=hge->Texture_Load("particles.png"); if(!snd || !tex) { // If one of the data files is not found, display // an error message and shutdown. MessageBox(NULL, "Can't load one of the following files:\nMENU.WAV, PARTICLES.PNG, FONT1.FNT, FONT1.PNG, TRAIL.PSI", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); hge->System_Shutdown(); hge->Release(); return 0; } // Create and set up a sprite spr=new hgeSprite(tex, 96, 64, 32, 32); spr->SetColor(0xFFFFA000); spr->SetHotSpot(16,16); // Load a font fnt=new hgeFont("font1.fnt"); // Create and set up a particle system spt=new hgeSprite(tex, 32, 32, 32, 32); spt->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE); spt->SetHotSpot(16,16); par=new hgeParticleSystem("trail.psi",spt); par->Fire(); // Let's rock now! hge->System_Start(); // Delete created objects and free loaded resources delete par; delete fnt; delete spt; delete spr; hge->Texture_Free(tex); hge->Effect_Free(snd); } // Clean up and shutdown hge->System_Shutdown(); hge->Release(); return 0; }
hge_tut04测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_LOGFILE, "hge_tut04.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_GFXRESTOREFUNC, GfxRestoreFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial 04 - Using render targets"); hge->System_SetState(HGE_FPS, 100); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, 800); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENBPP, 32); tar=0; target=0; if(hge->System_Initiate()) { snd=hge->Effect_Load("menu.wav"); tex=hge->Texture_Load("particles.png"); if(!snd || !tex) { // If one of the data files is not found, display // an error message and shutdown. MessageBox(NULL, "Can't load one of the following files:\nMENU.WAV, PARTICLES.PNG, FONT1.FNT, FONT1.PNG, TRAIL.PSI", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); hge->System_Shutdown(); hge->Release(); return 0; } spr=new hgeSprite(tex, 96, 64, 32, 32); spr->SetColor(0xFFFFA000); spr->SetHotSpot(16,16); fnt=new hgeFont("font1.fnt"); spt=new hgeSprite(tex, 32, 32, 32, 32); spt->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE); spt->SetHotSpot(16,16); par=new hgeParticleSystem("trail.psi",spt); par->Fire(); // Create a render target and a sprite for it target=hge->Target_Create(512,512,false); tar=new hgeSprite(hge->Target_GetTexture(target),0,0,512,512); tar->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE); // Let's rock now! hge->System_Start(); // Delete created objects and free loaded resources delete par; delete fnt; delete spt; delete spr; delete tar; hge->Target_Free(target); hge->Texture_Free(tex); hge->Effect_Free(snd); } // Clean up and shutdown hge->System_Shutdown(); hge->Release(); return 0; }
效果如图:
hge_tut05测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_LOGFILE, "hge_tut05.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial 05 - Using distortion mesh"); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, 800); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENBPP, 32); hge->System_SetState(HGE_USESOUND, false); if(hge->System_Initiate()) { // Load sound and texture tex=hge->Texture_Load("texture.jpg"); if(!tex) { // If one of the data files is not found, display // an error message and shutdown. MessageBox(NULL, "Can't load TEXTURE.JPG", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); hge->System_Shutdown(); hge->Release(); return 0; } // Create a distortion mesh dis=new hgeDistortionMesh(nCols, nRows); dis->SetTexture(tex); dis->SetTextureRect(0,0,512,512); dis->SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_ZWRITE); dis->Clear(0xFF000000); // Load a font fnt=new hgeFont("font1.fnt"); // Let's rock now! hge->System_Start(); // Delete created objects and free loaded resources delete fnt; delete dis; hge->Texture_Free(tex); } // Clean up and shutdown hge->System_Shutdown(); hge->Release(); return 0; }
hge_tut06测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_LOGFILE, "hge_tut06.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial 06 - Creating menus"); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, 800); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENBPP, 32); if(hge->System_Initiate()) { // Load sound and textures quad.tex=hge->Texture_Load("bg.png"); tex=hge->Texture_Load("cursor.png"); snd=hge->Effect_Load("menu.wav"); if(!quad.tex || !tex || !snd) { // If one of the data files is not found, display // an error message and shutdown. MessageBox(NULL, "Can't load BG.PNG, CURSOR.PNG or MENU.WAV", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); hge->System_Shutdown(); hge->Release(); return 0; } // Set up the quad we will use for background animation quad.blend=BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE; for(int i=0;i<4;i++) { // Set up z-coordinate of vertices quad.v[i].z=0.5f; // Set up color. The format of DWORD col is 0xAARRGGBB quad.v[i].col=0xFFFFFFFF; } quad.v[0].x=0; quad.v[0].y=0; quad.v[1].x=800; quad.v[1].y=0; quad.v[2].x=800; quad.v[2].y=600; quad.v[3].x=0; quad.v[3].y=600; // Load the font, create the cursor sprite fnt=new hgeFont("font1.fnt"); spr=new hgeSprite(tex,0,0,32,32); // Create and initialize the GUI gui=new hgeGUI(); gui->AddCtrl(new hgeGUIMenuItem(1,fnt,snd,400,200,0.0f,"Play")); gui->AddCtrl(new hgeGUIMenuItem(2,fnt,snd,400,240,0.1f,"Options")); gui->AddCtrl(new hgeGUIMenuItem(3,fnt,snd,400,280,0.2f,"Instructions")); gui->AddCtrl(new hgeGUIMenuItem(4,fnt,snd,400,320,0.3f,"Credits")); gui->AddCtrl(new hgeGUIMenuItem(5,fnt,snd,400,360,0.4f,"Exit")); gui->SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED); gui->SetCursor(spr); gui->SetFocus(1); gui->Enter(); // Let's rock now! hge->System_Start(); // Delete created objects and free loaded resources delete gui; delete fnt; delete spr; hge->Effect_Free(snd); hge->Texture_Free(tex); hge->Texture_Free(quad.tex); } // Clean up and shutdown hge->System_Shutdown(); hge->Release(); return 0; }
hge_tut07测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { int i; hge = hgeCreate(HGE_VERSION); // Set desired system states and initialize HGE hge->System_SetState(HGE_LOGFILE, "hge_tut07.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial 07 - Thousand of Hares"); hge->System_SetState(HGE_USESOUND, false); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, SCREEN_WIDTH); hge->System_SetState(HGE_SCREENHEIGHT, SCREEN_HEIGHT); hge->System_SetState(HGE_SCREENBPP, 32); if(hge->System_Initiate()) { // Load textures bgtex=hge->Texture_Load("bg2.png"); tex=hge->Texture_Load("zazaka.png"); if(!bgtex || !tex) { // If one of the data files is not found, // display an error message and shutdown MessageBox(NULL, "Can't load BG2.PNG or ZAZAKA.PNG", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); hge->System_Shutdown(); hge->Release(); return 0; } // Load font, create sprites fnt=new hgeFont("font2.fnt"); spr=new hgeSprite(tex,0,0,64,64); spr->SetHotSpot(32,32); bgspr=new hgeSprite(bgtex,0,0,800,600); bgspr->SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE); bgspr->SetColor(0xFF000000,0); bgspr->SetColor(0xFF000000,1); bgspr->SetColor(0xFF000040,2); bgspr->SetColor(0xFF000040,3); // Initialize objects list pObjects=new sprObject[MAX_OBJECTS]; nObjects=1000; for(i=0;i<MAX_OBJECTS;i++) { pObjects[i].x=hge->Random_Float(0,SCREEN_WIDTH); pObjects[i].y=hge->Random_Float(0,SCREEN_HEIGHT); pObjects[i].dx=hge->Random_Float(-200,200); pObjects[i].dy=hge->Random_Float(-200,200); pObjects[i].scale=hge->Random_Float(0.5f,2.0f); pObjects[i].dscale=hge->Random_Float(-1.0f,1.0f); pObjects[i].rot=hge->Random_Float(0,M_PI*2); pObjects[i].drot=hge->Random_Float(-1.0f,1.0f); } SetBlend(0); // Let's rock now! hge->System_Start(); // Delete created objects and free loaded resources delete[] pObjects; delete fnt; delete spr; delete bgspr; hge->Texture_Free(tex); hge->Texture_Free(bgtex); } // Clean up and shutdown hge->System_Shutdown(); hge->Release(); return 0; }
hge_tut08测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); // Set desired system states and initialize HGE hge->System_SetState(HGE_LOGFILE, "hge_tut08.log"); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_TITLE, "HGE Tutorial 08 - The Big Calm"); hge->System_SetState(HGE_USESOUND, false); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_SCREENWIDTH, SCREEN_WIDTH); hge->System_SetState(HGE_SCREENHEIGHT, SCREEN_HEIGHT); hge->System_SetState(HGE_SCREENBPP, 32); if(hge->System_Initiate()) { fnt=new hgeFont("font2.fnt"); if(!InitSimulation()) { // If one of the data files is not found, display an error message and shutdown MessageBox(NULL, "Can't load resources. See log for details.", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); hge->System_Shutdown(); hge->Release(); return 0; } hge->System_Start(); DoneSimulation(); delete fnt; } hge->System_Shutdown(); hge->Release(); return 0; }
学习的目标是成熟!~~~~