views:

253

answers:

10

I know this question could be in vain, but it's just out of curiosity, and I'm still much a newb^^ Anyways I've been loving python for some time while learning it. My problem is obviously speed issues. I'd like to get into indie game creation, and for the short future, 2d and pygame will work.
But I'd eventually like to branch into the 3d area, and python is really too slow to make anything 3d and professional. So I'm wondering if there has ever been work to create a high-level language able to import and use c libraries? I've looked at Genie and it seems to be able to use certain libraries, but I'm not sure to what extent. Will I be able to use it for openGL programing, or in a c game engine?
I do know some lisp and enjoy it a lot, but there aren't a great many libraries out there for it. Which leads to the problem: I can't stand C syntax, but C has libraries galore that I could need! And game engines like irrlicht. Is there any language that can be used in place of C around C?

Thanks so much guys

A: 

To some extent, Cython might be what you are looking for. It allows you to use Python as a high level language, but then use C for the parts that need to be optimized.

But, at the end of the day, if you want to do 3D, just learning C or C++ may be the way to go. :-)

carl
+9  A: 

Python can call functions in dynamically loaded C libraries (.so in unix, .dll in Windows) using the ctypes module.

There is also cython - a variation of python that compiles to C and can call C libraries directly. You can mix modules written in pure Python and cython.

You may also want to look at the numerous 3D game engines either written specifically for Python or with a python interface. The ones I have heard the most about (but not used) are Blender and Python-Ogre.

Dave Kirby
+1 for recommending libraries that already exist :)
Matthieu M.
C library can be statically linked - i.e. *.lib or *.a file. IT is a "C library" after all, not a "dynamically linked library".
SigTerm
@SigTerm - I am not sure what you mean. ctypes only works with shared libraries, ie. .so or .dll. It does not work with statically linked libraries. http://docs.python.org/library/ctypes.html
Dave Kirby
+1  A: 

Python is able to use C libraries via the ctypes module. You'll have to write some Python code to import the C functions, but if the C API is clean and simple you'll have no trouble at all.

Unknown
A: 

There are Python wrappers available for major open source game engines (Ogre, Irrlicht, etc.). Particularly Panda3D ought to have nice bindings.

bebraw
+3  A: 

Panda3D is an engine which uses Python as it's "game logic" interface. You basically write everything in Python and the Panda3D backend (which I assume is mostly written in C or C++) is responsible for rendering.

Check out the gallery of projects that use Panda3D. It's not going to be AAA the-next-Gears-of-War level graphics, but it's still pretty impressive.

Dean Harding
Most of the Panda3D backend is C++.
Crashworks
+1  A: 

You might find these useful:

Jacek
A: 

If you'd like to have a look at .Net platform. You have the following solution:

  1. Use C++/CLI to compile your C/C++ code into .Net assembly, the running time of this part would be as the same as your native C/C++ code.

  2. Use any .Net language (C#, F#, IronPython) to develop high-level stuff using the low level library. For pure number crunching, C#/F# is usually 2-4 times slower than native C code, which is still far faster than Python. For non-number crunching tasks, C#/F# could sometimes match the speed of native code.

Yin Zhu
I like C# a lot and plan to eventually learn it for xna, but right now my main development platform is linux. From what I understand C#, linux, and gaming doesn't go well together.
Isaiah
theoretically C# (through Mono), GNU/Linux and gaming can go well together in the same way they can go if you change GNU/Linux with MS Windows. What's happening for real, I don't know.
ShinTakezou
+1  A: 

I have been using PyOpenGL, it works great. Swig does its job if you want to call C/C++ libraries from Python.

kotlinski
+3  A: 

Using swig you can make C imports in various languages: lua, python, php, c# ...

See more info here about supported wrappers.

Iulian Şerbănoiu
+1  A: 

I'm surprised that no-one has yet stated clearly that C++ is what you are looking for. Like you I have a distaste for C syntax, but that's a poor reason for avoiding C++ if you want to get into 3D gaming. Do you want to dive into 3D gaming, or do you want to sit on the edge of the pool crying that the water is too cold ?

I think you'll also find that C++ plays very well with OpenGL, which is probably not true of a lot of the alternatives that have already been suggested

High Performance Mark
If the syntax is really the motivator for avoiding C, then C++ doesn't really seem like much of a help.
Rob Kennedy
@Rob: I don't dispute what you write, I do think distaste for a particular language's syntax is a poor reason to avoid using the right tool for the job. Lots of people think C++ is the right tool for 3D games. Personally I think C++'s syntax is worse than C's, but I'm not trying to get into 3D games programming.
High Performance Mark
@High Be careful of those "right tool for the job" assumptions. Python is clearly the "right tool for the job" if development time is the bottleneck rather than performance or bleeding-edge graphics.
Rakis