zoukankan      html  css  js  c++  java
  • 在此记录一下SharpGL最初创建的程序

    在此记录一下SharpGL最初创建的程序。完整工程在此

      1 /// <summary>
      2     /// The main form class.
      3     /// </summary>
      4     public partial class SharpGLForm : Form
      5     {
      6         /// <summary>
      7         /// Initializes a new instance of the <see cref="SharpGLForm"/> class.
      8         /// </summary>
      9         public SharpGLForm()
     10         {
     11             InitializeComponent();
     12         }
     13 
     14         /// <summary>
     15         /// Handles the OpenGLDraw event of the openGLControl control.
     16         /// </summary>
     17         /// <param name="sender">The source of the event.</param>
     18         /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param>
     19         private void openGLControl_OpenGLDraw(object sender, PaintEventArgs e)
     20         {
     21             //  Get the OpenGL object.
     22             OpenGL gl = openGLControl.OpenGL;
     23 
     24             //  Clear the color and depth buffer.
     25             gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
     26 
     27             //  Load the identity matrix.
     28             gl.LoadIdentity();
     29 
     30             //  Rotate around the Y axis.
     31             gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
     32 
     33             //  Draw a coloured pyramid.
     34             gl.Begin(OpenGL.GL_TRIANGLES);
     35             gl.Color(1.0f, 0.0f, 0.0f);
     36             gl.Vertex(0.0f, 1.0f, 0.0f);
     37             gl.Color(0.0f, 1.0f, 0.0f);
     38             gl.Vertex(-1.0f, -1.0f, 1.0f);
     39             gl.Color(0.0f, 0.0f, 1.0f);
     40             gl.Vertex(1.0f, -1.0f, 1.0f);
     41             gl.Color(1.0f, 0.0f, 0.0f);
     42             gl.Vertex(0.0f, 1.0f, 0.0f);
     43             gl.Color(0.0f, 0.0f, 1.0f);
     44             gl.Vertex(1.0f, -1.0f, 1.0f);
     45             gl.Color(0.0f, 1.0f, 0.0f);
     46             gl.Vertex(1.0f, -1.0f, -1.0f);
     47             gl.Color(1.0f, 0.0f, 0.0f);
     48             gl.Vertex(0.0f, 1.0f, 0.0f);
     49             gl.Color(0.0f, 1.0f, 0.0f);
     50             gl.Vertex(1.0f, -1.0f, -1.0f);
     51             gl.Color(0.0f, 0.0f, 1.0f);
     52             gl.Vertex(-1.0f, -1.0f, -1.0f);
     53             gl.Color(1.0f, 0.0f, 0.0f);
     54             gl.Vertex(0.0f, 1.0f, 0.0f);
     55             gl.Color(0.0f, 0.0f, 1.0f);
     56             gl.Vertex(-1.0f, -1.0f, -1.0f);
     57             gl.Color(0.0f, 1.0f, 0.0f);
     58             gl.Vertex(-1.0f, -1.0f, 1.0f);
     59             gl.End();
     60 
     61             //  Nudge the rotation.
     62             rotation += 3.0f;
     63         }
     64 
     65 
     66 
     67         /// <summary>
     68         /// Handles the OpenGLInitialized event of the openGLControl control.
     69         /// </summary>
     70         /// <param name="sender">The source of the event.</param>
     71         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
     72         private void openGLControl_OpenGLInitialized(object sender, EventArgs e)
     73         {
     74             //  TODO: Initialise OpenGL here.
     75 
     76             //  Get the OpenGL object.
     77             OpenGL gl = openGLControl.OpenGL;
     78 
     79             //  Set the clear color.
     80             gl.ClearColor(0, 0, 0, 0);
     81         }
     82 
     83         /// <summary>
     84         /// Handles the Resized event of the openGLControl control.
     85         /// </summary>
     86         /// <param name="sender">The source of the event.</param>
     87         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
     88         private void openGLControl_Resized(object sender, EventArgs e)
     89         {
     90             //  TODO: Set the projection matrix here.
     91 
     92             //  Get the OpenGL object.
     93             OpenGL gl = openGLControl.OpenGL;
     94 
     95             //  Set the projection matrix.
     96             gl.MatrixMode(OpenGL.GL_PROJECTION);
     97 
     98             //  Load the identity.
     99             gl.LoadIdentity();
    100 
    101             //  Create a perspective transformation.
    102             gl.Perspective(60.0f, (double)Width / (double)Height, 0.01, 100.0);
    103 
    104             //  Use the 'look at' helper function to position and aim the camera.
    105             gl.LookAt(-5, 5, -5, 0, 0, 0, 0, 1, 0);
    106 
    107             //  Set the modelview matrix.
    108             gl.MatrixMode(OpenGL.GL_MODELVIEW);
    109         }
    110 
    111         /// <summary>
    112         /// The current rotation.
    113         /// </summary>
    114         private float rotation = 0.0f;
    115     }
  • 相关阅读:
    ant 软件包不存在报错
    在 Internet Explorer 中使用 Windows 窗体控件
    智能客户端
    Back to the Future with Smart Clients
    "Automation 服务器不能创建对象" 的解决方案
    Top 10 Reasons for Developers to Create Smart Clients
    Updater Application Block for .NET
    Smart Client Application Model and the .NET Framework 1.1
    Security and Versioning Models in the Windows Forms Engine Help You Create and Deploy Smart Clients
    智能客户端技术总结(二)
  • 原文地址:https://www.cnblogs.com/bitzhuwei/p/SharpGLCreateNewApp.html
Copyright © 2011-2022 走看看