Author: cjcollier
Date: 2005-12-13 20:27:59 -0500 (Tue, 13 Dec 2005)
New Revision: 54337

Added:
   trunk/gtkglarea-sharp/examples/NeHe/
   trunk/gtkglarea-sharp/examples/NeHe/Lesson01/
   trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Lesson01.cs
   trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Makefile.am
   trunk/gtkglarea-sharp/examples/NeHe/Lesson02/
   trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Lesson02.cs
   trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Makefile.am
   trunk/gtkglarea-sharp/examples/NeHe/Lesson03/
   trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Lesson03.cs
   trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Makefile.am
   trunk/gtkglarea-sharp/examples/NeHe/Lesson04/
   trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Lesson04.cs
   trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Makefile.am
   trunk/gtkglarea-sharp/examples/NeHe/Makefile.am
Log:
- added NeHe examples


Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Lesson01.cs
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Lesson01.cs    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Lesson01.cs    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,165 @@
+// created on 12/13/2005 at 1:51 PM
+using System;
+using Gtk;
+using GtkSharp;
+
+using GtkGL;
+
+using Tao.OpenGl;
+
+using gl=Tao.OpenGl.Gl;
+using glu=Tao.OpenGl.Glu;
+
+// This code is based on work from Alp Toker and the NeHe lesson here:
+// http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
+namespace NeHe.Lesson01
+{
+       public class Lesson01
+       {
+               /* GlArea is the widget defined in the GtkGL namespace and is a
+                * specialized GtkDrawingArea with GL cow powers.
+                */
+               
+               GLArea glarea;
+               
+               /*      attrList
+            *      Specifies a list of Boolean attributes and enum/integer
+                *      attribute/value pairs. The last attribute must be zero 
or
+                *      _GDK_GL_CONFIGS.None.
+                *      
+                *      See glXChooseVisual man page for explanation of
+                *      attrList.
+                *      
+                *      http://www.xfree86.org/4.4.0/glXChooseVisual.3.html
+                */
+                  
+               int[] attrlist = {
+               (int)GtkGL._GDK_GL_CONFIGS.Rgba,
+               (int)GtkGL._GDK_GL_CONFIGS.RedSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.GreenSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.BlueSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.DepthSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.Doublebuffer,
+               (int)GtkGL._GDK_GL_CONFIGS.None,
+               };      
+               
+               // This method is called "ReSizeGLScene" in the original lesson
+               void OnConfigure (object o, EventArgs e)
+               {
+                       if( glarea.MakeCurrent() == 0)
+                               return;
+                       
+                       int height = glarea.Allocation.Height,
+                               width  = glarea.Allocation.Width;
+                               
+                       Console.WriteLine("Width: {0}", width);
+                       Console.WriteLine("Height: {0}", height);
+                       
+                       
+                       if (height==0)                                          
                        // Prevent A Divide By Zero By
+                       {
+                               height=1;                                       
                                // Making Height Equal One
+                       }
+                               
+                       gl.glViewport (0, 0, width, height);
+                       
+                       gl.glMatrixMode(gl.GL_PROJECTION);                      
        // Select The Projection Matrix
+                       gl.glLoadIdentity();                                    
                // Reset The Projection Matrix
+
+                       // Calculate The Aspect Ratio Of The Window
+                       
glu.gluPerspective(45.0f,(float)width/(float)height,0.1f,100.0f);
+
+                       gl.glMatrixMode(gl.GL_MODELVIEW);                       
        // Select The Modelview Matrix
+                       gl.glLoadIdentity();            
+               }
+
+               bool InitGL()
+               {
+                       if (glarea.MakeCurrent() == 0)
+                               return false;
+
+                       gl.glShadeModel(gl.GL_SMOOTH);                          
                // Enables Smooth Shading
+                       gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
        // Black Background
+                       gl.glClearDepth(1.0f);                                  
                        // Depth Buffer Setup
+                       gl.glEnable(gl.GL_DEPTH_TEST);                          
                // Enables Depth Testing
+                       gl.glDepthFunc(gl.GL_LEQUAL);                           
                // The Type Of Depth Test To Do
+                       // Really Nice Perspective Calculations
+                       gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, 
gl.GL_NICEST);     
+                       
+                       return true;
+               }
+               
+               // The correct time to init the gl window is at Realize time
+               void OnRealized (object o, EventArgs e)
+               {
+                       if(!InitGL())
+                               Console.WriteLine("Couldn't InitGL()");
+               }
+
+               // This method is called "DrawGLScene" in the original lesson   
        
+               void OnExposed (object o, EventArgs e)
+               {
+               
+                       if (glarea.MakeCurrent() == 0)
+                               return;
+
+                       Console.WriteLine("Exposed!");
+                       
+                       // Clear The Screen And The Depth Buffer
+                       gl.glClear(gl.GL_COLOR_BUFFER_BIT | 
gl.GL_DEPTH_BUFFER_BIT);
+                       gl.glLoadIdentity();                                    
                        // Reset The Current Modelview Matrix
+                       
+                       glarea.SwapBuffers ();                                  
                        // Show the newly displayed contents
+               }
+
+               public static int Main (string[] argc)
+               {
+                       Gtk.Application.Init ();
+
+                       Lesson01 l = new Lesson01();
+
+                       // Go, dog, go!
+                       Gtk.Application.Run ();
+
+                       return 1;
+               }               
+
+               public Lesson01()
+               {
+                       // Create a new GLArea widget and request a size
+                       glarea = new GLArea (attrlist);
+                       glarea.SetSizeRequest (300, 300);
+                       
+                       // Set some event handlers
+                       glarea.ExposeEvent += OnExposed;
+                       glarea.Realized += OnRealized;
+                       glarea.Unrealized += OnUnrealized;
+                       glarea.ConfigureEvent += OnConfigure;
+                                               
+                       // Create a new Vertical Box that the GLArea can live in
+                       VBox vb = new VBox (false, 0);
+                       
+                       // Pack the GLArea widget into the VBox
+                       vb.PackStart (glarea, true, true, 0);
+                       
+                       // Create a new window and name it appropriately
+                       Window win = new Window ("NeHe Lesson01");
+                       
+                       // Pack the VBox into the window
+                       win.Add (vb);
+
+                       // Show all of win's contained widgets
+                       win.ShowAll ();
+
+               }
+                               
+
+               
+               void OnUnrealized (object o, EventArgs e)
+               {
+                       Application.Quit();
+               }
+               
+
+       }
+}

Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Makefile.am
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Makefile.am    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson01/Makefile.am    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,15 @@
+SRCS = Lesson01.cs
+
+CLEANFILES = Lesson01.exe
+
+all: Lesson01.exe
+
+Lesson01.exe: $(SRCS)
+       mcs \
+               -pkg:gtk-sharp-2.0 \
+               -pkg:gtkgl-sharp-2.0 \
+               -pkg:tao \
+               $(SRCS) \
+               -out:Lesson01.exe
+
+

Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Lesson02.cs
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Lesson02.cs    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Lesson02.cs    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,181 @@
+// created on 12/13/2005 at 1:51 PM
+using System;
+using Gtk;
+using GtkSharp;
+
+using GtkGL;
+
+using Tao.OpenGl;
+
+using gl=Tao.OpenGl.Gl;
+using glu=Tao.OpenGl.Glu;
+
+// This code is based on work from Alp Toker and the NeHe lesson here:
+// http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
+namespace NeHe.Lesson02
+{
+       public class Lesson02
+       {
+               /* GlArea is the widget defined in the GtkGL namespace and is a
+                * specialized GtkDrawingArea with GL cow powers.
+                */
+               
+               GLArea glarea;
+               
+               /*      attrList
+            *      Specifies a list of Boolean attributes and enum/integer
+                *      attribute/value pairs. The last attribute must be zero 
or
+                *      _GDK_GL_CONFIGS.None.
+                *      
+                *      See glXChooseVisual man page for explanation of
+                *      attrList.
+                *      
+                *      http://www.xfree86.org/4.4.0/glXChooseVisual.3.html
+                */
+                  
+               int[] attrlist = {
+               (int)GtkGL._GDK_GL_CONFIGS.Rgba,
+               (int)GtkGL._GDK_GL_CONFIGS.RedSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.GreenSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.BlueSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.DepthSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.Doublebuffer,
+               (int)GtkGL._GDK_GL_CONFIGS.None,
+               };      
+               
+               // This method is called "ReSizeGLScene" in the original lesson
+               void OnConfigure (object o, EventArgs e)
+               {
+                       if( glarea.MakeCurrent() == 0)
+                               return;
+                       
+                       int height = glarea.Allocation.Height,
+                               width  = glarea.Allocation.Width;
+                               
+                       Console.WriteLine("Width: {0}", width);
+                       Console.WriteLine("Height: {0}", height);
+                       
+                       
+                       if (height==0)                                          
                        // Prevent A Divide By Zero By
+                       {
+                               height=1;                                       
                                // Making Height Equal One
+                       }
+                               
+                       gl.glViewport (0, 0, width, height);
+                       
+                       gl.glMatrixMode(gl.GL_PROJECTION);                      
        // Select The Projection Matrix
+                       gl.glLoadIdentity();                                    
                // Reset The Projection Matrix
+
+                       // Calculate The Aspect Ratio Of The Window
+                       
glu.gluPerspective(45.0f,(float)width/(float)height,0.1f,100.0f);
+
+                       gl.glMatrixMode(gl.GL_MODELVIEW);                       
        // Select The Modelview Matrix
+                       gl.glLoadIdentity();            
+               }
+
+               bool InitGL()
+               {
+                       if (glarea.MakeCurrent() == 0)
+                               return false;
+
+                       gl.glShadeModel(gl.GL_SMOOTH);                          
                // Enables Smooth Shading
+                       gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
        // Black Background
+                       gl.glClearDepth(1.0f);                                  
                        // Depth Buffer Setup
+                       gl.glEnable(gl.GL_DEPTH_TEST);                          
                // Enables Depth Testing
+                       gl.glDepthFunc(gl.GL_LEQUAL);                           
                // The Type Of Depth Test To Do
+                       // Really Nice Perspective Calculations
+                       gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, 
gl.GL_NICEST);     
+                       
+                       return true;
+               }
+               
+               // The correct time to init the gl window is at Realize time
+               void OnRealized (object o, EventArgs e)
+               {
+                       if(!InitGL())
+                               Console.WriteLine("Couldn't InitGL()");
+               }
+
+               // This method is called "DrawGLScene" in the original lesson   
        
+               void OnExposed (object o, EventArgs e)
+               {
+               
+                       if (glarea.MakeCurrent() == 0)
+                               return;
+
+                       Console.WriteLine("Exposed!");
+                       
+                       // Clear The Screen And The Depth Buffer
+                       gl.glClear(gl.GL_COLOR_BUFFER_BIT | 
gl.GL_DEPTH_BUFFER_BIT);
+                       gl.glLoadIdentity();                                    
                // Reset The Current Modelview Matrix
+                       
+                       gl.glTranslatef(-1.5f,0.0f,-6.0f);                      
        // Move Left 1.5 Units And Into The Screen 6.0
+                       
+                       gl.glBegin(gl.GL_TRIANGLES);                            
        // Drawing Using Triangles
+                               gl.glVertex3f( 0.0f, 1.0f, 0.0f);               
        // Top
+                               gl.glVertex3f(-1.0f,-1.0f, 0.0f);               
        // Bottom Left
+                               gl.glVertex3f( 1.0f,-1.0f, 0.0f);               
        // Bottom Right
+                       gl.glEnd();                                             
                                // Finished Drawing The Triangle
+                       
+                       gl.glTranslatef(3.0f,0.0f,0.0f);                        
        // Move Right 3 Units
+                       
+                       gl.glBegin(gl.GL_QUADS);                                
                // Draw A Quad
+                               gl.glVertex3f(-1.0f, 1.0f, 0.0f);               
        // Top Left
+                               gl.glVertex3f( 1.0f, 1.0f, 0.0f);               
        // Top Right
+                               gl.glVertex3f( 1.0f,-1.0f, 0.0f);               
        // Bottom Right
+                               gl.glVertex3f(-1.0f,-1.0f, 0.0f);               
        // Bottom Left
+                       gl.glEnd();                                             
                                // Done Drawing The Quad
+                       
+                       glarea.SwapBuffers ();                                  
                // Show the newly displayed contents
+               }
+
+               public static int Main (string[] argc)
+               {
+                       Gtk.Application.Init ();
+
+                       Lesson02 l = new Lesson02();
+
+                       // Go, dog, go!
+                       Gtk.Application.Run ();
+
+                       return 1;
+               }               
+
+               public Lesson02()
+               {
+                       // Create a new GLArea widget and request a size
+                       glarea = new GLArea (attrlist);
+                       glarea.SetSizeRequest (300, 300);
+                       
+                       // Set some event handlers
+                       glarea.ExposeEvent += OnExposed;
+                       glarea.Realized += OnRealized;
+                       glarea.Unrealized += OnUnrealized;
+                       glarea.ConfigureEvent += OnConfigure;
+                                               
+                       // Create a new Vertical Box that the GLArea can live in
+                       VBox vb = new VBox (false, 0);
+                       
+                       // Pack the GLArea widget into the VBox
+                       vb.PackStart (glarea, true, true, 0);
+                       
+                       // Create a new window and name it appropriately
+                       Window win = new Window ("NeHe Lesson02");
+                       
+                       // Pack the VBox into the window
+                       win.Add (vb);
+
+                       // Show all of win's contained widgets
+                       win.ShowAll ();
+               }
+                               
+
+               
+               void OnUnrealized (object o, EventArgs e)
+               {
+                       Application.Quit();
+               }
+               
+
+       }
+}

Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Makefile.am
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Makefile.am    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson02/Makefile.am    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,15 @@
+SRCS = Lesson02.cs
+
+CLEANFILES = Lesson02.exe
+
+all: Lesson02.exe
+
+Lesson02.exe: $(SRCS)
+       mcs \
+               -pkg:gtk-sharp-2.0 \
+               -pkg:gtkgl-sharp-2.0 \
+               -pkg:tao \
+               $(SRCS) \
+               -out:Lesson02.exe
+
+

Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Lesson03.cs
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Lesson03.cs    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Lesson03.cs    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,185 @@
+// created on 12/13/2005 at 1:51 PM
+using System;
+using Gtk;
+using GtkSharp;
+
+using GtkGL;
+
+using Tao.OpenGl;
+
+using gl=Tao.OpenGl.Gl;
+using glu=Tao.OpenGl.Glu;
+
+// This code is based on work from Alp Toker and the NeHe lesson here:
+// http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
+namespace NeHe.Lesson03
+{
+       public class Lesson03
+       {
+               /* GlArea is the widget defined in the GtkGL namespace and is a
+                * specialized GtkDrawingArea with GL cow powers.
+                */
+               
+               GLArea glarea;
+               
+               /*      attrList
+            *      Specifies a list of Boolean attributes and enum/integer
+                *      attribute/value pairs. The last attribute must be zero 
or
+                *      _GDK_GL_CONFIGS.None.
+                *      
+                *      See glXChooseVisual man page for explanation of
+                *      attrList.
+                *      
+                *      http://www.xfree86.org/4.4.0/glXChooseVisual.3.html
+                */
+                  
+               int[] attrlist = {
+               (int)GtkGL._GDK_GL_CONFIGS.Rgba,
+               (int)GtkGL._GDK_GL_CONFIGS.RedSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.GreenSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.BlueSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.DepthSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.Doublebuffer,
+               (int)GtkGL._GDK_GL_CONFIGS.None,
+               };
+               
+               // This method is called "ReSizeGLScene" in the original lesson
+               void OnConfigure (object o, EventArgs e)
+               {
+                       if( glarea.MakeCurrent() == 0)
+                               return;
+                       
+                       int height = glarea.Allocation.Height,
+                               width  = glarea.Allocation.Width;
+                               
+                       Console.WriteLine("Width: {0}", width);
+                       Console.WriteLine("Height: {0}", height);
+                       
+                       
+                       if (height==0)                                          
                        // Prevent A Divide By Zero By
+                       {
+                               height=1;                                       
                                // Making Height Equal One
+                       }
+                               
+                       gl.glViewport (0, 0, width, height);
+                       
+                       gl.glMatrixMode(gl.GL_PROJECTION);                      
        // Select The Projection Matrix
+                       gl.glLoadIdentity();                                    
                // Reset The Projection Matrix
+
+                       // Calculate The Aspect Ratio Of The Window
+                       
glu.gluPerspective(45.0f,(float)width/(float)height,0.1f,100.0f);
+
+                       gl.glMatrixMode(gl.GL_MODELVIEW);                       
        // Select The Modelview Matrix
+                       gl.glLoadIdentity();            
+               }
+
+               bool InitGL()
+               {
+                       if (glarea.MakeCurrent() == 0)
+                               return false;
+
+                       gl.glShadeModel(gl.GL_SMOOTH);                          
                // Enables Smooth Shading
+                       gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
        // Black Background
+                       gl.glClearDepth(1.0f);                                  
                        // Depth Buffer Setup
+                       gl.glEnable(gl.GL_DEPTH_TEST);                          
                // Enables Depth Testing
+                       gl.glDepthFunc(gl.GL_LEQUAL);                           
                // The Type Of Depth Test To Do
+                       // Really Nice Perspective Calculations
+                       gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, 
gl.GL_NICEST);     
+                       
+                       return true;
+               }
+               
+               // The correct time to init the gl window is at Realize time
+               void OnRealized (object o, EventArgs e)
+               {
+                       if(!InitGL())
+                               Console.WriteLine("Couldn't InitGL()");
+               }
+
+               // This method is called "DrawGLScene" in the original lesson   
        
+               void OnExposed (object o, EventArgs e)
+               {
+               
+                       if (glarea.MakeCurrent() == 0)
+                               return;
+
+                       Console.WriteLine("Exposed!");
+                       
+                       // Clear The Screen And The Depth Buffer
+                       gl.glClear(gl.GL_COLOR_BUFFER_BIT | 
gl.GL_DEPTH_BUFFER_BIT);
+                       gl.glLoadIdentity();                                    
                // Reset The Current Modelview Matrix
+                       
+                       gl.glTranslatef(-1.5f,0.0f,-6.0f);                      
        // Move Left 1.5 Units And Into The Screen 6.0
+                       
+                       gl.glBegin(gl.GL_TRIANGLES);                            
        // Drawing Using Triangles
+                               gl.glColor3f(1.0f,0.0f,0.0f);                   
        // Set The Color To Red
+                               gl.glVertex3f( 0.0f, 1.0f, 0.0f);               
        // Top
+                               gl.glColor3f(0.0f,1.0f,0.0f);                   
        // Set The Color To Green
+                               gl.glVertex3f(-1.0f,-1.0f, 0.0f);               
        // Bottom Left
+                               gl.glColor3f(0.0f,0.0f,1.0f);                   
        // Set The Color To Blue                                
+                               gl.glVertex3f( 1.0f,-1.0f, 0.0f);               
        // Bottom Right
+                       gl.glEnd();                                             
                                // Finished Drawing The Triangle
+                       
+                       gl.glTranslatef(3.0f,0.0f,0.0f);                        
        // Move Right 3 Units
+                       
+                       gl.glColor3f(0.5f,0.5f,1.0f);                           
        // Set The Color To Blue One Time Only
+                       gl.glBegin(gl.GL_QUADS);                                
                // Draw A Quad
+                               gl.glVertex3f(-1.0f, 1.0f, 0.0f);               
        // Top Left
+                               gl.glVertex3f( 1.0f, 1.0f, 0.0f);               
        // Top Right
+                               gl.glVertex3f( 1.0f,-1.0f, 0.0f);               
        // Bottom Right
+                               gl.glVertex3f(-1.0f,-1.0f, 0.0f);               
        // Bottom Left
+                       gl.glEnd();                                             
                                // Done Drawing The Quad
+                       
+                       glarea.SwapBuffers ();                                  
                // Show the newly displayed contents
+               }
+
+               public static int Main (string[] argc)
+               {
+                       Gtk.Application.Init ();
+
+                       Lesson03 l = new Lesson03();
+
+                       // Go, dog, go!
+                       Gtk.Application.Run ();
+
+                       return 1;
+               }               
+
+               public Lesson03()
+               {
+                       // Create a new GLArea widget and request a size
+                       glarea = new GLArea (attrlist);
+                       glarea.SetSizeRequest (300, 300);
+                       
+                       // Set some event handlers
+                       glarea.ExposeEvent += OnExposed;
+                       glarea.Realized += OnRealized;
+                       glarea.Unrealized += OnUnrealized;
+                       glarea.ConfigureEvent += OnConfigure;
+                                               
+                       // Create a new Vertical Box that the GLArea can live in
+                       VBox vb = new VBox (false, 0);
+                       
+                       // Pack the GLArea widget into the VBox
+                       vb.PackStart (glarea, true, true, 0);
+                       
+                       // Create a new window and name it appropriately
+                       Window win = new Window ("NeHe Lesson03");
+                       
+                       // Pack the VBox into the window
+                       win.Add (vb);
+
+                       // Show all of win's contained widgets
+                       win.ShowAll ();
+               }
+                               
+
+               
+               void OnUnrealized (object o, EventArgs e)
+               {
+                       Application.Quit();
+               }
+               
+
+       }
+}

Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Makefile.am
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Makefile.am    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson03/Makefile.am    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,15 @@
+SRCS = Lesson03.cs
+
+CLEANFILES = Lesson03.exe
+
+all: Lesson03.exe
+
+Lesson03.exe: $(SRCS)
+       mcs \
+               -pkg:gtk-sharp-2.0 \
+               -pkg:gtkgl-sharp-2.0 \
+               -pkg:tao \
+               $(SRCS) \
+               -out:Lesson03.exe
+
+

Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Lesson04.cs
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Lesson04.cs    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Lesson04.cs    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,209 @@
+// created on 12/13/2005 at 1:51 PM
+using System;
+using System.Timers;
+
+using Gtk;
+using GtkSharp;
+
+using GtkGL;
+
+using Tao.OpenGl;
+
+using gl=Tao.OpenGl.Gl;
+using glu=Tao.OpenGl.Glu;
+
+// This code is based on work from Alp Toker and the NeHe lesson here:
+// http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
+namespace NeHe.Lesson03
+{
+       public class Lesson03
+       {
+               /* GlArea is the widget defined in the GtkGL namespace and is a
+                * specialized GtkDrawingArea with GL cow powers.
+                */
+               
+               GLArea glarea;
+               
+               /*      attrList
+            *      Specifies a list of Boolean attributes and enum/integer
+                *      attribute/value pairs. The last attribute must be zero 
or
+                *      _GDK_GL_CONFIGS.None.
+                *      
+                *      See glXChooseVisual man page for explanation of
+                *      attrList.
+                *      
+                *      http://www.xfree86.org/4.4.0/glXChooseVisual.3.html
+                */
+                  
+               int[] attrlist = {
+               (int)GtkGL._GDK_GL_CONFIGS.Rgba,
+               (int)GtkGL._GDK_GL_CONFIGS.RedSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.GreenSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.BlueSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.DepthSize,1,
+               (int)GtkGL._GDK_GL_CONFIGS.Doublebuffer,
+               (int)GtkGL._GDK_GL_CONFIGS.None,
+               };      
+               
+               float           rtri;                                           
// Angle For The Triangle (NEW)
+               float           rquad;                                          
// Angle For The Quad (NEW)
+               
+               // This method is called "ReSizeGLScene" in the original lesson
+               void OnConfigure (object o, EventArgs e)
+               {
+                       if( glarea.MakeCurrent() == 0)
+                               return;
+                       
+                       int height = glarea.Allocation.Height,
+                               width  = glarea.Allocation.Width;
+                               
+                       Console.WriteLine("Width: {0}", width);
+                       Console.WriteLine("Height: {0}", height);
+                       
+                       
+                       if (height==0)                                          
                        // Prevent A Divide By Zero By
+                       {
+                               height=1;                                       
                                // Making Height Equal One
+                       }
+                               
+                       gl.glViewport (0, 0, width, height);
+                       
+                       gl.glMatrixMode(gl.GL_PROJECTION);                      
        // Select The Projection Matrix
+                       gl.glLoadIdentity();                                    
                // Reset The Projection Matrix
+
+                       // Calculate The Aspect Ratio Of The Window
+                       
glu.gluPerspective(45.0f,(float)width/(float)height,0.1f,100.0f);
+
+                       gl.glMatrixMode(gl.GL_MODELVIEW);                       
        // Select The Modelview Matrix
+                       gl.glLoadIdentity();            
+               }
+
+               bool InitGL()
+               {
+                       if (glarea.MakeCurrent() == 0)
+                               return false;
+
+                       gl.glShadeModel(gl.GL_SMOOTH);                          
                // Enables Smooth Shading
+                       gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
        // Black Background
+                       gl.glClearDepth(1.0f);                                  
                        // Depth Buffer Setup
+                       gl.glEnable(gl.GL_DEPTH_TEST);                          
                // Enables Depth Testing
+                       gl.glDepthFunc(gl.GL_LEQUAL);                           
                // The Type Of Depth Test To Do
+                       // Really Nice Perspective Calculations
+                       gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, 
gl.GL_NICEST);     
+                       
+                       return true;
+               }
+               
+               // The correct time to init the gl window is at Realize time
+               void OnRealized (object o, EventArgs e)
+               {
+                       if(!InitGL())
+                               Console.WriteLine("Couldn't InitGL()");
+               }
+
+               // This method is called "DrawGLScene" in the original lesson   
        
+               void OnExposed (object o, EventArgs e)
+               {
+               
+                       if (glarea.MakeCurrent() == 0)
+                               return;
+                       
+                       // Clear The Screen And The Depth Buffer
+                       gl.glClear(gl.GL_COLOR_BUFFER_BIT | 
gl.GL_DEPTH_BUFFER_BIT);
+                       gl.glLoadIdentity();                                    
                // Reset The Current Modelview Matrix
+                       
+                       gl.glTranslatef(-1.5f,0.0f,-6.0f);                      
        // Move Left 1.5 Units And Into The Screen 6.0
+                       
+                       gl.glRotatef(rtri,0.0f,1.0f,0.0f);                      
        // Rotate The Triangle On The Y axis (NEW)
+                       
+                       gl.glBegin(gl.GL_TRIANGLES);                            
        // Drawing Using Triangles
+                               gl.glColor3f(1.0f,0.0f,0.0f);                   
        // Set The Color To Red
+                               gl.glVertex3f( 0.0f, 1.0f, 0.0f);               
        // Top
+                               gl.glColor3f(0.0f,1.0f,0.0f);                   
        // Set The Color To Green
+                               gl.glVertex3f(-1.0f,-1.0f, 0.0f);               
        // Bottom Left
+                               gl.glColor3f(0.0f,0.0f,1.0f);                   
        // Set The Color To Blue                                
+                               gl.glVertex3f( 1.0f,-1.0f, 0.0f);               
        // Bottom Right
+                       gl.glEnd();                                             
                                // Finished Drawing The Triangle
+                       
+                       gl.glLoadIdentity();                                    
                        // If this didn't happen, weird rotation happens
+                       gl.glTranslatef(1.5f,0.0f,-6.0f);                       
        // Move Right 1.5 Units And Into The Screen 6.0
+                       gl.glRotatef(rquad,1.0f,0.0f,0.0f);                     
        // Rotate The Quad On The X axis ( NEW )
+                       
+                       gl.glColor3f(0.5f,0.5f,1.0f);                           
        // Set The Color To Blue One Time Only
+                       gl.glBegin(gl.GL_QUADS);                                
                // Draw A Quad
+                               gl.glVertex3f(-1.0f, 1.0f, 0.0f);               
        // Top Left
+                               gl.glVertex3f( 1.0f, 1.0f, 0.0f);               
        // Top Right
+                               gl.glVertex3f( 1.0f,-1.0f, 0.0f);               
        // Bottom Right
+                               gl.glVertex3f(-1.0f,-1.0f, 0.0f);               
        // Bottom Left
+                       gl.glEnd();                                             
                                // Done Drawing The Quad
+                       
+                       glarea.SwapBuffers ();                                  
                // Show the newly displayed contents
+               }
+
+               public static int Main (string[] argc)
+               {
+                       Gtk.Application.Init ();
+                       
+                       System.Timers.Timer t = new System.Timers.Timer();
+                       
+                       Lesson03 l = new Lesson03();
+                       
+                       GLib.Timeout.Add (50, new GLib.TimeoutHandler 
(l.RotateObjects));
+
+                       // Go, dog, go!
+                       Gtk.Application.Run ();
+
+                       return 1;
+               }
+               
+               private bool RotateObjects()
+               {
+                       rtri = (rtri % 360) + 1.0f;
+                       rquad = (rquad % 360) + 0.8f;
+                       
+                       if( glarea.MakeCurrent() == 0)
+                               return true;
+                       
+                       glarea.QueueDraw();
+                       
+                       return true;
+               }
+
+               public Lesson03()
+               {
+                       // Create a new GLArea widget and request a size
+                       glarea = new GLArea (attrlist);
+                       glarea.SetSizeRequest (300, 300);
+                       
+                       // Set some event handlers
+                       glarea.ExposeEvent += OnExposed;
+                       glarea.Realized += OnRealized;
+                       glarea.Unrealized += OnUnrealized;
+                       glarea.ConfigureEvent += OnConfigure;
+                                               
+                       // Create a new Vertical Box that the GLArea can live in
+                       VBox vb = new VBox (false, 0);
+                       
+                       // Pack the GLArea widget into the VBox
+                       vb.PackStart (glarea, true, true, 0);
+                       
+                       // Create a new window and name it appropriately
+                       Window win = new Window ("NeHe Lesson03");
+                       
+                       // Pack the VBox into the window
+                       win.Add (vb);
+
+                       // Show all of win's contained widgets
+                       win.ShowAll ();
+               }
+                               
+
+               
+               void OnUnrealized (object o, EventArgs e)
+               {
+                       Application.Quit();
+               }
+               
+
+       }
+}

Added: trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Makefile.am
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Makefile.am    2005-12-14 
01:15:21 UTC (rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Lesson04/Makefile.am    2005-12-14 
01:27:59 UTC (rev 54337)
@@ -0,0 +1,15 @@
+SRCS = Lesson04.cs
+
+CLEANFILES = Lesson04.exe
+
+all: Lesson04.exe
+
+Lesson04.exe: $(SRCS)
+       mcs \
+               -pkg:gtk-sharp-2.0 \
+               -pkg:gtkgl-sharp-2.0 \
+               -pkg:tao \
+               $(SRCS) \
+               -out:Lesson04.exe
+
+

Added: trunk/gtkglarea-sharp/examples/NeHe/Makefile.am
===================================================================
--- trunk/gtkglarea-sharp/examples/NeHe/Makefile.am     2005-12-14 01:15:21 UTC 
(rev 54336)
+++ trunk/gtkglarea-sharp/examples/NeHe/Makefile.am     2005-12-14 01:27:59 UTC 
(rev 54337)
@@ -0,0 +1,5 @@
+SUBDIRS = \
+       Lesson01 \
+       Lesson02 \
+       Lesson03 \
+       Lesson04

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to