当前位置: 首页 > news >正文

临汾住房与城乡建设厅网站迎访问中国建设银行网站_

临汾住房与城乡建设厅网站,迎访问中国建设银行网站_,物流网站制作怎么做,怎样用代码做网站接上篇,绘制着色矩形 C#使用OpenTK绘制一个着色矩形-CSDN博客 上一篇安装OpenTK.GLControl后,这里可以直接拖动控件GLControl 我们会发现GLControl继承于UserControl //// 摘要:// OpenGL-aware WinForms control. The WinForms designer will always call the default//…接上篇,绘制着色矩形 C#使用OpenTK绘制一个着色矩形-CSDN博客 上一篇安装OpenTK.GLControl后,这里可以直接拖动控件GLControl 我们会发现GLControl继承于UserControl //// 摘要:// OpenGL-aware WinForms control. The WinForms designer will always call the default// constructor. Inherit from this class and call one of its specialized constructors// to enable antialiasing or custom OpenTK.GLControl.GraphicsModes.public class GLControl : System.Windows.Forms.UserControl 以下我们绘制一个三棱锥,三棱锥需要四个顶点Vertex 新建窗体FormGLControl,拖入一个控件GLControl,绑定Load,Paint等事件 窗体FormGLControl设计器代码为: 文件FormGLControl.Designer.cs using OpenTK; namespace OpenTKDemo {partial class FormGLControl{/// summary/// Required designer variable./// /summaryprivate System.ComponentModel.IContainer components null;/// summary/// Clean up any resources being used./// /summary/// param namedisposingtrue if managed resources should be disposed; otherwise, false./paramprotected override void Dispose(bool disposing){if (disposing (components ! null)){components.Dispose();}base.Dispose(disposing);}#region Windows Form Designer generated code/// summary/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// /summaryprivate void InitializeComponent(){this.glControl1 new OpenTK.GLControl();this.SuspendLayout();// // glControl1// this.glControl1.BackColor System.Drawing.Color.Black;this.glControl1.Location new System.Drawing.Point(12, 12);this.glControl1.Name glControl1;this.glControl1.Size new System.Drawing.Size(800, 600);this.glControl1.TabIndex 0;this.glControl1.VSync false;this.glControl1.Load new System.EventHandler(this.glControl1_Load);this.glControl1.Paint new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);this.glControl1.MouseDown new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseDown);this.glControl1.MouseMove new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseMove);this.glControl1.MouseUp new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseUp);this.glControl1.Resize new System.EventHandler(this.glControl1_Resize);// // FormGLControl// this.AutoScaleDimensions new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode System.Windows.Forms.AutoScaleMode.Font;this.ClientSize new System.Drawing.Size(832, 619);this.Controls.Add(this.glControl1);this.Name FormGLControl;this.Text FormGLControl;this.ResumeLayout(false);}#endregionprivate GLControl glControl1;} } 窗体FormGLControl相关代码如下: 文件FormGLControl.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using OpenTK; using OpenTK.Graphics.OpenGL;namespace OpenTKDemo {public partial class FormGLControl : Form{private int vao, vbo, shaderProgram;private Matrix4 model, view, projection;private float rotationX 0.0f, rotationY 0.0f; // 旋转角度private bool isDragging false;private Point lastMousePosition;public FormGLControl(){InitializeComponent();}private void glControl1_Load(object sender, EventArgs e){// 设置清屏颜色GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);// 初始化 VAO 和 VBOvao GL.GenVertexArray();vbo GL.GenBuffer();GL.BindVertexArray(vao);float[] vertices {// 顶点位置 // 颜色0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // 顶点1(x,y,z,red,green,blue)-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, // 顶点20.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, // 顶点30.0f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f // 顶点4};int[] indices {0, 1, 2, // 正面0, 2, 3, // 右面0, 3, 1, // 左面1, 3, 2 // 底面};int ebo GL.GenBuffer();GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);GL.BindBuffer(BufferTarget.ElementArrayBuffer, ebo);GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(int), indices, BufferUsageHint.StaticDraw);GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);GL.EnableVertexAttribArray(0);GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 3 * sizeof(float));GL.EnableVertexAttribArray(1);// 创建并编译着色器string vertexShaderSource #version 330 corelayout (location 0) in vec3 aPosition;layout (location 1) in vec3 aColor;out vec3 vertexColor;uniform mat4 model;uniform mat4 view;uniform mat4 projection;void main(){gl_Position projection * view * model * vec4(aPosition, 1.0);vertexColor aColor;};string fragmentShaderSource #version 330 corein vec3 vertexColor;out vec4 FragColor;void main(){FragColor vec4(vertexColor, 1.0);};int vertexShader CompileShader(ShaderType.VertexShader, vertexShaderSource);int fragmentShader CompileShader(ShaderType.FragmentShader, fragmentShaderSource);shaderProgram GL.CreateProgram();GL.AttachShader(shaderProgram, vertexShader);GL.AttachShader(shaderProgram, fragmentShader);GL.LinkProgram(shaderProgram);// 删除着色器GL.DeleteShader(vertexShader);GL.DeleteShader(fragmentShader);// 初始化矩阵view Matrix4.LookAt(new Vector3(0.0f, 0.0f, 2.0f), Vector3.Zero, Vector3.UnitY);projection Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45.0f), glControl1.Width / (float)glControl1.Height, 0.1f, 100.0f);GL.BindVertexArray(0);}private void glControl1_Paint(object sender, PaintEventArgs e){// 清屏GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);// 绘制三角锥GL.UseProgram(shaderProgram);model Matrix4.CreateRotationX(MathHelper.DegreesToRadians(rotationX)) *Matrix4.CreateRotationY(MathHelper.DegreesToRadians(rotationY));GL.UniformMatrix4(GL.GetUniformLocation(shaderProgram, model), false, ref model);GL.UniformMatrix4(GL.GetUniformLocation(shaderProgram, view), false, ref view);GL.UniformMatrix4(GL.GetUniformLocation(shaderProgram, projection), false, ref projection);GL.BindVertexArray(vao);GL.DrawElements(PrimitiveType.Triangles, 12, DrawElementsType.UnsignedInt, 0);glControl1.SwapBuffers();}private void glControl1_Resize(object sender, EventArgs e){GL.Viewport(0, 0, glControl1.Width, glControl1.Height);projection Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45.0f), glControl1.Width / (float)glControl1.Height, 0.1f, 100.0f);}private void glControl1_MouseDown(object sender, MouseEventArgs e){if (e.Button MouseButtons.Left){isDragging true;lastMousePosition e.Location;}}private void glControl1_MouseUp(object sender, MouseEventArgs e){if (e.Button MouseButtons.Left){isDragging false;}}private void glControl1_MouseMove(object sender, MouseEventArgs e){if (isDragging){int deltaX e.X - lastMousePosition.X;int deltaY e.Y - lastMousePosition.Y;rotationX deltaY * 0.5f;rotationY deltaX * 0.5f;lastMousePosition e.Location;glControl1.Invalidate();}}private int CompileShader(ShaderType type, string source){int shader GL.CreateShader(type);GL.ShaderSource(shader, source);GL.CompileShader(shader);GL.GetShader(shader, ShaderParameter.CompileStatus, out int status);if (status 0){GL.GetShaderInfoLog(shader, out string infoLog);throw new Exception($Error compiling shader ({type}): {infoLog});}return shader;}} }运行如图: 可以拖动旋转:
http://www.zqtcl.cn/news/410621/

相关文章:

  • 织梦做的网站首页幻灯片怎么不能显示北大青鸟网站建设课程
  • 做淘客的网站有哪些延安市住建建设网站
  • 南京林业大学实验与建设网站现在都用什么软件搜索附近的人
  • 建站系统wordpress下载亚马逊雨林十大恐怖生物
  • 凡科网做网站怎么样专业团队电影
  • 有什么有趣的网站移动网站排名怎么做
  • 深圳网站建设专家wordpress 4.5下载地址
  • 网站建设公司公司我我提供一个平台wordpress如何去版权信息
  • seo怎么给网站做外链受欢迎的网站建设教程
  • 网站建设使用多语言河南电商网站设计
  • 网站搭建有免费的吗网站地图生成代码
  • 建设公司网站要注意什么投资小利润高的小生意
  • 网站建设需要做哪些工作做胃镜需那好天津津门网站A
  • 做网站申请域名的流程辽宁省工程造价网
  • 网站系统维护一般多长时间金华高端网站设计
  • 做网站公司销售开场白企业网站规划与开发
  • 兰州新区建站不锈钢网站建设
  • 淘宝小网站怎么做的电商网站有哪些
  • 哪些网站可以做画赚钱wordpress go跳转页
  • 怎么做新网站上线通稿深圳罗湖区网站建设公司
  • php 企业网站做网站可以赚钱吗
  • 局域网视频网站建设点播系统长沙3合1网站建设价格
  • 静态网站 服务器合肥做个网站什么价格
  • 宁阳网站设计家电网站设计方案
  • 网站备案icp秦皇岛黄金海岸
  • dedecms 金融类网站模板wordpress dux5.3
  • 学校网站源码wordpress向网站上传文件怎么做
  • 电子商务网站建设说课稿济南网站建设方案报价
  • 谈谈设计和建设网站体会wordpress header在哪
  • 360免费建站怎么进不去域名托管