private static int Main(string[] args) { // * Init GTK. Gtk.Application.Init ("Color", ref args); // * Init GtkGLExt. GtkGL.Application.Init (ref args); // * Display mode. GdkGL.ConfigMode mode = GdkGL.ConfigMode.Index; for (int i = 0; i < args.Length; i++) { if (args[i] == "--rgb") mode = GdkGL.ConfigMode.Rgb; } // * Query OpenGL extension version. int major, minor; Query.Version (out major, out minor); Console.WriteLine ("\nOpenGL extension version - {0}.{1}", major, minor); // * Configure OpenGL-capable visual. // Try double-buffered visual GdkGL.Config glconfig = new GdkGL.Config (mode | GdkGL.ConfigMode.Depth | GdkGL.ConfigMode.Double); if (glconfig == null) { Console.WriteLine ("*** Cannot find the double-buffered visual.\n*** Trying single-buffered visual."); glconfig = new GdkGL.Config (mode | GdkGL.ConfigMode.Depth); if (glconfig == null) { Console.WriteLine ("*** Cannot find any OpenGL-capable visual."); return 1; } } GlUtilities.WriteOutConfig (glconfig); bool is_rgba = glconfig.IsRgba; // Top-level window. Window window = new Window (WindowType.Toplevel); window.Title = "color"; // Perform the resizes immediately window.ResizeMode = ResizeMode.Immediate; // Get automatically redrawn if any of their children changed allocation. window.ReallocateRedraws = true; window.DeleteEvent += new DeleteEventHandler (Window_Delete); // VBox. VBox vbox = new VBox (false, 0); window.Add (vbox); vbox.Show (); // Drawing area for drawing OpenGL scene. ColorTriangle drawing_area = new ColorTriangle (glconfig); drawing_area.SetSizeRequest (200, 200); vbox.PackStart (drawing_area, true, true, 0); drawing_area.Show (); // Simple quit button. Button button = new Button ("Quit"); button.Pressed += new EventHandler (Button_Click); vbox.PackStart (button, false, false, 0); button.Show (); // * Show window. window.Show (); // * Allocate colors. if (!is_rgba) { Gdk.Colormap colormap = glconfig.Colormap; Console.WriteLine ("\nAllocate colors."); // Allocate writable color cells. bool[] success = new bool [NUM_COLORS]; int not_allocated = colormap.AllocColors (colors, NUM_COLORS, false, false, success); for (int i = 0; i < NUM_COLORS; i++) Console.WriteLine ("{0}", success[i]); Console.WriteLine ("Not allocated = {0}", not_allocated); for (int i = 0; i < NUM_COLORS; i++) Console.WriteLine ("colors[{0}] = [ {1}, {2}, {3}, {4} ]", i, colors[i].Pixel, colors[i].Red, colors[i].Green, colors[i].Blue ); Console.WriteLine ("\nQuery colors."); for (int i = 0; i < NUM_COLORS; i++) { Gdk.Color color = new Gdk.Color (); color.Pixel = colors[i].Pixel; colormap.QueryColor (colors[i].Pixel, ref color); Console.WriteLine ("colors[{0}] = { {1}, {2}, {3}, {4} }", i, colors[i].Pixel, color.Red, color.Green, color.Blue); } Console.WriteLine (); } // * Main loop. Gtk.Application.Run (); return 0; }
static int Main(string[] args) { // Init GTK. Gtk.Application.Init ("Button", ref args); // Init GtkGLExt. GtkGL.Application.Init (ref args); // Configure OpenGL-capable visual. // Try double-buffered visual GdkGL.Config glconfig = new GdkGL.Config (GdkGL.ConfigMode.Rgb | GdkGL.ConfigMode.Depth | GdkGL.ConfigMode.Double); if (glconfig == null) { Console.WriteLine ("*** Cannot find the double-buffered visual."); Console.WriteLine ("*** Trying single-buffered visual."); // Try single-buffered visual glconfig = new GdkGL.Config (GdkGL.ConfigMode.Rgb | GdkGL.ConfigMode.Depth); if (glconfig == null) { Console.WriteLine ("*** No appropriate OpenGL-capable visual found."); return 1; } } // Top-level window. Window window = new Window (WindowType.Toplevel); window.Title = "button"; // Perform the resizes immediately window.ResizeMode = ResizeMode.Immediate; // Get automatically redrawn if any of their children changed allocation. window.ReallocateRedraws = true; // Set border width. window.BorderWidth = 10; window.DeleteEvent += new DeleteEventHandler (Window_Delete); // Toggle button which contains an OpenGL scene. GlToggleButton button = new GlToggleButton (glconfig); button.Show (); window.Add (button); // Show window. window.Show (); // Main Loop Gtk.Application.Run(); return 0; }
public static int Main(string[] args) { /* * Init GTK. */ Gtk.Application.Init (/*"Gears3D", null*/); /* * Init GtkGLExt. */ GtkGL.Application.Init (ref args); /* * Command line options. */ for (int i = 0; i < args.Length; i++) if (args[i] == "--async") is_sync = false; /* * Configure OpenGL-capable visual. */ /* Try double-buffered visual */ GdkGL.Config glconfig = new GdkGL.Config (GdkGL.ConfigMode.Rgb | GdkGL.ConfigMode.Depth | GdkGL.ConfigMode.Double); if (glconfig == null) { Console.WriteLine ("*** Cannot find the double-buffered visual.\n*** Trying single-buffered visual."); /* Try single-buffered visual */ glconfig = new GdkGL.Config (GdkGL.ConfigMode.Rgb | GdkGL.ConfigMode.Depth); if (glconfig == null) { Console.WriteLine ("*** Cannot find any OpenGL-capable visual."); return 1; } } /* * Top-level window. */ Window window = new Window (WindowType.Toplevel); window.Title = "gears"; /* Get automatically redrawn if any of their children changed allocation. */ window.ReallocateRedraws = true; window.DeleteEvent += new DeleteEventHandler (Window_Delete); /* * VBox. */ VBox vbox = new VBox (false, 0); window.Add (vbox); vbox.Show (); /* * Drawing area for drawing OpenGL scene. */ /* Set OpenGL-capability to the widget. */ GearsArea drawing_area = new GearsArea (glconfig); drawing_area.SetSizeRequest (300, 300); window.KeyPressEvent += new KeyPressEventHandler (drawing_area.OnKeyPress); vbox.PackStart (drawing_area, true, true, 0); drawing_area.Show (); /* * Simple quit button. */ Button button = new Button ("Quit"); button.Clicked += new EventHandler (Button_Click); vbox.PackStart (button, false, false, 0); button.Show (); /* * Show window. */ window.Show (); /* * Main loop. */ Gtk.Application.Run (); return 0; }