www.pudn.com > CSharp_OpenGL_Material.rar > Form1.cs, change:2009-06-16,size:4256b
// CSharp_OpenGL_Material
// [ IceSharK - PP.Poet ]
// 2004.10.6
using System.Windows.Forms;
using CsGL.OpenGL; // 引用 CsGL.OpenGL 名字空间
namespace CSharp_OpenGL_Material
{
internal class Form1 : System.Windows.Forms.Form
{
#region Windows 窗体设计器生成的代码
internal Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem_Light0;
private System.Windows.Forms.MenuItem menuItem_Rotate;
private System.Windows.Forms.MenuItem menuItem_Specular;
private System.ComponentModel.IContainer components = null;
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem_Specular = new System.Windows.Forms.MenuItem();
this.menuItem_Light0 = new System.Windows.Forms.MenuItem();
this.menuItem_Rotate = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem_Specular,
this.menuItem_Light0,
this.menuItem_Rotate});
//
// menuItem_Specular
//
this.menuItem_Specular.Index = 0;
this.menuItem_Specular.Text = "还原 镜面反射";
this.menuItem_Specular.Click += new System.EventHandler(this.menuItem_Specular_Click);
//
// menuItem_Light0
//
this.menuItem_Light0.Index = 1;
this.menuItem_Light0.Text = "禁用 0号光源";
this.menuItem_Light0.Click += new System.EventHandler(this.menuItem_Light0_Click);
//
// menuItem_Rotate
//
this.menuItem_Rotate.Index = 2;
this.menuItem_Rotate.Text = "停止 旋转";
this.menuItem_Rotate.Click += new System.EventHandler(this.menuItem_Rotate_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(1008, 711);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "CSharp_OpenGL_Material";
this.Closed += new System.EventHandler(this.Form1_Closed);
}
#endregion
private bool IsSpecular = true;
private float[] Teapot_Specular;
private void menuItem_Specular_Click(object sender, System.EventArgs e)
{
if( IsSpecular )
{
IsSpecular = false;
Teapot_Specular = new float[]{ 0.0f , 0.0f , 0.0f , 1.0f };
GL.glMaterialfv( GL.GL_FRONT , GL.GL_SPECULAR , Teapot_Specular );
menuItem_Specular.Text = "设置 镜面反射";
this.Refresh();
}
else
{
IsSpecular = true;
Teapot_Specular = new float[]{ 1.0f , 1.0f , 1.0f , 1.0f };
GL.glMaterialfv( GL.GL_FRONT , GL.GL_SPECULAR , Teapot_Specular );
menuItem_Specular.Text = "还原 镜面反射";
this.Refresh();
}
}
private void menuItem_Light0_Click(object sender, System.EventArgs e)
{
if( GL.glIsEnabled( GL.GL_LIGHT0 ) == (int)GL.GL_TRUE )
{
menuItem_Light0.Text = "启用 0号光源";
GL.glDisable( GL.GL_LIGHT0 );
menuItem_Specular.Enabled = false;
this.Refresh();
}
else
{
menuItem_Light0.Text = "禁用 0号光源";
GL.glEnable( GL.GL_LIGHT0 );
menuItem_Specular.Enabled = true;
this.Refresh();
}
}
internal bool IsFinished = false; // 绘制是否结束
private void menuItem_Rotate_Click(object sender, System.EventArgs e)
{
if( IsFinished == true )
{
menuItem_Rotate.Text = "停止 旋转";
IsFinished = false;
}
else
{
menuItem_Rotate.Text = "开始 旋转";
IsFinished = true;
}
}
private void Form1_Closed( object sender , System.EventArgs e )
{
Application.Exit(); // Form1关闭后 程序退出
}
}
}