There are several issues with the example you linked to:
- It was written with an old libglfw.vapi file.
- All the gl.vapi links on the ListOfBindings page are dead.
I have tried to rewrite the example for glfw3.vapi
:
using GL;
int show_triangle () {
// Open an OpenGL window (you can also try Mode.FULLSCREEN)
var win = new GLFW.Window(640, 480, "My example window");
if (win == null)
return 1;
// Making the context current is required before calling any gl* function
win.make_context_current ();
// Main loop, exit when the user closes the window (e.g. via ALT + F4 or close button)
while (!win.should_close) {
// OpenGL rendering goes here...
glClear (GL_COLOR_BUFFER_BIT);
glBegin (GL_TRIANGLES);
glVertex3f ( 0.0f, 1.0f, 0.0f);
glVertex3f (-1.0f,-1.0f, 0.0f);
glVertex3f ( 1.0f,-1.0f, 0.0f);
glEnd ();
// Swap front and back rendering buffers
win.swap_buffers ();
// Poll events, otherwise should_close will always be false
GLFW.poll_events ();
}
return 0;
}
int main () {
// Initialize GLFW
if (!GLFW.init ())
return 1;
int exit_code = show_triangle ();
// Terminate GLFW
GLFW.terminate ();
// Exit program
return exit_code;
}
You have to reference the glfw3.vapi
file which is part of the vala-extra-vapis package:
https://wiki.gnome.org/action/show/Projects/Vala/ListOfBindings
https://git.gnome.org/browse/vala-extra-vapis/tree/glfw3.vapi
Problem 2 can be fixed by using a gl.vapi from somewhere else, e.g.:
https://github.com/mikesmullin/Vala-Genie-OpenGL/blob/master/gl.vapi
You also have to install the package of your distribution that contains the glfw3 development files. (e.g. libglfw3-dev on Debian)
If you put both vapi files and the example source code in your working directory you can compile with:
valac --vapidir=. --pkg gl --pkg glfw3 test.vala
Edit: I have improved my code using some info from the glfw quick start tutorial here:
http://www.glfw.org/docs/latest/quick.html