public PostProcessingExample(int width, int height)
 {
     fbo = new FBO();
     textureForRendering = Texture.Create(width, height);
     shaderPostProcess = PixelShader.Create(Encoding.UTF8.GetString(Resources.Swirl));
     shaderSource = PixelShader.Create(Encoding.UTF8.GetString(Resources.PatternCircle));
 }
Ejemplo n.º 2
0
        private MyApplication()
        {
            //registers a callback for drawing a frame
            gameWindow.RenderFrame += GameWindow_RenderFrame;
            gameWindow.RenderFrame += (sender, e) => gameWindow.SwapBuffers();
            //register a callback for updating the game logic
            gameWindow.UpdateFrame += GameWindow_UpdateFrame;
            gameWindow.KeyDown += GameWindow_KeyDown;

            texBackground = TextureLoader.FromBitmap(Resources.background);
            texBird = TextureLoader.FromBitmap(Resources.bird);

            postProcessing = new PostProcessing(gameWindow.Width, gameWindow.Height);
            try
            {
                postProcessing.SetShader(Encoding.UTF8.GetString(Resources.EdgeDetect));
            }
            catch (ShaderException e)
            {
                Console.WriteLine(e.Log);
            }

            //for transparency in textures we use blending
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            globalTime.Start();
        }
Ejemplo n.º 3
0
 public MyApplication()
 {
     gameWindow.Closing += GameWindow_Closing;
     gameWindow.Resize += GameWindow_Resize;
     gameWindow.KeyDown += GameWindow_KeyDown;
     gameWindow.MouseDown += GameWindow_MouseDown;
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (sender, e) => { gameWindow.SwapBuffers(); };
     GL.ClearColor(Color.DarkGreen);
     for (int x = 0; x < 8; ++x)
     {
         for (int y = 0; y < 8; ++y)
         {
             grid[x, y] = FieldType.EMPTY;
         }
     }
     grid[3, 3] = FieldType.BLACK;
     grid[3, 4] = FieldType.WHITE;
     grid[4, 3] = FieldType.WHITE;
     grid[4, 4] = FieldType.BLACK;
     lastMove = new Point(4, 4);
     texWhite = TextureLoader.FromBitmap(Resourcen.white);
     texBlack = TextureLoader.FromBitmap(Resourcen.black);
     texTable = TextureLoader.FromBitmap(Resourcen.pool_table);
 }
Ejemplo n.º 4
0
 public SpriteSheet(Texture tex, uint spritesPerLine
     , float spriteBoundingBoxWidth = 1.0f, float spriteBoundingBoxHeight = 1.0f)
 {
     this.tex = tex;
     this.tex.FilterTrilinear();
     this.spritesPerLine = spritesPerLine;
     this.spriteBoundingBoxWidth = spriteBoundingBoxWidth;
     this.spriteBoundingBoxHeight = spriteBoundingBoxHeight;
 }
Ejemplo n.º 5
0
 public PingPongExample(int width, int height)
 {
     fbo = new FBO();
     textureA = Texture.Create(width, height);
     textureB = Texture.Create(width, height);
     active = textureA;
     shaderCopy = PixelShader.Create(PixelShader.Copy);
     shaderGameOfLife = PixelShader.Create(Encoding.UTF8.GetString(Resources.GameOfLife));
 }
Ejemplo n.º 6
0
 public static Texture Create(int width, int height, PixelInternalFormat internalFormat = PixelInternalFormat.Rgba8
     , PixelFormat inputPixelFormat = PixelFormat.Rgba, PixelType type = PixelType.UnsignedByte)
 {
     var texture = new Texture();
     //create empty texture of given size
     texture.LoadPixels(IntPtr.Zero, width, height, internalFormat, inputPixelFormat, type);
     //set default parameters for filtering and clamping
     texture.FilterBilinear();
     texture.WrapMode(TextureWrapMode.Repeat);
     return texture;
 }
Ejemplo n.º 7
0
        public VisualContext()
        {
            GL.Disable(EnableCap.DepthTest);
            GL.ClearColor(1, 0, 0, 0);

            surface = new FBO();
            textureSurface = Texture.Create(1, 1);

            shaderCopyToScreen = InitShaderCopyToScreen();
            shaderDefault = InitShaderDefault();
        }
Ejemplo n.º 8
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();
 }
Ejemplo n.º 9
0
        public VisualSmoke(Vector3 emitterPos, Vector3 wind)
        {
            Emitter = emitterPos;
            Wind = wind;
            texStar = TextureLoader.FromBitmap(Resourcen.smoke);
            shaderWatcher = new ShaderFileDebugger("../../ParticleSystemExample/Resources/smoke.vert"
                , "../../ParticleSystemExample/Resources/smoke.frag"
                , Resourcen.smoke_vert, Resourcen.smoke_frag);

            particleSystem.ReleaseInterval = 0.02f;
            particleSystem.OnParticleCreate += Create;
        }
Ejemplo n.º 10
0
        public VisualWaterfall(Vector3 emitterPos)
        {
            this.emitterPos = emitterPos;
            texStar = TextureLoader.FromBitmap(Resourcen.water_splash);
            shaderWatcher = new ShaderFileDebugger("../../ParticleSystemExample/Resources/smoke.vert"
                , "../../ParticleSystemExample/Resources/smoke.frag"
                , Resourcen.smoke_vert, Resourcen.smoke_frag);

            particleSystem.ReleaseInterval = 0.03f;
            particleSystem.OnParticleCreate += Create;
            particleSystem.OnAfterParticleUpdate += OnAfterParticleUpdate;
        }
Ejemplo n.º 11
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();
 }
Ejemplo n.º 12
0
 private MyApplication()
 {
     //setup
     gameWindow = new GameWindow(512, 512);
     gameWindow.KeyDown += (s, arg) => gameWindow.Close();
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     texBackground = TextureLoader.FromBitmap(Resourcen.mountains);
     //background clear color
     GL.ClearColor(Color.White);
 }
Ejemplo n.º 13
0
 public void BeginUse(Texture texture)
 {
     GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.m_FBOHandle);
     GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, texture.ID, 0);
     string status = GetStatusMessage();
     if (!string.IsNullOrEmpty(status))
     {
         EndUse();
         throw new FBOException(status);
     }
     GL.Viewport(0, 0, texture.Width, texture.Height);
 }
Ejemplo n.º 14
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();
 }
Ejemplo n.º 15
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);
     }
 }
Ejemplo n.º 16
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();
 }
Ejemplo n.º 17
0
 private MyApplication()
 {
     //setup
     gameWindow = new GameWindow(700, 700);
     gameWindow.KeyDown += (s, arg) => gameWindow.Close();
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     texShip = TextureLoader.FromBitmap(Resourcen.redship4);
     texBackground = TextureLoader.FromBitmap(Resourcen.water);
     //background clear color
     GL.ClearColor(Color.White);
     //for transparency in textures we use blending
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
 }
Ejemplo n.º 18
0
        public Visual()
        {
            // Vertex positions
            float[] positions =
            {
                1.0f, -1.0f,
                1.0f, 1.0f,
                -1.0f, -1.0f,
                -1.0f, 1.0f
            };
            // Reserve a name for the buffer object.
            bufferQuad = GL.GenBuffer();
            // Bind it to the GL_ARRAY_BUFFER target.
            GL.BindBuffer(BufferTarget.ArrayBuffer, bufferQuad);
            // Allocate space for it (sizeof(positions)
            GL.BufferData(BufferTarget.ArrayBuffer
                , (IntPtr) (sizeof(float) * positions.Length), positions, BufferUsageHint.StaticDraw);

            GL.BindVertexArray(bufferQuad);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.VertexPointer(2, VertexPointerType.Float, 0, 0);
            GL.BindVertexArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.Disable(EnableCap.DepthTest);
            GL.ClearColor(1, 0, 0, 0);

            surface = new FBO();
            textureSurface = Texture.Create(1, 1);

            string sVertexShader = @"
                varying vec2 uv;
                void main() {
                    gl_Position = gl_Vertex;
                    uv = gl_Vertex.xy * 0.5f + 0.5f;
                }";
            string sFragmentShd = @"
            varying vec2 uv;
            uniform sampler2D tex;
            void main() {
                gl_FragColor = texture(tex, uv);
            }";
            shaderCopyToScreen = Shader.LoadFromStrings(sVertexShader, sFragmentShd);
            shader = new Shader();
            texture1 = new Texture();
            texture2 = new Texture();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Create a new font that can be printed in OpenGL
 /// </summary>
 /// <param name="texture">texture containing a equally spaced grid of characters</param>
 /// <param name="charactersPerLine">number of characters per grid row</param>
 /// <param name="firstAsciiCode">ascii code of upper left most character in the grid</param>
 /// <param name="characterBoundingBoxWidth">bounding box width of each character cell, allows to zoom in/out of each character</param>
 /// <param name="characterBoundingBoxHeight">bounding box height of each character cell, allows to zoom in/out of each character</param>
 /// <param name="characterSpacing">how much to move to the right after drawing a single character</param>
 public TextureFont(Texture texture, uint charactersPerLine = 16, byte firstAsciiCode = 0
     , float characterBoundingBoxWidth = 1.0f, float characterBoundingBoxHeight = 1.0f, float characterSpacing = 1.0f)
 {
     this.texFont = new SpriteSheet(texture, charactersPerLine, characterBoundingBoxWidth, characterBoundingBoxHeight);
     // Creating 256 Display Lists
     this.baseList = (uint)GL.GenLists(256);
     //foreach of the 256 possible characters create a a quad
     //with texture coordinates and store it in a display list
     var rect = new Box2D(0, 0, 1, 1);
     for (uint asciiCode = 0; asciiCode < 256; ++asciiCode)
     {
         GL.NewList((this.baseList + asciiCode), ListMode.Compile);
         texFont.Draw(asciiCode - firstAsciiCode, rect);
         GL.Translate(characterSpacing, 0, 0);	// Move To The next character
         GL.EndList();
     }
 }
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
0
 public MyApplication()
 {
     gameWindow.Resize += GameWindow_Resize;
     gameWindow.KeyDown += (sender, e) => { if (Key.Escape == e.Key)	gameWindow.Exit(); };
     gameWindow.MouseDown += GameWindow_MouseDown;
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (sender, e) => { gameWindow.SwapBuffers(); };
     GL.ClearColor(Color.Black);
     for (int x = 0; x < gridRes; ++x)
     {
         for (int y = 0; y < gridRes; ++y)
         {
             grid[x, y] = FieldType.EMPTY;
         }
     }
     texWhite = TextureLoader.FromBitmap(Resourcen.white);
     texBlack = TextureLoader.FromBitmap(Resourcen.black);
     texWater = TextureLoader.FromBitmap(Resourcen.water);
     font = new TextureFont(TextureLoader.FromBitmap(Resourcen.Fire_2), 10, 32, 1.0f, 0.9f, 0.5f);
 }
Ejemplo n.º 22
0
 private MyApplication()
 {
     //setup
     gameWindow = new GameWindow(700, 700);
     gameWindow.KeyDown += (s, arg) => gameWindow.Close();
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     //callback for updating http://gameprogrammingpatterns.com/game-loop.html
     gameWindow.UpdateFrame += GameWindow_UpdateFrame;
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     texPlayer = TextureLoader.FromBitmap(Resourcen.bird1);
     //two landscape resources are available in the Resourcen.resx file
     texBackground = TextureLoader.FromBitmap(Resourcen.forest);
     //set how texture coordinates outside of [0..1] are handled
     texBackground.WrapMode(TextureWrapMode.Repeat);
     //background clear color
     GL.ClearColor(Color.White);
     //for transparency in textures
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
 }
Ejemplo n.º 23
0
 private MyApplication()
 {
     //setup
     gameWindow = new GameWindow(700, 700);
     gameWindow.VSync = VSyncMode.On;
     gameWindow.KeyDown += (s, arg) => gameWindow.Close();
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     gameWindow.UpdateFrame += GameWindow_UpdateFrame;
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     texBird = TextureLoader.FromBitmap(Resourcen.bird1);
     //background clear color
     GL.ClearColor(Color.DarkGreen);
     //for transparency in textures
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     //generate birds
     for(float delta = .1f; delta < .5f; delta += .1f)
     {
         birds.Add(Box2D.CreateFromCenterSize(rotCenter.X - delta, rotCenter.Y - delta, .1f, .1f));
         birds.Add(Box2D.CreateFromCenterSize(rotCenter.X - delta, rotCenter.Y + delta, .1f, .1f));
         birds.Add(Box2D.CreateFromCenterSize(rotCenter.X + delta, rotCenter.Y - delta, .1f, .1f));
         birds.Add(Box2D.CreateFromCenterSize(rotCenter.X + delta, rotCenter.Y + delta, .1f, .1f));
     }
 }
Ejemplo n.º 24
0
 private void UpdateSurfaceSize(int width, int height)
 {
     if (width != textureSurface.Width || height != textureSurface.Height)
     {
         textureSurface.Dispose();
         textureSurface = Texture.Create(width, height);
     }
 }
Ejemplo n.º 25
0
 public void AddFrame(Texture textureFrame)
 {
     textures.Add(textureFrame);
 }
Ejemplo n.º 26
0
 public PostProcessing(int width, int height)
 {
     fbo = new FBO();
     texImage = Texture.Create(width, height);
     SetShader(ShaderCopy);
 }
Ejemplo n.º 27
0
 private static void DrawTexturedRect(Box2D rect, Texture tex, Box2D texCoords)
 {
     tex.BeginUse();
     rect.DrawTexturedRect(texCoords);
     tex.EndUse();
 }
Ejemplo n.º 28
0
 public void LoadTexture2(string fileName)
 {
     texture2 = TextureLoader.FromFile(fileName);
 }
Ejemplo n.º 29
0
 public void Register(string type, Texture texture)
 {
     this.registeredTypes[type] = texture;
 }
Ejemplo n.º 30
-1
 private MyApplication()
 {
     //set waypoints of enemy
     wayPoints.Add(new Vector2(-.5f, -.5f));
     wayPoints.Add(new Vector2(.5f, -.5f));
     wayPoints.Add(new Vector2(.5f, .5f));
     wayPoints.Add(new Vector2(-.5f, .5f));
     //wayPoints.Add(new Vector2(.6f, -.7f));
     //wayPoints.Add(new Vector2(.5f, .8f));
     //wayPoints.Add(new Vector2(-.5f, .4f));
     //wayPoints.Add(new Vector2(0, 0));
     wayTangents = CatmullRomSpline.FiniteDifferenceLoop(wayPoints);
     //setup
     gameWindow = new GameWindow(700, 700);
     gameWindow.VSync = VSyncMode.On;
     gameWindow.KeyDown += (s, arg) => gameWindow.Close();
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     gameWindow.UpdateFrame += GameWindow_UpdateFrame;
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     texBird = TextureLoader.FromBitmap(Resourcen.bird1);
     //background clear color
     GL.ClearColor(Color.White);
     //for transparency in textures
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     timeSource.Start();
 }