Is PyOpenGL as fast as OpenGL?

I'm trying to create a generic game engine in Python and PyOpenGL, but I don't know if it's even worth trying because I'm not sure if Python is the right way to go ...

As far as I know, PyOpenGL is just a wrapper for OpenGL. However, I still see people saying things like "OpenGL is better" and "Python is too slow".

Take a look at this question for example . Most of the answers are biased towards C ++.

If they use the same technology, why is it better to be better than others? For me, the language doesn't seem to matter much since most of the work is done by OpenGl / hardware. What am I missing?


source to share

2 answers

First difference: OpenGL is a specification, not a library. So comparing PyOpenGL to OpenGL is like comparing blue print to home.

Answering your question: Python is an interpreted language like Java. Game engines are very computationally intensive not only for graphics but also physics, AI, animation, loading 3D files, etc. PyOpenGL is probably good enough for good graphics, but Python is not good enough for all the cpu-side code.

Of course, this also depends on the "level" of your game engine: for simple / academic games, Python might work fine, but don't expect Cryengine from it.



Think of it this way: "how many layers of abstraction are between your application and the GPU. So let's see. Using Python, you have a Python interpreter that reads, parses, and converts your code into intermediate (Python bytecode) which is then loaded into the Python virtual machine runtime , and the runtime interprets that bytecode and executes it.Now if you are using the OpenGL library, this means that after that Python must also call GL methods through some abstraction layer, probably similar to Java JNI . which wraps pointers to OpenGL API functions (usually a shared C ++ library). And only after that a GL command is passed to your OpenGL driver. As it does in Java, C # OpenGL wrappers.

Now if you are using C ++ and I have omitted all the obvious advantages of C ++ as a native language (compiled directly to machine bytecode) based on virtual machines / interpreters here, you call these GL API methods directly (after how they are loaded at startup) using libs extensions such as GLEW.No interfaces or wrappers. So not only are you taking advantage of C ++, but you are also using a so-called "close to metal" language capable of interacting directly with the graphical API, without any of the mediation that usually causes noticeable overhead in heavy applications.

But as others say, it really depends on the nature of your application. If you're working on some kind of prototype or scientific modeling where results are more important than performance, then Python is probably sufficient. But if your goal is to squeeze everything from your GPU, you should go for native.

Hope it helps.



All Articles