| Path: | README.API |
| Last Update: | Mon Oct 22 02:04:09 +0200 2007 |
The function names and general usage are equivalent to C (you can read the GLFW C API documentation here), with some differences outlined bellow.
The naming conventions follows those of ruby-opengl bindings - all the constants and functions are contained in Glfw module (click for RDoc documentation), in file glfw.so which is loaded by writing
require 'glfw'
You can also add
include Glfw
which will export the module‘s functions and constants to the global namespace, so instead of writing
Glfw.glfwSomeFunction(Glfw::GLFW_SOME_CONSTANT)
in full scope, you can then use the C-like syntax:
glfwSomeFunction(GLFW_SOME_CONSTANT)
Loading the module will call Glfw.glfwInit function, and will generate ruby exception should the initialization fail. At the end of your program, Glfw.glfwTerminate is automatically called, although you are free to call it yourself if you wish.
Functions working with boolean states are using ruby‘s true/false rather then GL_TRUE/GL_FALSE (both for input and output).
For specifying callback functions just pass ruby Proc object, e.g
mouse_callback = lambda do |x,y|
puts "Mouse moved! current mouse position is #{x} #{y}"
end
...
glfwSetMousePosCallback(mouse_callback)
or convert regular function, as
def mouse_callback(x,y)
puts "Mouse moved! current mouse position is #{x} #{y}"
end
...
glfwSetMousePosCallback(method("mouse_callback").to_proc)
Passing ‘nil’ will disable the callback.
You can combine GLFW with other GL or graphic libraries as long as you use only one of them for window creation/destruction, events callbacks and general window state modifications. For example you can write:
require 'glfw' require 'glut' include Glfw,Glut ... glfwCreateWindow(...) # use GLFW to create OpenGL window glutSolidSphere(...) # use GLUT to draw sphere ...
You can find the examples in the ‘examples’ directory - they are pretty much just conversion of the GLFW C examples. The ‘particles’ example was tuned down for compensation of ruby speed - see the file particles.rb for more details.