Tutorial 01d : Using the CBasicApplication Class
Complete source file : tut01d.cc
Include the VortexGE header file as always :
#include <VMain.h>
Then, derive our specialized application class :
class MyApplication : public CBasicApplication<> { public: // Here we invoke the CBasicApplication constructor so that // we can define our window title inline MyApplication() : CBasicApplication<>("Tutorial 1d : Using the CBasicApplication Class") {} // Reimplement only the needed event handlers virtual void EventButtonRelease(EBtnSymbol eButtonSym) { if(eButtonSym == VBS_MB1) EventCloseWindow(); } virtual void EventUpdateFrame(bool bWindowIsActive); };
By default CBasicApplication supports FPS control. If FPS control is not needed, just rewrite the above code to :
class MyApplication : public CBasicApplication<CEventHandler> { ... ... MyApplication() : CBasicApplication<CEventHandler>("Tutorial 1d : Using the CBasicApplication Class") ... ... };
Also, if the lines :
MyApplication() : CBasicApplication<>("Tutorial 1d : Using the CBasicApplication Class") {}
The function main() can now be written as :
int main() { // Create the application class MyApplication csMyApp; csMyApp.iVideoEnv().SetForegroundColor(csMyApp.iVideoEnv().CreateColor(255, 192, 255)); // Execute the application if(csMyApp.DoMainLoop() < 0) return(-1); csMyApp.iVideoEnv().MessageBox("End Program", "Click \"OK\" to exit ..."); return(0); }
Finally, this is our rendering (updating) handler :
void MyApplication::EventUpdateFrame(bool bWindowIsActive) { // Just exit if the window is inactive if(!bWindowIsActive) return; // Update audio iAudioEnv().UpdateBuffer(); // Update video i3DEnv().ClearRenderBuffer(V_RGB(12, 12, 16)); i3DEnv().ClearZBuffer(); iVideoEnv().PutRenderImageOnDisplay(); iVideoEnv().DrawText(10, 20, GetFPSInfoString()); iVideoEnv().DrawText(10, 50, "Click the left mouse button to exit ..."); iVideoEnv().UpdateDisplay(); }