Beispiel #1
0
 public void CreateTex(OpenGL context, Bitmap image)
 {
     texture = new SharpGL.SceneGraph.Assets.Texture();
     texture.Create(context, image);
     context.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_REPEAT);
     context.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_REPEAT);
     context.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
     context.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
     context.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_REPLACE);
     texture.Bind(context);
 }
Beispiel #2
0
        /// <summary>
        /// Handles the OpenGLDraw event of the openGLControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RenderEventArgs"/> instance containing the event data.</param>
        ///


        private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            try
            {
                double LIGHT = 400;
                //  Get the OpenGL object.
                OpenGL gl = openGLControl.OpenGL;
                gl.LookAt(Tin.CenterPoint.X, Tin.CenterPoint.Y, -300, Tin.CenterPoint.X, Tin.CenterPoint.Y, 50, 0, 1, 0);

                //  Clear the color and depth buffer.
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

                //  Load the identity matrix.
                gl.LoadIdentity();
                gl.ClearColor(0, 0.3f, 0, 1);



                gl.ShadeModel(OpenGL.GL_FLAT);
                SharpGL.SceneGraph.Assets.Texture texture = new SharpGL.SceneGraph.Assets.Texture();
                texture.Create(gl, @".\123.bmp");
                gl.Enable(OpenGL.GL_TEXTURE_2D);
                texture.Bind(gl);
                #region //添加纹理
                gl.Begin(OpenGL.GL_TRIANGLES);
                foreach (Triangle x in Tin.Triangledata)
                {
                    gl.TexCoord(0.0f, 0.0f); gl.Vertex(x.GetTriPointA.X, x.GetTriPointA.Y, x.GetTriPointA.Z);
                    gl.TexCoord(1f, 0f); gl.Vertex(x.GetTriPointB.X, x.GetTriPointB.Y, x.GetTriPointB.Z);
                    gl.TexCoord(1f, 1f); gl.Vertex(x.GetTriPointC.X, x.GetTriPointC.Y, x.GetTriPointC.Z);
                }
                gl.End();



                #endregion


                gl.Enable(OpenGL.GL_LIGHTING);
                gl.Enable(OpenGL.GL_LIGHT0);
                gl.Enable(OpenGL.GL_LIGHT1);
                gl.Enable(OpenGL.GL_DEPTH_TEST);
                gl.ShadeModel(OpenGL.GL_FLAT);
                gl.LightModel(OpenGL.GL_LIGHT_MODEL_TWO_SIDE, OpenGL.GL_FALSE);


                Tin.Process();
                //绑定纹理



                #region//画三角网

                gl.LineWidth(1 / 2);
                //gl.Begin(OpenGL.GL_LINES);


                gl.Color(0, 0, 0);
                gl.Begin(OpenGL.GL_LINES);
                foreach (Edge temp1 in Tin.UsedEdgedata)
                {
                    gl.TexCoord(0.0f, 0.0f); gl.Vertex(temp1.GetPointa.X, temp1.GetPointa.Y, temp1.GetPointa.Z);
                    gl.TexCoord(1f, 1f); gl.Vertex(temp1.GetPointb.X, temp1.GetPointb.Y, temp1.GetPointb.Z);
                }
                foreach (Edge temp in Tin.OnlyEdgedata)
                {
                    gl.TexCoord(0.0f, 0.0f); gl.Vertex(temp.GetPointa.X, temp.GetPointa.Y, temp.GetPointa.Z);
                    gl.TexCoord(1f, 1f); gl.Vertex(temp.GetPointb.X, temp.GetPointb.Y, temp.GetPointb.Z);
                }

                gl.End();
                #endregion
                #region//添加光照
                gl.ShadeModel(OpenGL.GL_SMOOTH);
                //初始化材质
                var mat_specular  = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
                var mat_ambient   = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
                var mat_diffuse   = new float[] { 2.0f, 2.0f, 2.0f, 0.1f };
                var mat_shininess = new float[] { 100.0f };
                gl.Material(OpenGL.GL_FRONT, OpenGL.GL_SPECULAR, mat_specular);
                gl.Material(OpenGL.GL_FRONT, OpenGL.GL_AMBIENT, mat_ambient);
                gl.Material(OpenGL.GL_FRONT, OpenGL.GL_DIFFUSE, mat_diffuse);
                gl.Material(OpenGL.GL_FRONT, OpenGL.GL_SHININESS, mat_shininess);
                //初始化光照
                var ambientLight = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
                var diffuseLight = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
                var posLight0    = new float[] { 2.0f, 0.1f, 0.0f, 0.0f };
                gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_AMBIENT, ambientLight);
                gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_DIFFUSE, diffuseLight);
                gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, posLight0);
                #endregion
            }
            catch { }
        }
 public void UseTexure(OpenGL gl)
 {
     _texture.Bind(gl);
     gl.ActiveTexture(_texture.TextureName);
 }