English 中文(简体)
Best dynamic languages for OpenGL/general graphics
原标题:

Which are the most mature and well supported solutions for writing graphical programs?

I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach.

Ruby and Processing? Python and OGRE? What things have worked well for you?

问题回答

If you are just interested in experimenting, I d suggest picking a 3D framework with bindings for a dynamic language you are already familiar with.

I started doing experiments with Ruby/OpenGL a year or three ago and that was easy enough to play around with.

If you seriously want to build a project (for whatever reason), I d suggest picking a framework based on a combination of

  • The native language it s implemented in (or runtime it runs on)
  • The dynamic language bindings available for the engine or runtime
  • The license of the framework

If you want your project to be fairly easily running across different OS es, you ll probably want to pick a framework written in Java (because the JVM runs everywhere) with bindings in Ruby (jRuby) or JavaScript (because these languages are well supported there). This would, however, limit the frameworks available to you. (This is my OSS + linux bias showing).

Wikipedia has a list of game engines. Based on several criteria I started a project with jMonkeyEngine (v2) and found it easy to work with and control from Rhino (a JVM JavaScript implementation).

I recently saw a presentation from another Java-based framework with bindings for several languages that looked really cool (inspired by the Ogre engine), but I forget the name and can t find it in the list.

Doing C# at the time I did look at projects/frameworks targeting both dotNet and Mono for running across platforms but it was too much hassle to get the development builds of the (Tao?) framework and the Mono Lua bindings running. Maybe things have changed.

To sum it up, pick a framework that can run on the environment(s) you want with bindings for the dynamic language that you want to use. Even if the framework library code available for the dynamic language you want to use is fairly minimal you can easily extend it if you can work with the underlying language. If you re fluent with C++, Java and C# shouldn t be too much of a stretch.

Given you are familiar with C++, you might give Lua a try. Lua is a dynamic language that can be embedded in any C/C++ program. It is very popular in the game industry.

I would like to mention Python with PyOpenGL as an option to consider.

If you are already familiar with OpenGL, PyOpenGL is basically a API wrapper written in Python. I was surprised at first how similar the code looks in Python and in C++. Like this (note I m also using Pyglet):

def setup_render(self):
       First rendering setup   
    glClearColor(0.0, 0.0, 0.0, 1.0) 
    glClearDepth(1.0)       

    glEnable(GL_LIGHTING)       
    glEnable(GL_DEPTH_TEST)    
    glEnable(GL_ALPHA_TEST)         
    glEnable(GL_CULL_FACE)              

def draw(self, time_passed):
       Drawing events   
    if self.has_exit:
        pyglet.app.exit()
        return

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glUseProgram(self.shader.program)
    self.set_lights()

    # Draw objects here
    glTranslate(0, 0, -10)
    glScale(5.0, 5.0, 5.0)
    glutSolidSphere(1, 16, 16)

See how similar it is to C++ code.

I was able to quickly pick up PyOpenGL in Python, and implemented a Quaternion class under 200 lines. If you re comfortable with Python, I wouldn t hesitate to recommend you to check it out.

By the way, PyOpenGL s API documentation is far more readable than the official one, too.

If you are looking for dynamic languages that support OpenGL out-of-the-box (no external bindings) try these:

My personal suggestion if you are after maturity and support would be Processing - very flexible, open source, well documented and a great community. Syntax is C-like so you should have no difficulty picking it up.

One slightly more cutting edge solution that looks very promising (but I haven t got round to testing yet!) is Penumbra - a Clojure library for OpenGL development in a dynamic functional programming style. Here s a elegant little snippet:

(enable :light0)
(push-matrix
  (translate 0 0 -10)
  (draw-quads
    (vertex 0 0 0)
    (vertex 0 1 0)
    (vertex 1 1 0)
    (vertex 1 0 0)))

Note that thanks to lots of Clojure macro cleverness, it automatically and transparently handles things like popping the transformation matrices at the right time. Other things that look good are things like GPGPU support.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签