On my side, I have something like this:
Code: Select all
#ifndef _FLAT_OGRE_ROOT__
#define _FLAT_OGRE_ROOT__
#include "cpp_types.h"
#ifdef __cplusplus
extern "C"
{
#endif
/*
Ogre Root constructors, in different flavors
*/
DLLEXPORT Pointer ogre_root_new(void);
DLLEXPORT Pointer ogre_root_new1(PChar pluginFile);
DLLEXPORT Pointer ogre_root_new2(PChar pluginFile, PChar configFile);
DLLEXPORT Pointer ogre_root_new3(PChar pluginFile, PChar configFile, PChar logFile);
/**
Ogre Root destructor callback
@param Pointer anonymized pointer to the Ogre::Root element
*/
DLLEXPORT void ogre_root_free(Pointer);
/**
Tries to load and parse config file
@param Pointer object
@return int 0 if failed
*/
DLLEXPORT int ogre_root_restore_config(Pointer);
/**
Launch Ogre setup and edit / create config file
@param Pointer object
@return int 0 if failed
*/
DLLEXPORT int ogre_root_show_config(Pointer);
/**
Initialize Ogre and automatically create render window
@param Pointer object
@param PChar window title
@return Pointer
*/
DLLEXPORT Pointer ogre_root_initialise_create(Pointer, PChar);
/**
Initialize Ogre but don't create a render window
@param Pointer object
@return int
*/
DLLEXPORT int ogre_root_initialise(Pointer);
/**
Manually create a render window
@param Pointer object
@param PChar window title
@param int width
@param int height
@param int fullscreen
@param int window context handle
@return Pointer
*/
DLLEXPORT Pointer ogre_root_create_render_window(Pointer, PChar, int, int, int, int);
/**
Create a scene manager
@param Pointer object
@param PChar type
@return Pointer
*/
DLLEXPORT Pointer ogre_root_create_scene_manager(Pointer, PChar);
/**
Render one frame
@param Pointer object
@return int
*/
DLLEXPORT int ogre_root_render_one_frame(Pointer);
#ifdef __cplusplus
}
#endif
#endif
which gives in my (insane ?) Pascal try:
Code: Select all
program project1;
{$mode objfpc}
{$H+}
uses
Classes, object_storage, ogre_camera, ogre_config, ogre_entity, ogre_light, ogre_log_manager, ogre_render_window, ogre_resource_group, ogre_root, ogre_scene_manager, ogre_scene_node, ogre_texture_manager, ogre_vector3, ogre_viewport, ogre_window_event_utilities, ois_manager;
var
ogreRoot, ogreRenderWindow, ogreSceneMgr, ogreCamera, ogreViewport : Pointer;
oisManager : Pointer;
stop : Boolean;
const
PLUGIN_FILE : PChar = 'plugins.cfg';
RESOURCE_FILE : PChar = 'resources.cfg';
procedure my_event_listener(p: Pointer); cdecl;
begin
if (ois_manager_keyboard_is_pressed(p, 1) = 1) { KC_ESCAPE }
then
stop := true;
end;
begin
writeln('Alloc Ogre Root');
ogreRoot := ogre_root_new1(PLUGIN_FILE);
object_store('Root', ogreRoot, @ogre_root_free);
ogre_config_parse_resources(RESOURCE_FILE);
if (((ogre_root_restore_config(ogreRoot) <> 1) and (ogre_root_show_config(ogreRoot) <> 1)))
then begin
writeln('Configuration failed !');
object_remove('Root');
exit;
end;
ogreRenderWindow := ogre_root_initialise_create(ogreRoot, 'Ogre Test Window');
object_store('Window', ogreRenderWindow, nil);
ogre_texture_manager_set_default_num_mipmaps(5);
ogre_resource_group_initialise();
ogreSceneMgr := ogre_root_create_scene_manager(ogreRoot, 'DefaultSceneManager');
object_store('SceneMgr', ogreSceneMgr, nil);
ogreCamera := ogre_scene_manager_create_camera(ogreSceneMgr, 'DefaultCamera');
object_store('Camera', ogreCamera, nil);
ogre_camera_set_clip_distances(ogreCamera, 5.0, 1000.0);
ogre_camera_set_position(ogreCamera, 0, 0, 80.0);
ogre_camera_look_at(ogreCamera, 0, 0, -300.0);
ogreViewport := ogre_render_window_add_viewport(ogreRenderWindow, ogreCamera);
object_store('Viewport', ogreViewport, nil);
ogre_viewport_set_background_color(ogreViewport, 0, 0, 0);
ogre_camera_set_aspect_ratio(ogreCamera,
single(ogre_viewport_get_actual_width(ogreViewport)) /
single(ogre_viewport_get_actual_height(ogreViewport)) );
object_store('Entity_Head', ogre_scene_manager_create_entity(ogreSceneMgr, 'Head', 'ogrehead.mesh'), nil);
ogre_scene_node_attach_object(
ogre_scene_manager_get_root_scene_node(ogreSceneMgr),
object_retrieve('Entity_Head')
);
ogre_scene_manager_set_ambient_light(ogreSceneMgr, 0.5, 0.5, 0.5);
object_store('Entity_Light', ogre_scene_manager_create_light(ogreSceneMgr, 'Light'), nil);
ogre_scene_node_attach_object(
ogre_scene_manager_get_root_scene_node(ogreSceneMgr),
object_retrieve('Entity_Light')
);
ogre_light_set_position(
object_retrieve('Entity_Light'),
20.0, 80.0, 50.0
);
oisManager := ois_manager_create(ogreRoot, ogreRenderWindow, 0);
object_store('Input_Manager', oisManager, @ois_manager_destroy);
ois_manager_register(oisManager, @my_event_listener);
while (not stop)
do begin
ogre_window_event_utilities_message_pump();
if (ogre_render_window_is_closed(ogreRenderWindow) = 1)
then
break;
if (ogre_root_render_one_frame(ogreRoot) <> 1)
then
break;
end;
writeln('--- Press a key to continue ---');
readln;
writeln('Delete OIS manager');
object_remove('Input_Manager');
writeln('Delete Ogre Root');
object_remove('Root');
end.
This works but with some limitations:
- I miss some exceptions, I'm currently working on intercepting them (if appropriate)
- I used CMake to have VC & MingW environments, however the MingW behavior is different (alloc error on some shaders compilations)
- DLL linkage is a mess; if you build on MSVC you have to use the Ogre DLL along, when you build on MinG you have to use the Ogre *plus* MingW runtimes *plus* boost dlls.