Hi everyone,
Does someone tried to use OGRE3D Engine (http://www.ogre3d.org/) natively from PureBasic (without the use of PB 3D commands) ?
Using OGRE natively from PureBasic ?
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Using OGRE natively from PureBasic ?
Its possible but almost impossible. The problem is that you need to write a wrapper for all the classes, find the corresponding addresses etc. and that is a horrible task. You could maybe compile OGRE from sources with g++ and pass the parameter -fdump-class-hierarchy to it. To explain what it does, here is an example:
Saving this as test.cpp and executing g++ -fdump-class-hierarchy -c test.cpp will give us a file with the following content:
It tells you the VTable of the class and the size and alignment of it. However as you might have found out, the method test seems missing. The reason for this is that it is not in the vtable.
A further possibility is to write a gcc plugin https://gcc.gnu.org/wiki/GCC_PluginAPI or use the debugging information if you compiled OGRE in debug mode. However, I think I found another solution to make it easier to write a wrapper: http://gccxml.github.io/HTML/Index.html or the newer CastXML https://github.com/CastXML/CastXML. It is able to parse the c++ code for you and give it to you as an XML. With this and much background knowledge, you could write a proper wrapper generator.
[EDIT]
CastXML produces this output:
Code: Select all
class Test {
public:
virtual ~Test();
void test(int a);
virtual void hello(int a, char b);
};
Test::~Test() {}
void Test::test(int a) {
}
void Test::hello(int a, char b) {
}
int main(int argc, char** argv) {
return 0;
}
Code: Select all
Vtable for Test
Test::_ZTV4Test: 5u entries
0 (int (*)(...))0
8 (int (*)(...))(& _ZTI4Test)
16 (int (*)(...))Test::~Test
24 (int (*)(...))Test::~Test
32 (int (*)(...))Test::hello
Class Test
size=8 align=8
base size=8 base align=8
Test (0x0x7fa14605d5a0) 0 nearly-empty
vptr=((& Test::_ZTV4Test) + 16u)
A further possibility is to write a gcc plugin https://gcc.gnu.org/wiki/GCC_PluginAPI or use the debugging information if you compiled OGRE in debug mode. However, I think I found another solution to make it easier to write a wrapper: http://gccxml.github.io/HTML/Index.html or the newer CastXML https://github.com/CastXML/CastXML. It is able to parse the c++ code for you and give it to you as an XML. With this and much background knowledge, you could write a proper wrapper generator.
[EDIT]
CastXML produces this output:
Code: Select all
<?xml version="1.0"?>
<GCC_XML version="0.9.0" cvs_revision="1.139">
<Namespace id="_1" name="::" members="_2 _3 _4 _5 _6 _7 _8 _9 _10 _11 _12"/>
<Typedef id="_2" name="__int128_t" type="_13" context="_1" location="f0:0" file="f0" line="0"/>
<Typedef id="_3" name="__uint128_t" type="_14" context="_1" location="f0:0" file="f0" line="0"/>
<Typedef id="_4" name="__NSConstantString" type="_15" context="_1" location="f0:0" file="f0" line="0"/>
<Typedef id="_5" name="__builtin_ms_va_list" type="_16" context="_1" location="f0:0" file="f0" line="0"/>
<Typedef id="_6" name="__builtin_va_list" type="_17" context="_1" location="f0:0" file="f0" line="0"/>
<Class id="_7" name="Test" context="_1" location="f1:1" file="f1" line="1" members="_18 _19 _20 _21 _22" size="64" align="64"/>
<OperatorFunction id="_8" name="new" returns="_23" context="_1" location="f0:0" file="f0" line="0" artificial="1" throw="_24" mangled="_Znwm">
<Argument type="_25" location="f0:0" file="f0" line="0"/>
</OperatorFunction>
<OperatorFunction id="_9" name="new[]" returns="_23" context="_1" location="f0:0" file="f0" line="0" artificial="1" throw="_24" mangled="_Znam">
<Argument type="_25" location="f0:0" file="f0" line="0"/>
</OperatorFunction>
<OperatorFunction id="_10" name="delete" returns="_26" context="_1" location="f0:0" file="f0" line="0" artificial="1" throw="" mangled="_ZdlPv">
<Argument type="_23" location="f0:0" file="f0" line="0"/>
</OperatorFunction>
<OperatorFunction id="_11" name="delete[]" returns="_26" context="_1" location="f0:0" file="f0" line="0" artificial="1" throw="" mangled="_ZdaPv">
<Argument type="_23" location="f0:0" file="f0" line="0"/>
</OperatorFunction>
<Function id="_12" name="main" returns="_27" context="_1" location="f1:17" file="f1" line="17" mangled="_Z4main">
<Argument name="argc" type="_27" location="f1:17" file="f1" line="17"/>
<Argument name="argv" type="_28" location="f1:17" file="f1" line="17"/>
</Function>
<FundamentalType id="_13" name="__int128" size="128" align="128"/>
<FundamentalType id="_14" name="unsigned __int128" size="128" align="128"/>
<Struct id="_15" name="__NSConstantString_tag" context="_1" location="f0:0" file="f0" line="0" members="_29 _30 _31 _32" size="256" align="64"/>
<PointerType id="_16" type="_33"/>
<ArrayType id="_17" min="0" max="0" type="_34"/>
<Destructor id="_18" name="Test" context="_7" access="public" location="f1:3" file="f1" line="3" virtual="1"/>
<Method id="_19" name="hello" returns="_26" context="_7" access="public" location="f1:6" file="f1" line="6" virtual="1" mangled="_ZN4Test5helloEic">
<Argument name="a" type="_27" location="f1:6" file="f1" line="6"/>
<Argument name="b" type="_33" location="f1:6" file="f1" line="6"/>
</Method>
<OperatorMethod id="_20" name="=" returns="_35" context="_7" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1" throw="" mangled="_ZN4TestaSERKS_">
<Argument type="_36" location="f1:1" file="f1" line="1"/>
</OperatorMethod>
<Constructor id="_21" name="Test" context="_7" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1" throw=""/>
<Constructor id="_22" name="Test" context="_7" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1" throw="">
<Argument type="_36" location="f1:1" file="f1" line="1"/>
</Constructor>
<PointerType id="_23" type="_26"/>
<Class id="_24" name="bad_alloc" context="_37" location="f0:0" file="f0" line="0" incomplete="1"/>
<FundamentalType id="_25" name="long unsigned int" size="64" align="64"/>
<FundamentalType id="_26" name="void" size="0" align="8"/>
<FundamentalType id="_27" name="int" size="32" align="32"/>
<PointerType id="_28" type="_16"/>
<Field id="_29" name="isa" type="_38" context="_15" access="public" offset="0"/>
<Field id="_30" name="flags" type="_27" context="_15" access="public" offset="64"/>
<Field id="_31" name="str" type="_39" context="_15" access="public" offset="128"/>
<Field id="_32" name="length" type="_40" context="_15" access="public" offset="192"/>
<FundamentalType id="_33" name="char" size="8" align="8"/>
<Struct id="_34" name="__va_list_tag" context="_1" location="f0:0" file="f0" line="0" members="_41 _42 _43 _44" size="192" align="64"/>
<ReferenceType id="_35" type="_7"/>
<ReferenceType id="_36" type="_7c"/>
<CvQualifiedType id="_7c" type="_7" const="1"/>
<PointerType id="_38" type="_27c"/>
<CvQualifiedType id="_27c" type="_27" const="1"/>
<PointerType id="_39" type="_33c"/>
<CvQualifiedType id="_33c" type="_33" const="1"/>
<FundamentalType id="_40" name="long int" size="64" align="64"/>
<Field id="_41" name="gp_offset" type="_45" context="_34" access="public" offset="0"/>
<Field id="_42" name="fp_offset" type="_45" context="_34" access="public" offset="32"/>
<Field id="_43" name="overflow_arg_area" type="_23" context="_34" access="public" offset="64"/>
<Field id="_44" name="reg_save_area" type="_23" context="_34" access="public" offset="128"/>
<FundamentalType id="_45" name="unsigned int" size="32" align="32"/>
<Namespace id="_37" name="std" context="_1"/>
<File id="f0" name="<builtin>"/>
<File id="f1" name="test.cpp"/>
</GCC_XML>
bye,
Daniel
Daniel
Re: Using OGRE natively from PureBasic ?
Thank you VERY MUCH for taking the time for this very complete answer, i will explore this way.
Niffo
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Using OGRE natively from PureBasic ?
I think it would even make sense to have a look at SWIG, which is used for generating wrappers.
bye,
Daniel
Daniel
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Using OGRE natively from PureBasic ?
I just found this thread here:
http://www.ogre3d.org/forums/viewtopic. ... &start=225
It points to a C wrapper, which makes everything much easier for writing a PureBasic wrapper:
https://bitbucket.org/galaktor/llcoi
http://www.ogre3d.org/forums/viewtopic. ... &start=225
It points to a C wrapper, which makes everything much easier for writing a PureBasic wrapper:
https://bitbucket.org/galaktor/llcoi
bye,
Daniel
Daniel
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Using OGRE natively from PureBasic ?
The MIT License is generous, but this C API has not been updated since 2014-01-04? Could be it's abandoned?
http://www.horde3d.org/ Looks to have great potential
http://www.horde3d.org/ Looks to have great potential
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Using OGRE natively from PureBasic ?
There are a few problems with this:
1. the work done by PB-Team has to be done again
2. you will problably not be able to use a pb-screen (OpenScreen()) and so drawing and 2d commands couldn't be used
3. the task size is aproxamatly endless as OGRE3D is really huge
4. later, the created code has to be updated, too. And updates can be a big challange for a single person. But otherwise this project would have no reason if it gets outdated, too.
I would really love to have a open source wrapper for Ogre3D that is up to date.
And it should be possible, it is just nothing that one person can do in a timeframe that is reasonable.
MFG PMV
1. the work done by PB-Team has to be done again
2. you will problably not be able to use a pb-screen (OpenScreen()) and so drawing and 2d commands couldn't be used
3. the task size is aproxamatly endless as OGRE3D is really huge
4. later, the created code has to be updated, too. And updates can be a big challange for a single person. But otherwise this project would have no reason if it gets outdated, too.
I would really love to have a open source wrapper for Ogre3D that is up to date.
And it should be possible, it is just nothing that one person can do in a timeframe that is reasonable.
MFG PMV