Esempio n. 1
0
 private static void DrawTexturedRect(Box2D rect, Texture tex, Box2D texCoords)
 {
     tex.BeginUse();
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(texCoords.X, texCoords.Y); GL.Vertex2(rect.X, rect.Y);
     GL.TexCoord2(texCoords.MaxX, texCoords.Y); GL.Vertex2(rect.MaxX, rect.Y);
     GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rect.MaxX, rect.MaxY);
     GL.TexCoord2(texCoords.X, texCoords.MaxY); GL.Vertex2(rect.X, rect.MaxY);
     GL.End();
     tex.EndUse();
 }
Esempio n. 2
0
 static void DrawSprite(float x, float y, Texture tex, float radius = 0.5f, float repeat = 1.0f)
 {
     tex.BeginUse();
     GL.Color3(Color.White);
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(x - radius, y - radius);
     GL.TexCoord2(repeat, 0.0f); GL.Vertex2(x + radius, y - radius);
     GL.TexCoord2(repeat, repeat); GL.Vertex2(x + radius, y + radius);
     GL.TexCoord2(0.0f, repeat); GL.Vertex2(x - radius, y + radius);
     GL.End();
     tex.EndUse();
 }
Esempio n. 3
0
 private void DrawTexturedRect(Box2D Rectangle, Texture tex)
 {
     GL.Color3(Color.White);
     tex.BeginUse();
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rectangle.X, Rectangle.Y);
     GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.Y);
     GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.MaxY);
     GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rectangle.X, Rectangle.MaxY);
     GL.End();
     tex.EndUse();
 }
Esempio n. 4
0
 public static void SaveToFile(Texture texture, string fileName)
 {
     var format = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
     texture.BeginUse();
     using (Bitmap bmp = new Bitmap(texture.Width, texture.Height))
     {
         BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, format);
         GL.GetTexImage(TextureTarget.Texture2D, 0, selectInputPixelFormat(format), PixelType.UnsignedByte, data.Scan0);
         bmp.UnlockBits(data);
         texture.EndUse();
         bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
         bmp.Save(fileName);
     }
 }
Esempio n. 5
0
        public static void SaveToFile(Texture texture, string fileName)
        {
            var format = System.Drawing.Imaging.PixelFormat.Format32bppArgb;

            texture.BeginUse();
            using (Bitmap bmp = new Bitmap(texture.Width, texture.Height))
            {
                BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, format);
                GL.GetTexImage(TextureTarget.Texture2D, 0, selectInputPixelFormat(format), PixelType.UnsignedByte, data.Scan0);
                bmp.UnlockBits(data);
                texture.EndUse();
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                bmp.Save(fileName);
            }
        }
Esempio n. 6
0
 private static void DrawTexturedRect(Box2D Rect, Texture tex)
 {
     //the texture has to be enabled before use
     tex.BeginUse();
     GL.Begin(PrimitiveType.Quads);
         //when using textures we have to set a texture coordinate for each vertex
         //by using the TexCoord command BEFORE the Vertex command
         GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rect.X, Rect.Y);
         GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rect.MaxX, Rect.Y);
         GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rect.MaxX, Rect.MaxY);
         GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rect.X, Rect.MaxY);
     GL.End();
     //the texture is disabled, so no other draw calls use this texture
     tex.EndUse();
 }
Esempio n. 7
0
 public static Texture FromBitmap(Bitmap bitmap)
 {
     Texture texture = new Texture();
     texture.FilterTrilinear();
     texture.BeginUse();
     //todo: 16bit channels
     using (Bitmap bmp = new Bitmap(bitmap))
     {
         bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
         BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
         PixelInternalFormat internalFormat = selectInternalPixelFormat(bmp.PixelFormat);
         OpenTK.Graphics.OpenGL.PixelFormat inputPixelFormat = selectInputPixelFormat(bmp.PixelFormat);
         texture.LoadPixels(bmpData.Scan0, bmpData.Width, bmpData.Height, internalFormat, inputPixelFormat, PixelType.UnsignedByte);
         bmp.UnlockBits(bmpData);
     }
     texture.EndUse();
     return texture;
 }
Esempio n. 8
0
        public static Texture FromBitmap(Bitmap bitmap)
        {
            Texture texture = new Texture();

            texture.BeginUse();
            texture.FilterTrilinear();
            //todo: 16bit channels
            using (Bitmap bmp = new Bitmap(bitmap))
            {
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                BitmapData          bmpData        = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
                PixelInternalFormat internalFormat = selectInternalPixelFormat(bmp.PixelFormat);
                OpenTK.Graphics.OpenGL.PixelFormat inputPixelFormat = selectInputPixelFormat(bmp.PixelFormat);
                texture.LoadPixels(bmpData.Scan0, bmpData.Width, bmpData.Height, internalFormat, inputPixelFormat, PixelType.UnsignedByte);
                bmp.UnlockBits(bmpData);
            }
            texture.EndUse();
            return(texture);
        }
Esempio n. 9
0
 private static void DrawTexturedRect(Box2D rect, Texture tex, Box2D texCoords)
 {
     tex.BeginUse();
     rect.DrawTexturedRect(texCoords);
     tex.EndUse();
 }