1, a case: a triangle, a square (Vertex)

/ * Note: 
 * Modify project properties (right-click Properties -> Applications -> target framework -> NET Framework 4.), 
 * Otherwise occur "SharpGL" namespace reference error ---- "OpenGLControl" 
 * * / 
 
1 , ---- a case a triangle, a square (Vertex)
 namespace sharpGLTest01 
{ 
    public  partial  class the Form1: Form1 
    { 
        public the Form1 () 
        { 
            the InitializeComponent (); 
        } 
        / * OpenGLInitialized (initialize the OpenGL) event handler 
         * this a major purpose of the event is to provide users install the required logic. 
         * 
         * * / 
        // initialize 
        Private  void openGLControl1_OpenGLInitialized ( ObjectSENDER, EventArgs E) 
        { 
            // the OpenGL GL = openGLControl1.OpenGL; / * get a reference to the control OpenGLControl * /
             // gl.ClearColor (0,0,0,0); / * set the background color to glClearColor method scenes * / 
        } 

        / * OpenGLDraw event handler 
         * this is an OpenGL rendering event: 
         * 
         * * / 
        // draw 
        Private  void openGLControl1_OpenGLDraw ( Object SENDER, the PaintEventArgs E) 
        { 
            SharpGL.OpenGL GL = the this .openGLControl1.OpenGL;
             // clear the depth buffer 
            gl.Clear (OpenGL.GL_COLOR_BUFFER_BIT |OpenGL.GL_DEPTH_BUFFER_BIT); 

            // 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 (); 

            // coordinate axis conversion to a position (-1.5,0, -6 ) 
            gl.Translate (- 1.5F , 0F, - 6F); 

            gl.Begin (OpenGL.GL_TRIANGLES); 
            { 
                // vertex 
                gl.Vertex ( 0.0f , 1.0f , 0.0f );
                 // left endpoint       
                gl.Vertex ( - 1.0f , - 1.0f , 0.0f );
                 // the right end        
                gl.Vertex ( 1.0f , -1.0f , 0.0f ); 
            } 
            gl.End (); 

            // the current coordinates right by 3 units, noted above, and this was relatively (-1.5,0, -6) point positioning 
            gl.Translate (3f, 0f , 1F); 

            gl.Begin (OpenGL.GL_QUADS); 
            { 
                gl.Vertex ( - 1.0f , 1.0f , 0.0f ); 
                gl.Vertex ( 1.0f , 1.0f , 0.0f ); 
                gl.Vertex ( 1.0f , - 1.0f , 0.0f ); 
                gl.Vertex ( - 1.0f , - 1.0f, 0.0f ); 
            } 
            gl.End (); 
            gl.Flush ();    // force a refresh 
        } 
        
        / * OpenGLDraw event handler 
         * This is an OpenGL drawing event: 
         * 
         * * / 
        // adjust 
        Private  void openGLControl1_Resize ( Object SENDER, E EventArgs) 
        { 
            // the OpenGL GL = openGLControl1.OpenGL; 

            /// / current matrix pattern, and then apply the matrix operation on the projection matrix 
            // gl.MatrixMode (OpenGL.GL_PROJECTION); 

            /// / reset the current designated matrix is a unit matrix, the origin of the current user coordinate system is moved to the center of the screen 
            // gl.LoadIdentity (); 

            /// / create perspective projection transformation
            // gl.Perspective (30.0f, (Double) the Width / (Double) the Height,. 5, 100.0); 

            /// / viewpoint converting 
            // gl.LookAt (-5,. 5, -5, 0, 0, 0, 0, 1, 0); 

            // / current matrix model view matrix 
            // gl.MatrixMode (OpenGL.GL_MODELVIEW); 
        } 
    } 
}

Reference article: https: //www.cnblogs.com/hackpig/p/5770458.html

Note: For SharpGL learning article was referring to the author's blog

Guess you like

Origin www.cnblogs.com/lotuses/p/11357893.html