Good day.
I've been trying to port HGE (http://hge.relishgames.com) to Python for more than 4 months now...
HGE is a hardware accelerated 2D game engine.
It comes with the source and examples. In the folder "include", you can find "hge.h", the file that i am talking about in all the post.
#
I tried to load the DLL functions with Python Ctypes like this :
>>> from ctypes import *
>>> HGE = cdll.LoadLibrary("C:/hge181/hge")
>>> HGE.hgeCreate(0x180)
But i get this error : "Procedure called with not enough arguments (4 bytes missing) or wrong calling convention".
The call should be done with hgeCreate(HGE_VERSION) and the constant is defined as "#define HGE_VERSION 0x180"...
Number 0x180 means 384 in Python. I don't mean what it means in C.
So i am stuck.
I also tried to modify the "hge.h" file on line 408, and export the rest of the classes...
__declspec (dllexport) hgeVertex;
__declspec (dllexport) hgeTriple;
__declspec (dllexport) hgeQuad;
__declspec (dllexport) hgeInputEvent;
But after compilation, i am not able to access them from Python "ctypes". They seem to remain invisible. Perhaps i am not doing it right?...
#
I tried Cython.
I tried to load "hge.h" in Cython and use the structures.
The first error i get is at line 173: "typedef bool (*hgeCallback)();". I am not that good in C/C++ to understand what it means. So i commented it...
The second big error is at line 408: "extern "C" { EXPORT HGE * CALL hgeCreate(int ver); }". This should be the DLL export. I comented that too...
I used this code in Cython, loading from "hge.h":
# file HGE.pyx
cdef extern from "windows.h":
pass
cdef extern from "hge.h":
pass
And i get this errors:
..\hge.h(215) : error C2061: syntax error : identifier 'hgeVertex'
..\hge.h(218) : error C2059: syntax error : '}'
..\hge.h(226) : error C2061: syntax error : identifier 'hgeVertex'
..\hge.h(229) : error C2059: syntax error : '}'
..\hge.h(274) : error C2061: syntax error : identifier 'HGE'
..\hge.h(274) : error C2059: syntax error : ';'
..\hge.h(275) : error C2449: found '{' at file scope (missing function header?)
..\hge.h(407) : error C2059: syntax error : '}'
Then i tried to define hgeVertex in Cython like:
struct hgeVertex:
float x, y # screen position
float z # Z-buffer depth 0..1
DWORD col # color
float tx, ty # texture coordinates
But i get the exact same errors.
If i comment all the structures hgeVertex and Triple and Quad and the HGE class, the Cython file compiles !... But it's not useful at all.
My Cython is okay, i compiled a few programs before, so that's not a problem...
#
Then i tried Swig (and it worked with the examples )... But the problems with "hge,h" seem to be somewhat similar.
I call swig like this : "swig -c++ -python hge.i"
And the file "hge.i" contains:
/* File : hge.i */
%module hge
%{
#include "hge.h"
%}
/* Let's just grab the original header file here */
%include "hge.h"
And the error i get after commenting the HGE callback and DLL export is this : "hge.h(276): Error: Syntax error in input(3)." Line 276 is exactly the first call of HGE class : "virtual void CALL Release() = 0;".
#
I tried Boost.Python (and it works with embedding and extending examples), but i could't compile "hge.h" even after commenting the structures and classes. I have to write some wrapper code in "hge.h" and i am probably doing it completely wrong.
BOOST_PYTHON_MODULE(hge)
{
using namespace boost::python;
class_<hgeVertex> base("hgeVertex");
}
So i am stuck again...
I am not that good in neither C or Python.
Can anyone suggest any ideas? Please?
I really really really want to port HGE in Python. It's the greatest game engine i have ever seen. The particle engine is EXCELLENT and i need it.
Thank you in advance.