當前位置: 首頁>>代碼示例>>C#>>正文


C# OpenGL.BindTexture方法代碼示例

本文整理匯總了C#中SharpGL.OpenGL.BindTexture方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.BindTexture方法的具體用法?C# OpenGL.BindTexture怎麽用?C# OpenGL.BindTexture使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SharpGL.OpenGL的用法示例。


在下文中一共展示了OpenGL.BindTexture方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DrawQuadsWithTexture

 private void DrawQuadsWithTexture(OpenGL gl, int texture, params int[][][] quads)
 {
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, _textures[texture]);
     gl.Begin(OpenGL.GL_QUADS);
     foreach (var quad in quads)
     {
         gl.TexCoord(0.0f, 0.0f); gl.Vertex(quad[0]);
         gl.TexCoord(1.0f, 0.0f); gl.Vertex(quad[1]);
         gl.TexCoord(1.0f, 1.0f); gl.Vertex(quad[2]);
         gl.TexCoord(0.0f, 1.0f); gl.Vertex(quad[3]);
     }
     gl.End();
 }
開發者ID:fbmly007,項目名稱:3dsexplorer,代碼行數:13,代碼來源:frmAbout.cs

示例2: InitTexture

 public void InitTexture(OpenGL gl)
 {
     _texture = new SharpGL.SceneGraph.Assets.Texture();
     _texture.Create(gl, _image);
     Id = _texture.TextureName;
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, _texture.TextureName);
 }
開發者ID:Vinic,項目名稱:TomatoEngine,代碼行數:7,代碼來源:ImageTexture.cs

示例3: BindBitmapToTexture

 private void BindBitmapToTexture(OpenGL gl, Bitmap bmp, int textureNumber)
 {
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, _textures[textureNumber]);
     gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, bmp.Width, bmp.Height, 0, 
         OpenGL.GL_BGR, 
         OpenGL.GL_UNSIGNED_BYTE, 
         bmp.LockBits(
             new Rectangle(0, 0, bmp.Width, bmp.Height), 
             ImageLockMode.ReadOnly, 
             PixelFormat.Format24bppRgb
             ).Scan0
         );
     //  Specify linear filtering.
     gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
     gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
     // the texture wraps over at the edges (repeat)
     gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_REPEAT);
     gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_REPEAT);
 }
開發者ID:fbmly007,項目名稱:3dsexplorer,代碼行數:19,代碼來源:frmAbout.cs

示例4: Draw

        public void Draw(OpenGL gl)
        {
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureID);

            int[] amb_diff = { Colour.A, Colour.B, Colour.G, Colour.A };
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_AMBIENT_AND_DIFFUSE, amb_diff);

            gl.Begin(OpenGL.GL_TRIANGLES);

            for (int i = 0; i < 3; i++)
            {
                Position point = Verts[i].Point;
                UV uv = Verts[i].UV;

                if (uv != null)
                    gl.TexCoord(uv.U, uv.V);

                gl.Vertex(point.X, point.Y, point.Z);
            }

            gl.End();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
        }
開發者ID:Kruithne,項目名稱:W3DT,代碼行數:23,代碼來源:Face.cs

示例5: AfterRendering

        protected void AfterRendering(OpenGL gl, RenderMode renderMode)
        {
            gl.Disable(OpenGL.GL_POLYGON_SMOOTH);

            shaderProgram.Unbind(gl);

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);

            gl.Disable(OpenGL.GL_TEXTURE_2D);
        }
開發者ID:bitzhuwei,項目名稱:CSharpGL,代碼行數:10,代碼來源:HexahedronGrid.cs

示例6: Draw

        public override void Draw(ref OpenGL gl)
        {
            if (!TexturesInitialised)
            {
                InitializeTexture(ref gl);
            }
            //  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.Enable(OpenGL.GL_TEXTURE_2D);
            gl.Enable(OpenGL.GL_LIGHTING);
            gl.Enable(OpenGL.GL_LIGHT0);
            gl.Enable(OpenGL.GL_DEPTH_TEST);
            gl.Enable(OpenGL.GL_NORMALIZE);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]);
            gl.Color(1.0f, 1.0f, 1.0f, 0.1f);

            gl.Begin(OpenGL.GL_QUADS);
            gl.FrontFace(OpenGL.GL_FRONT_FACE);

            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(gImage1.Width, gImage1.Height, 1.0f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(0.0f, gImage1.Height, 1.0f);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(0.0f, 0.0f, 1.0f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(gImage1.Width, 0.0f, 1.0f);
            gl.End();

            gl.Disable(OpenGL.GL_TEXTURE_2D);

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Ortho(0.0, (double)gImage1.Width, (double)gImage1.Height, 0.0, -1.0, 1.0);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
        }
開發者ID:EternalEnvy,項目名稱:SmackBrosClient,代碼行數:40,代碼來源:GameplayScreen.cs

示例7: InitializeTexture

        private void InitializeTexture(ref OpenGL gl)
        {
            gImage1 = new Bitmap(@"C:\Users\Lee\Documents\GitHub\SmackBrosClient\SmackBrosClient\files\meleemenu1.jpg");
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, gImage1.Width, gImage1.Height);
            gbitmapdata = gImage1.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            gImage1.UnlockBits(gbitmapdata);
            gl.GenTextures(1, gtexture);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]);
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA, gImage1.Width, gImage1.Height, 0, OpenGL.GL_BGR_EXT, OpenGL.GL_UNSIGNED_BYTE, gbitmapdata.Scan0);

            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);

            TexturesInitialised = true;
        }
開發者ID:EternalEnvy,項目名稱:SmackBrosClient,代碼行數:14,代碼來源:GameplayScreen.cs

示例8: RenderObjects

        public void RenderObjects(OpenGL gl, GameObject[] objects)
        {
            //clears the screen
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            //St matrix mode to PROJECTION so we can move the camera
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            //  Load the identity matrix.
            gl.LoadIdentity();
            //Move the camera
            CamController.SetCam(gl);
            //Set matrix mode back to Modelview so we can draw objects
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            if (_mode == RenderMode.WireFrame || _mode == RenderMode.Hitboxes)
            {
                foreach(GameObject obj in objects){
                    //Draw the object with texture
                    obj.Draw(gl);
                    //Unbind texture so we can draw lines
                    gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
                    if ( _mode == RenderMode.Hitboxes)
                    {
                        obj.DrawVelocity(gl);
                        DrawCircle(gl, obj.GetPosition().x,obj.GetPosition().y, obj.GetPhysSize());
                    }
                    else
                    {
                        obj.DrawWireFrame(gl);
                    }
                }
            }
            else
            {
                foreach ( GameObject obj in objects )
                {
                    //Draw the object with texture
                    obj.Draw(gl);
                }
            }
            //Unbind texture
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
        }
開發者ID:Vinic,項目名稱:TomatoEngine,代碼行數:42,代碼來源:RenderEngine.cs

示例9: Create

        /// <summary>
        /// This function creates the texture from an image file.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="path">The path to the image file.</param>
        /// <returns>True if the texture was successfully loaded.</returns>
        public virtual bool Create(OpenGL gl, string path)
        {
            //  Create the underlying OpenGL object.
            Create(gl);

            //  Try and load the bitmap. Return false on failure.
            Bitmap image = new Bitmap(path);
            if (image == null)
                return false;

            //	Get the maximum texture size supported by OpenGL.
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                    targetWidth = size;

            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                    targetHeight = size;
            }

            //  If need to scale, do so now.
            if (image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);

                //  Destory the old image, and reset.
                image.Dispose();
                image = (Bitmap)newImage;
            }

            //  Create an array of pixels the correct size.
            pixelData = new byte[image.Width * image.Height * 4];
            int index = 0;

            //  TODO: The loop below is staggeringly slow and needs speeding up.
            //  Go through the pixels backwards, this seems to be how OpenGL wants the data.
            for (int y = image.Height - 1; y >= 0; y--)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    Color pixel = image.GetPixel(x, y);
                    pixelData[index++] = pixel.R;
                    pixelData[index++] = pixel.G;
                    pixelData[index++] = pixel.B;
                    pixelData[index++] = pixel.A;
                }
            }

            //	Set the width and height.
            width = image.Width;
            height = image.Height;

            //  Dispose of the image file.
            image.Dispose();

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);

            //  Set the image data.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                width, height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE,
                pixelData);

            //  Set linear filtering mode.
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);

            //  We're done!
            return true;
        }
開發者ID:Kontrast,項目名稱:Computer-Graphics,代碼行數:99,代碼來源:Texture.cs

示例10: Bind

 /// <summary>
 /// This wraps the OpenGL function that makes the texture 'current'.
 /// </summary>
 public virtual void Bind(OpenGL gl)
 {
     //	Bind our texture object (make it the current texture).
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);
 }
開發者ID:Kontrast,項目名稱:Computer-Graphics,代碼行數:8,代碼來源:Texture.cs

示例11: InitTexture

        public void InitTexture(OpenGL renderer)
        {
            if (String.IsNullOrEmpty(Texture))
            {
                return;
            }

            //  We need to load the texture from file.
            var textureImage = new Bitmap(Texture);

            renderer.Enable(OpenGL.GL_TEXTURE_2D);
            //  Get one texture id, and stick it into the textures array.
            renderer.GenTextures(1, _textures);

            //  Bind the texture.
            renderer.BindTexture(OpenGL.GL_TEXTURE_2D, _textures[0]);

            //  Tell OpenGL where the texture data is.
            renderer.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE,
                textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);

            //  Specify linear filtering.
            renderer.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);


        }
開發者ID:cvanherk,項目名稱:3d-engine,代碼行數:27,代碼來源:GameObject.cs

示例12: AfterRendering

 protected void AfterRendering(OpenGL gl, RenderMode renderMode)
 {
     shaderProgram.Unbind(gl);
     gl.Disable(OpenGL.GL_BLEND);
     gl.Disable(OpenGL.GL_VERTEX_PROGRAM_POINT_SIZE);
     gl.Disable(OpenGL.GL_POINT_SPRITE_ARB);
     gl.Disable(OpenGL.GL_POINT_SMOOTH);
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
 }
開發者ID:bitzhuwei,項目名稱:CSharpGL,代碼行數:9,代碼來源:PointGrid.cs


注:本文中的SharpGL.OpenGL.BindTexture方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。