Update of /cvsroot/csdopenglnet/csdOpenGL/samples
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11141
Modified Files:
Makefile.gtk
Added Files:
gtkFrame.cs
Log Message:
Base application for OpenGL+Gtk#-Examples
Index: Makefile.gtk
===================================================================
RCS file: /cvsroot/csdopenglnet/csdOpenGL/samples/Makefile.gtk,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile.gtk 28 Jul 2004 16:30:50 -0000 1.1
--- Makefile.gtk 30 Jul 2004 06:46:14 -0000 1.2
***************
*** 9,13 ****
LIBOPTS=$(foreach lib,$(LIBS),-r $(lib))
! all: $(LIBS) gtkTriangle.exe gtkGears.exe gtkTexture.exe
csdGL_Gtk.dll: libcsdGL.so
--- 9,13 ----
LIBOPTS=$(foreach lib,$(LIBS),-r $(lib))
! all: $(LIBS) gtkTriangle.exe gtkGears.exe gtkTexture.exe gtkFrame.exe
csdGL_Gtk.dll: libcsdGL.so
--- NEW FILE: gtkFrame.cs ---
using csDragons.OpenGL;
using GLib;
using Gtk;
using GtkSharp;
using System;
using System.Diagnostics;
public class GtkFrame : csdGL {
protected GtkGLArea glarea;
protected bool propStop = false;
protected bool propMapped = false;
protected float rotX = 0.0f;
protected float rotY = 0.0f;
protected float rotZ = 0.0f;
protected Fixed fixedLayout;
public GtkFrame() {
Debug.Indent();
Debug.WriteLine( "Enering GtkFrame()" );
Debug.WriteLine( "Init Application" );
Application.Init();
Debug.WriteLine( "Init Window" );
Gtk.Window window = new Gtk.Window( "Gtk Frame" );
window.ReallocateRedraws = true;
window.DeleteEvent += new DeleteEventHandler( OnDeleteEvent );
window.Resize( 640, 480 );
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);
fixedLayout = new Fixed();
fixedLayout.Put( glarea, 50, 50 );
glarea.HeightRequest = 200;
glarea.WidthRequest = 200;
fixedLayout.Show();
window.Add( fixedLayout );
glarea.Show ();
window.ShowAll ();
Debug.WriteLine( "MainLoop" );
Application.Run ();
Debug.WriteLine( "Exiting GtkFrame()" );
Debug.Unindent();
}
protected void OnDeleteEvent (object obj, DeleteEventArgs args) {
Application.Quit ();
}
protected void OnMap (object obj, MapEventArgs args) {
glMapped = false;
}
protected void OnUnmap (object obj, UnmapEventArgs args) {
glMapped = true;
}
protected virtual bool Animate () {
rotX += 1.0f;
rotY += 0.5f;
rotZ += 0.1f;
glarea.QueueDraw ();
return !stop;
}
protected virtual 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( rotX, 1.0f, 0.0f, 0.0f );
glRotatef( rotY, 0.0f, 1.0f, 0.0f );
glRotatef( rotZ, 0.0f, 0.0f, 1.0f );
glTranslatef( -0.5f, -0.5f, 0.0f );
draw();
glPopMatrix();
glarea.SwapBuffers();
}
}
protected virtual void draw() {
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 virtual 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 );
}
protected bool stop {
get {
return propStop;
}
set {
propStop = value;
}
}
protected bool glMapped {
get {
return propMapped;
}
set {
propMapped = value;
if (!value) stop = true;
}
}
public static void Main( string[] args) {
Debug.Listeners.Add( new TextWriterTraceListener( Console.Out ) );
Debug.AutoFlush = true;
GtkFrame gl = new GtkFrame();
}
}
|