From: Chananya Freiman Date: 2010-12-25T04:43:29+09:00 Subject: Re: OpenGL support I looked a bit into C extensions and I thought of a pretty easy way of making the bindings. However, this way isn't really "portable" in the sense that you have to run a Ruby file on every computer, and have to have something that can create an OpenGL context (I am using GLFW at the moment). All these steps are done in an rb file, no need to do it manually. Step 1) Download the gl3.h file from opengl.org Step 2) Create a tiny C extension that creates an OpenGL context, gets the OpenGL version supported by the computer, and terminates the context. Step 3) Start creating the bindings by parsing gl3.h and taking the version into consideration. Parsing should be too hard. You figure where the first occurrence of "#define GL_VERSION_x_y", where x and y are your major and minor parts of the GL version. You find the next occurrence of any GL_VERSION. This is where your drivers stop supporting constants, so you parse everything that far. Now, you get the next occurrence of "#define GL_VERSION_x_y", and again the next occurrence of any GL_VERSION. This is where the drivers stop supporting actual GL function entry points, so you parse the entry points until there. And...that's basically it. The parsing itself is pretty easy. Constants are a quick one-liner in a String#scan: data.scan(/#define (GL_[A-Z0-9_]+)[ \t]+([0-9A-Fx]+)/) { |block| f.puts "rb_define_const(GL, \"#{block[0]}\", INT2FIX(#{block[1]}));" } Functions are a little harder because of the argument types that need to be taken into account, but it shouldn't be too hard (I started working on them and then realized that I forgot to remove functions of higher GL version then I have so I got tons of linker errors :P). The main problem of this as I see it is the fact that you must create a context to get the GL version. Running a Ruby file is sort of an annoyance, but then installing gems is more work. Having to have a specific library, however, is sort of un-portable and annoying. What do you guys think about this? -- Posted via http://www.ruby-forum.com/.