From: Tim R. <ti...@us...> - 2004-07-28 16:31:06
|
Update of /cvsroot/csdopenglnet/csdOpenGL/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10022/samples Modified Files: Makefile Added Files: Makefile.gtk gtkTexture.cs gtkTriangle.cs Log Message: new examples --- NEW FILE: gtkTriangle.cs --- using csDragons.OpenGL; using GLib; using Gtk; using GtkSharp; using System; using System.Diagnostics; public class GtkTest : csdGL { GtkGLArea glarea; bool stop; float angle = 0.0f; public GtkTest() { Debug.Indent(); Debug.WriteLine( "Enering GtkTest()" ); Debug.WriteLine( "Init Application" ); Application.Init(); Debug.WriteLine( "Init Window" ); Gtk.Window window = new Gtk.Window( "Gtk Triangle" ); window.ReallocateRedraws = true; window.DeleteEvent += new DeleteEventHandler( OnDeleteEvent ); Debug.WriteLine( "Init GtkGLArea" ); glarea = new GtkGLArea(); glarea.Realized += new EventHandler (OnRealized); glarea.ConfigureEvent += new ConfigureEventHandler (OnConfigure); glarea.ExposeEvent += new ExposeEventHandler (OnExpose); glarea.MapEvent += new MapEventHandler (OnMap); glarea.UnmapEvent += new UnmapEventHandler (OnUnmap); Table table = new Table( 10, 20, true ); table.Attach( glarea, 1, 19, 1, 9 ); window.Add( table ); glarea.Show (); window.ShowAll (); Debug.WriteLine( "MainLoop" ); Application.Run (); Debug.WriteLine( "Exiting GtkTest()" ); Debug.Unindent(); } protected void OnDeleteEvent (object obj, DeleteEventArgs args) { Application.Quit (); } protected void OnMap (object obj, MapEventArgs args) { GLib.Idle.Add (new IdleHandler (Animate)); stop = false; } protected void OnUnmap (object obj, UnmapEventArgs args) { stop = true; } protected bool Animate () { angle += 0.2f; glarea.QueueDraw (); return !stop; } protected void OnExpose (object obj, ExposeEventArgs args) { if (glarea.MakeCurrent()) { glClearColor( 0, 0, 0, 0 ); glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix(); glRotatef( angle, 0.0f, 0.0f, 1.0f ); glTranslatef( -0.5f, -0.5f, 0.0f ); triangle(); glPopMatrix(); glarea.SwapBuffers(); } } protected void triangle() { glBegin( GL_TRIANGLES ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 0.0f); glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.5f, 1.0f); glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( 1.0f, 0.0f); glEnd(); } protected void OnConfigure (object obj, ConfigureEventArgs args) { if (glarea.MakeCurrent()) { glViewport(0, 0, glarea.Allocation.Width, glarea.Allocation.Height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); float h = (float) glarea.Allocation.Height / (float) (glarea.Allocation.Width); glFrustum( -1.0f, 1.0f, -h, h, 5.0f, 5.0f ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); //glTranslatef( 0.0f, 0.0f, -40.0f); glEnd(); } } protected void OnRealized (object obj, EventArgs args) { glShadeModel( GL_SMOOTH ); glClearColor( 0.0f, 0.0f, 0.0f, 0.5f ); glClearDepth( 1.0f ); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); } public static void Main( string[] args) { Debug.Listeners.Add( new TextWriterTraceListener( Console.Out ) ); Debug.AutoFlush = true; GtkTest gl = new GtkTest(); } } Index: Makefile =================================================================== RCS file: /cvsroot/csdopenglnet/csdOpenGL/samples/Makefile,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile 18 Jul 2004 20:41:52 -0000 1.4 --- Makefile 28 Jul 2004 16:30:50 -0000 1.5 *************** *** 1,3 **** - FILES=generator.cs AssemblyInfo.cs define.cs typedef.cs function.cs CC=mcs DEBUG=/d:DEBUG --- 1,2 ---- *************** *** 10,21 **** LIBOPTS=$(foreach lib,$(LIBS),-r $(lib)) ! all: $(LIBS) triangle.exe texture.exe gtkWidget.exe gears.exe gtkGears.exe csdGL.dll: libcsdGL.so ln -sf ../generator/csdGL.dll . - csdGL_Gtk.dll: libcsdGL.so - ln -sf ../generator/csdGL_Gtk.dll . - csdMath.dll: ln -sf ../math/csdMath.dll --- 9,18 ---- LIBOPTS=$(foreach lib,$(LIBS),-r $(lib)) ! all: $(LIBS) triangle.exe texture.exe gears.exe ! $(MAKE) -f Makefile.gtk csdGL.dll: libcsdGL.so ln -sf ../generator/csdGL.dll . csdMath.dll: ln -sf ../math/csdMath.dll *************** *** 27,36 **** ln -sf ../cbonding/libcsdGL.so . - gtkWidget.exe:gtkWidget.cs csdGL_Gtk.dll - $(MCS) -r:glib-sharp.dll -r:gtk-sharp.dll -r:csdGL_Gtk.dll -r:System.Drawing gtkWidget.cs -o $@ - - gtkGears.exe:gtkGears.cs csdGL_Gtk.dll - $(MCS) -r:glib-sharp.dll -r:gtk-sharp.dll -r:csdGL_Gtk.dll -r:System.Drawing gtkGears.cs -o $@ - %.exe:%.cs $(MCS) -r:csdGL.dll -r:csdGLtools.dll -r:csdMath.dll -r:System.Drawing $^ -o $@ --- 24,27 ---- *************** *** 38,41 **** --- 29,33 ---- clean: + $(MAKE) -f Makefile.gtk clean rm -f *.exe rm -f *.dll --- NEW FILE: gtkTexture.cs --- using csDragons.OpenGL; using GLib; using Gtk; using GtkSharp; using System; using System.Diagnostics; public class GtkTest : csdGL { protected GtkGLArea glarea; protected ByteTexture2D tex1; protected uint tex1Id = 0; protected bool stop = false; public GtkTest() { Debug.Indent(); Debug.WriteLine( "Enering GtkTest()" ); Debug.WriteLine( "Init Application" ); Application.Init(); Debug.WriteLine( "Init Window" ); Gtk.Window window = new Gtk.Window( "Gtk Triangle" ); window.Resize( 480, 480 ); window.ReallocateRedraws = true; window.DeleteEvent += new DeleteEventHandler( OnDeleteEvent ); Debug.WriteLine( "Init GtkGLArea" ); glarea = new GtkGLArea(); glarea.Realized += new EventHandler (OnRealized); glarea.ConfigureEvent += new ConfigureEventHandler (OnConfigure); glarea.ExposeEvent += new ExposeEventHandler (OnExpose); glarea.MapEvent += new MapEventHandler (OnMap); glarea.UnmapEvent += new UnmapEventHandler (OnUnmap); Table table = new Table( 10, 20, true ); table.Attach( glarea, 1, 19, 1, 9 ); window.Add( table ); glarea.Show (); window.ShowAll (); Debug.WriteLine( "MainLoop" ); Application.Run (); Debug.WriteLine( "Exiting GtkTest()" ); Debug.Unindent(); } protected void OnDeleteEvent (object obj, DeleteEventArgs args) { Application.Quit (); } protected void OnMap (object obj, MapEventArgs args) { GLib.Idle.Add (new IdleHandler (Animate)); stop = false; } protected void OnUnmap (object obj, UnmapEventArgs args) { stop = true; } protected bool Animate () { glarea.QueueDraw (); return !stop; } protected void quad() { glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, tex1Id ); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glEnd(); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f( 2.5f, 0.0f, 0.0f ); glEnd(); glBegin(GL_LINES); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f( 2.5f, 0.0f, 0.0f ); glEnd(); glBegin(GL_LINES); glColor3f( 0.0f, 1.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f ); glColor3f( 0.0f, 1.0f, 0.0f ); glVertex3f( 0.0f, 2.5f, 0.0f ); glEnd(); glBegin(GL_LINES); glColor3f( 0.0f, 0.0f, 1.0f ); glVertex3f( 0.0f, 0.0f, 0.0f ); glColor3f( 0.0f, 0.0f, 1.0f ); glVertex3f( 0.0f, 0.0f, 2.5f ); glEnd(); } protected void OnExpose (object obj, ExposeEventArgs args) { if (glarea.MakeCurrent()) { glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix(); quad(); glPopMatrix(); glarea.SwapBuffers(); } } protected void OnConfigure (object obj, ConfigureEventArgs args) { if (glarea.MakeCurrent()) { float h = (float) glarea.Allocation.Height / (float) (glarea.Allocation.Width); glViewport(0, 0, glarea.Allocation.Width, glarea.Allocation.Height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( (double)45.0f, (double)h, (double)0.1f, (double)1000.0f ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( 0.5, 0.5, 5.0, // Eye 0.0, 0.0, 0.0, // Center 0.0, 1.0, 0.0 ); // Up } } protected void OnRealized (object obj, EventArgs args) { if (glarea.MakeCurrent()) { glShadeModel( GL_SMOOTH ); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClearDepth( 1.0f ); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); tex1 = new ByteTexture2D( "image1.png" ); uint[] i = new uint[1]; glGenTextures( 1, i ); tex1Id = i[0]; glBindTexture( GL_TEXTURE_2D, tex1Id ); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, tex1.Bits, tex1.Width, tex1.Height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex1.Texture); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glEnable(GL_TEXTURE_2D); glShadeModel(GL_FLAT); } } public static void Main( string[] args) { Debug.Listeners.Add( new TextWriterTraceListener( Console.Out ) ); Debug.AutoFlush = true; GtkTest gl = new GtkTest(); } } --- NEW FILE: Makefile.gtk --- CC=mcs DEBUG=/d:DEBUG DEBUG= OPTS=$(DEBUG) LIBS=csdGL_Gtk.dll csdMath.dll csdGLtools.dll MCS=$(CC) $(OPTS) -lib:/usr/lib/mono/gtk-sharp PACKAGE=csDragons LIBOPTS=$(foreach lib,$(LIBS),-r $(lib)) all: $(LIBS) gtkTriangle.exe gtkGears.exe gtkTexture.exe csdGL_Gtk.dll: libcsdGL.so ln -sf ../generator/csdGL_Gtk.dll . csdMath.dll: ln -sf ../math/csdMath.dll csdGLtools.dll: ln -sf ../tools/csdGLtools.dll libcsdGL.so: ln -sf ../cbonding/libcsdGL.so . %.exe:%.cs $(MCS) -r:glib-sharp.dll -r gtk-sharp.dll -r:csdGL_Gtk.dll -r:csdGLtools.dll -r:csdMath.dll -r:System.Drawing $^ -o $@ clean: rm -f *.exe rm -f *.dll rm -f *.so .IGNORE: clean .EXPORT_ALL_VARIABLES: .PHONY: clean |