-2

Edit : it's not a problem of header linking or package missing

I'm trying to compile a Vala sample program from:

https://wiki.gnome.org/Projects/Vala/OpenGLSamples.

I am on Arch Linux.

I have two errors:

Vala API can't be found
Package `GL` not found
Package `GLFW' not found
  • Welcome to stackoverflow, have you done the tour? http://stackoverflow.com/tour – Jens Mühlenhoff Nov 07 '15 at 11:03
  • Please include more information in your question, you can also [edit your question](http://stackoverflow.com/posts/33556913/edit) at any time to improve it. – Jens Mühlenhoff Nov 07 '15 at 11:04
  • To the downvoters: I know you don't have to explain yourselves, but it would have been helpful to write a comment or two in order to help this user with his/her first question. – Jens Mühlenhoff Nov 07 '15 at 11:06

1 Answers1

3

There are several issues with the example you linked to:

  1. It was written with an old libglfw.vapi file.
  2. 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

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
  • sorry i dont understand, i have using GLFW; using GL; in my code. and i compile with this valac --pkg gl --pkg libglfw t.vala (also tried with using glfw3 and pkg glfw3) i understand the binding you show but how can i link this to my vala code ? –  Nov 06 '15 at 18:01
  • so, i copied the glfw3.vapi and valac --pkg glfw3 t.vala. now i have a message glfwSwapBuffers does not exist in the context and the same for all function in glfw3 –  Nov 06 '15 at 19:21
  • 1
    The links in [ListOfBindings](https://wiki.gnome.org/Projects/Vala/ListOfBindings) are now fixed. You may also want to read [Vala and Modern OpenGL](http://lucidfox.dreamwidth.org/11614.html) where someone who updated the OpenGL bindings recommends [Cogl](http://www.cogl3d.org/) – AlThomas Nov 08 '15 at 14:30