[NeoEngine Logo]
Platform independent Open Source 3D game engine
Source - latest release

Source - weekly snapshot

Download tarball




Projects and extensions

Plan files

Useful Links

Mailing Lists

News archive

SourceForge.net Logo
Tutorial 1 - Init & Exit
Last update: 22/Jan/2004

This tutorial covers the initialization and shutdown sequences for the engine.

#include <neoengine/core.h>
#include <neoengine/render.h>
#include <neoengine/logstream.h>

#ifdef WIN32
#include <neodevd3d9/link.h>
#include <neodevopengl/link.h>
These are the base includes for using neoengine. core.h declares the core engine singleton classo as well as includes and defines for the specific OS used, core engine macros and some other internal engine defines and data. This file should always be included first of all neoengine headers.

render.h defines the render device class. The render device is the interface used for all rendering- related tasks in the engine. It creates your window, loads texture, creates vertex buffers and render primitives.

logstream.h defines the useful C++ stream-style logging interface used throughout the engine

The block of includes inside the BUILD_STATIC ifdef is for building by statically linking to the engine. NeoEngien supports building both as a dynamic and static library, and these includes are needed to simulate the use of loaded modules when linking statically. You need to include the link.h header for each module you use when using static linking.

using namespace NeoEngine;
using namespace std;
Saves a fair bit of typing.

RenderDevice    *g_pkRenderDevice    = 0;
RenderCaps       g_kRenderCaps;
LogFileSink      g_kLogFile( "neoengine.log" );
Global objects used in the tutorials.

g_pkRenderDevice is our render device.

g_kRenderCaps is the capabilities bitfield object for the render device. We use this both for passing requested render caps when opening the device and as storing the actual received caps.

g_kLogFile is a log sink that can be attached as output for log messages. Other sinks include stdout and the in-game console. For more information, look at the API docs for the logstream.h file

int main( int argc, char **argv )
  neolog.SetLogThreshold( DEBUG );
  neolog.AttachSink( Core::Get()->GetStdoutSink() );
  neolog.AttachSink( &g_kLogFile );
Control the logging output. The first call to SetLogThreshold determines how verbose the logging is. All messages with a lower level than the current threshold are ignored. The log levels are, in rising level order, DEBUG, INFO, WARNING, ERROR and PANIC. For example, passing INFO to SetLogThreshold will filter all DEBUG messages streamed to that source object.

It is also possible to set the log level by passing the --loglevel [level] commandline argument to the application, if it passes on arguments to the initalization of the engine correctly. More about this below.

The calls to AttachSink determines the "channels" to which log messages are directed. Possible channels provided by the engine are the stdout sink and the core console object. We can also pass other sinks, like the file sink used here. Not that the core is a singleton object, created on demand and accessed through the Get() method.

  Core::Get()->Initialize( argc, argv );
This call initializes the engine. You must always call Initialize before you start using the engine, with the only exception of the log control methods described above. The arguments to Initialize should usually be your command line line, but you might want to preprocess this in certain cases.

  if( !( g_pkRenderDevice = Core::Get()->CreateRenderDevice( "opengl" ) ) )
Now we create the render device. A render device is responsible for all graphic rendering, and is an abstraction of the underlying API and hardware. You create the render device by specifying which device backend you wish to use, for now we use the OpenGL backend which is named "opengl".

CreateRenderDevice will return a pointer to this device, or null if the method failed for some reason (like the library not found or unable to load).

  if( !g_pkRenderDevice->Open( RenderWindow( "Init & Exit", g_kRenderCaps, RenderResolution( 640, 480, 16 ) ) ) )
    goto SHUTDOWN;

  g_kRenderCaps = g_pkRenderDevice->GetCaps();
Before we can use a render device, we must open it. This call will create the application window and setup the render device for rendering. After a successful call to Open(), the device will be ready to use. The method takes a single argument, a RenderWindow object that defines the data for the rendering window. To have the device create a new window, we create a RenderWindow object with a specified window title, render caps and requested resolution (size). It is also possible to set data in the RenderWindow object to get the device to open in an already existing window.

After the render device has been open, we first store away the capabilities of the opened device, then we are ready to rock! Main loop would go here, for now we fall through and exit cleanly.


  Core::Get()->DeleteRenderDevice( g_pkRenderDevice );
Deallocate the render device

Shutdown the engine. This must always be the last call done to the engine, after this you cannot use any engine methods anymore. Will cleanup any internal data used and delete the core object.

  return 0;