Lesson 1: A basic walkthrough

Writing a 2D or 3D appliction using the acknex engine is a lot easier than writing a general Windows application. There are only three functions that you need to know:

ENGINE_VARS *engine_open(char * commandline)

Initializes the engine, returns a pointer to the engine variables struct (see avars.h), and accepts a command line string with the name of a script, an entity file, or a movie file to be loaded upon initialization, as well as command line options.

BOOL engine_frame(void)

Renders one frame in window or fullscreen mode, while performing collision detection, physics executions, I/O handling and so on. This function is called in the main 'game loop' and returns 0 when the engine is about to quit. The target rendering area can be given by the video_window function - this way the engine can render into an arbitrary window. The first engine_frame call opens the 3D device. Only after that, engine and video functions can be called.

void engine_close(void)

Closes the engine.

Example: Lesson1

In Lesson 1 you'll learn how to write a 3D walkthrough with just only 4 lines of C++ commands:
// ackexe.cpp : Tutorial Application, Lesson 1
// Link to the engine library
#pragma comment(lib, "acknex.lib") // Include the usual Windows headers #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <stdlib.h> #include <malloc.h> #include <memory.h> #include <tchar.h> // Include the engine data types, variables, and functions #include "adll.h" /////////////////////////////////////////////////////////////// // Lesson 1: Writing an application with just four lines of C /////////////////////////////////////////////////////////////// // This is the Windows main function. It's executed at start // of the application. Don't be confused by the scary looking // arguments, we normally won't need any. int APIENTRY WinMain(HINSTANCE hInstance, // application instance handle HINSTANCE hPrevInstance, // always zero LPTSTR lpCmdLine, // application command line int nCmdShow) // window flags { // If you're used to windows programming, you would normally expect // here about 150 lines of window definition, class registration, // and message loop stuff. You can do that if you want and override // the engine defaults, but all you really need is: engine_open("arena.wmb"); // The engine_open() function initializes the Gamestudio engine, // and accepts a command line string with the name of a script, // or an entity file to be loaded upon initialization. For instance, // we could hand over the application command line (char*)lpCmdLine. // We could also pass options to start in client or server mode. // Here we're just loading the arena level. // After loading a level we're ready to render it. The engine_frame() // function executes the scripts and physics, and renders the // current camera position to the screen if a level is loaded. // The function returns zero when a script calls exit() or an Abort // button is clicked. while (engine_frame()); // For rendering the level, we are just repeating engine_frame() until // a 0 value is returned. This is normally our main loop, all // the interesting stuff happens here. However, when an entity file // name is given for engine_open(), the engine acts as a viewer. // A default walkthrough movement is activated and we don't want // to do anything else at the moment. engine_close(); // Someone pressed the Exit icon. Our application is about to end. // Before that, the engine must be closed by engine_close(). return 0; }
► latest version online