Dashboard > NeL > ... > NeLDocumentation > HelloWorld
HelloWorld
Added by Matt Raykowski, last edited by Robert Wetzel on Jan 10, 2008  (view change) show comment
Labels: 
(None)


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.)

Using Windows, create a console application in Visual Studio and conform to the helloworld.cpp code below. It is worth noting that if you create a windows app rather than a console app, you will have a number of problems with multiple defined symbols during linking. Make sure that run time type identification is turned on in your build settings.

On Unix systems, you can easily compile the code below with a command similar to this (assuming nel-config is within your $PATH, and pointing to a properly installed NeL):

g++ `nel-config --libs` `nel-config --cflags` helloworld.cpp -o helloworld

The Hello World code:

helloworld.cpp
#include <nel/misc/types_nl.h>

#include <nel/3d/u_driver.h>
#include <nel/3d/u_text_context.h>

using namespace std;
using namespace NLMISC;
using namespace NL3D;

// The 3d driver
UDriver        *Driver = NULL;
// This variable is used to display text on the screen
UTextContext   *TextContext = NULL;
// true if you want to exit the main loop
bool            NeedExit = false;

int main(int argc, char **argv)
{
    // Create a driver
    Driver = UDriver::createDriver();
    nlassert(Driver);

    // Create the window with config file values
    Driver->setDisplay (UDriver::CMode(640, 480, 32));

    // Create a Text context for later text rendering
    TextContext = Driver->createTextContext ("data/n019003l.pfb");
    nlassert(TextContext);

    while ((!NeedExit) && Driver->isActive())
    {
        // Clear all buffers
        Driver->clearBuffers (CRGBA (0, 0, 0));

        // Display a text on the screen
        TextContext->setHotSpot (UTextContext::TopLeft);
        TextContext->setColor (CRGBA(255, 255, 255, 255));
        TextContext->setFontSize (14);
        TextContext->printfAt (0.01f, 0.99f, "Hello, World!");

        // Swap 3d buffers
        Driver->swapBuffers ();

        // Pump user input messages
        Driver->EventServer.pump();

        // Manage the keyboard
        if (Driver->AsyncListener.isKeyDown (KeySHIFT)
            && Driver->AsyncListener.isKeyDown (KeyESCAPE))
        {
            // Shift Escape -> quit
            NeedExit = true;
        }
    }
}

Site running on a free Atlassian Confluence Open Source Project License granted to Open NeL (Open Nevrax Library, community branch of NeL). Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators