private void Render() { //初始化屏幕 //1.清理屏幕 GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearColor(0, 0, 0, 0); //背景为黑 //2.设置矩阵模式:GL_Projection或者GL_Modelview GL.MatrixMode(MatrixMode.Modelview); //指定当前矩阵模型视图矩阵 //3.加载当前矩阵模式 GL.LoadIdentity(); //将当前矩阵转为单位矩阵 if (glControl1.Focused) { GL.Color3(Color.Yellow); } else { GL.Color3(Color.SeaGreen); } //视口设置 //4.视口设置 Matrix4 lookat = Matrix4.LookAt(-Eye_distance, -Eye_distance, Eye_distance, 0, 0, 0, 0, 0, 1); GL.LoadMatrix(ref lookat);//加载视口矩阵 //GL.Rotate(angle.X, 1, 0, 0);//旋转物体 //GL.Rotate(angle.Y, 0, 0, 1); _ArcBall.TransformMatrix();//更新轨迹球 //显示设置 //5.显示设置 //绘图 if (hasAxis) { DrawAxis();//画坐标轴 } if (hasElem) { //循环显示每个线单元 foreach (KeyValuePair <int, Element> elem in CurModel.elements) { if (elem.Value.TYPE != ElemType.BEAM) { continue; } FrameElement bm = elem.Value as FrameElement; Point3d pt1 = CurModel.nodes[bm.I].Location; Point3d pt2 = CurModel.nodes[bm.J].Location; //显示单元 DrawElem((float)pt1.X, (float)pt1.Y, (float)pt1.Z, (float)pt2.X, (float)pt2.Y, (float)pt2.Z); } } //绘图最后:swapBuffers() glControl1.SwapBuffers();//调换缓存 }
private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args) { var gl = openGLControl1.OpenGL; gl.ClearColor(0.2f, 0.4f, 0.2f, 0.2f); gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); gl.MatrixMode(OpenGL.GL_PROJECTION); gl.LoadIdentity(); gl.Perspective(90, (float)openGLControl1.Width / openGLControl1.Height, 1, 1000); gl.LookAt(vx, vy, vz, 0, 0, 0, upx, upy, upz); ArcBall.TransformMatrix(gl); gl.MatrixMode(OpenGL.GL_MODELVIEW); gl.LoadIdentity(); DrawAxis(gl); DrawPos(gl); gl.Finish(); gl.Flush(); }