Intro to NeL Coding: Hello World¶
A very minimal client example can be created that will print the text "Hello, World!" in the upper left of the screen. The program expects to be run from the Snowballs bin directory (it needs a font from the data directory, as well as a bunch of the DLL's / NeL libraries.)
1#include <nel/misc/types_nl.h> 2#include <nel/3d/u_driver.h> 3#include <nel/3d/u_text_context.h> 4 5using namespace std; 6using namespace NLMISC; 7using namespace NL3D; 8 9// The 3d driver 10UDriver *Driver = NULL; 11// This variable is used to display text on the screen 12UTextContext *TextContext = NULL; 13// true if you want to exit the main loop 14bool NeedExit = false; 15 16int main(int argc, char **argv) 17{ 18 // Create a driver 19 Driver = UDriver::createDriver(); 20 nlassert(Driver); 21 22 // Create the window with config file values 23 Driver->setDisplay (UDriver::CMode(640, 480, 32)); 24 25 // Create a Text context for later text rendering 26 TextContext = Driver->createTextContext ("data/n019003l.pfb"); 27 nlassert(TextContext); 28 29 while ((!NeedExit) && Driver->isActive()) 30 { 31 // Clear all buffers 32 Driver->clearBuffers (CRGBA (0, 0, 0)); 33 34 // Display a text on the screen 35 TextContext->setHotSpot (UTextContext::TopLeft); 36 TextContext->setColor (CRGBA(255, 255, 255, 255)); 37 TextContext->setFontSize (14); 38 TextContext->printfAt (0.01f, 0.99f, "Hello, World!"); 39 40 // Swap 3d buffers 41 Driver->swapBuffers (); 42 43 // Pump user input messages 44 Driver->EventServer.pump(); 45 46 // Manage the keyboard 47 if (Driver->AsyncListener.isKeyDown (KeySHIFT) 48 && Driver->AsyncListener.isKeyDown (KeyESCAPE)) 49 { 50 // Shift Escape -> quit 51 NeedExit = true; 52 } 53 } 54}

