namespace sharpGLTest02 { public partial class Form1 : Form { private int mtype = 3; public Form1() { InitializeComponent(); } //初始化 private void openGLControl1_OpenGLInitialized(object sender, EventArgs e) { } //调整 private void openGLControl1_Resize(object sender, EventArgs e) { } //画图 private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e) { SharpGL.OpenGL gl = this.openGLControl1.OpenGL; gl.ClearColor(0, 0, 0, 1); //清除深度缓存 gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); switch (mtype) { case 0: translateSample(gl); break; case 1: rotateSample(gl); break; case 2: scaleSample(gl); break; case 3: originSample(gl); break; } gl.Finish(); gl.Flush(); //强制刷新 } private void originSample(SharpGL.OpenGL gl) { gl.LoadIdentity(); gl.Translate(0f, 0f, -1f); drawPT(gl); //gl.LoadIdentity(); //gl.Translate(0f, 1f, -1f); //drawPT(gl); } private void scaleSample(SharpGL.OpenGL gl) { gl.LoadIdentity(); //缩放 //gl.Scale(1f, 1f, 1f); gl.Scale(1f, 2f, 1f); gl.Translate(0, 0, -9f); drawPT(gl); gl.LoadIdentity(); gl.Scale(5f, 1f, 1f); //gl.Translate(0, 1, -9f); gl.Translate(0, 2, -9f); drawPT(gl); } private void rotateSample(SharpGL.OpenGL gl) { gl.LoadIdentity(); //旋转 gl.Rotate(0,0, 45); gl.Translate(0, 0, -3f); drawPT(gl); //gl.Rotate(0, 0, 45); //gl.Translate(-1, 1,0f); //drawPT(gl); } private void translateSample(SharpGL.OpenGL gl) { //Reset the current specified matrix is an identity matrix, the origin of the current user coordinate system is moved to the center of the screen gl.LoadIdentity (); // Since gl.LoadIdentity (); converting point to the origin, the coordinate axis conversion to the position ( 0, 0, -3), and this was noted above relative to (0,0,0) point positioning gl.Translate (0F, 0F, - 3F); drawPT (GL); gl.LoadIdentity (); // GL. Translate (0F, 0.5f, -3F); gl.Translate (0F, 1F, - 3F); // gl.Translate (0F, 1.5F, -3F); drawPT (GL); } Private void drawPT (SharpGL. GL the OpenGL) { gl.PointSize (5F); gl.Begin (OpenGL.GL_TRIANGLES); { gl.Vertex (0.0f , 0F, 0.0f ); gl.Vertex ( - 1.0f , -1F, 0.0f ); gl.Vertex ( 1.0f , -1F, 0.0f ); } gl.End (); } // button clicks event Private void btnTranslate_Click ( Object SENDER, EventArgs E) { Switch (((the Button) SENDER) .Name) { Case " btnTranslate " : MTYPE = 0 ; BREAK; case "btnRotate": mtype = 1; break; case "btnScale": mtype = 2; break; case "btnOrigin": mtype = 3; break; } } } }