On Wed, Aug 6, 2008 at 6:09 PM, Zeeshan Ali Khattak <[EMAIL PROTECTED]> wrote:
> Hi!
>   I've started to use these bindings for (re)learning OpenGL. I
> already compiled by hello-world (which is attached to this mail). Two
> observations so far:

 Oops! Forgot the attachment. :)

-- 
Regards,

Zeeshan Ali Khattak
FSF member#5124
using Gtk;
using Gdk;
using GL;

public class Rectangle: GLib.Object {
   static int main (string[] args) {
        Gtk.init (ref args);
        Gtk.GL.init (ref args);

        Gdk.GL.Config config = new Gdk.GL.Config.by_mode (
                                        Gdk.GL.ConfigMode.RGB |
                                        Gdk.GL.ConfigMode.DEPTH);
        assert (config != null);

        Gtk.Window window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);

        if (!Gtk.GL.GtkWidgetExtension.set_gl_capability
                                            (window,
                                             config,
                                             null,
                                             true,
                                             Gdk.GL.RenderType.RGBA_TYPE)) {
            error ("Couldn't add GL caps to window\n");
        }

        window.realize += on_window_realize;
        window.expose_event += on_window_expose;

        window.show ();

        Gtk.main ();

        return 0;
   }

   private static void on_window_realize (Gtk.Window window) {
        weak Gdk.GL.Drawable drawable;
        weak Gdk.GL.Context context;

        drawable = Gtk.GL.GtkWidgetExtension.get_gl_drawable (window);
        context = Gtk.GL.GtkWidgetExtension.get_gl_context (window);
        assert (context != null);

        if (!drawable.gl_begin (context)) {
            critical ("Failed to draw\n");

            Gtk.main_quit ();
        }

        GL.ClearColor (0.0f, 0.0f, 0.2f, 0.0f);
        GL.Clear (Consts.COLOR_BUFFER_BIT);

        drawable.gl_end ();
   }

   private static bool on_window_expose (Gtk.Window window) {
        weak Gdk.GL.Drawable drawable;
        weak Gdk.GL.Context context;

        drawable = Gtk.GL.GtkWidgetExtension.get_gl_drawable (window);
        context = Gtk.GL.GtkWidgetExtension.get_gl_context (window);
        assert (context != null);

        if (!drawable.gl_begin (context)) {
            critical ("Failed to draw\n");

            Gtk.main_quit ();
        }

        GL.Begin (Consts.TRIANGLES);
            GL.Color3f (1.0f, 1.0f, 1.0f);

            GL.Vertex3d (0.25, 0.25, 0.0);
            GL.Vertex3d (0.75, 0.25, 0.0);
            GL.Vertex3d (0.75, 0.75, 0.0);
            GL.Vertex3d (0.25, 0.75, 0.0);
        GL.End ();

        GL.Flush ();

        drawable.gl_end ();

        return true;
   }
}

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to