Пример #1
0
        public virtual void BindLightmap( )
        {
            if (TCol != null)
            {
                TCol.Bind(0);
            }

            Active = this;
        }
Пример #2
0
        public void LoadModel(string prefix, dynamic modelPath, dynamic textures)
        {
            //!< 2byte文字をLive2D側が読み込めない様子...
            using (var fs = new FileStream(Path.Combine(prefix, modelPath), FileMode.Open))
            {
                byte[] readBuffer = new byte[fs.Length];
                fs.Read(readBuffer, 0, (int)fs.Length);
                IntPtr dest = Marshal.AllocHGlobal((int)fs.Length);
                Marshal.Copy(readBuffer, 0, dest, (int)fs.Length);
                ModelObject.craeteModel(dest, (int)fs.Length);
            }

            //!< テクスチャー読み込み
            for (int i = 0; i < ((object[])textures).Length; ++i)
            {
                using (Bitmap bitmap = new Bitmap(Path.Combine(prefix, textures[i])))
                {
                    //  Create a new texture and bind it.
                    var tex = new Texture2D();
                    tex.Create();
                    tex.Bind();
                    ModelObject.setTexture(i, tex.SetImage(bitmap));
                    _cacheTextureList.Add(tex);
                }
            }
            ModelObject.setPremultipliedAlpha(false);
            IsLoadComplete = true;
        }
Пример #3
0
        public override void OnUpdate()
        {
            var spec = framebuffer.FramebufferData;

            if (spec.Width > 0 && spec.Height > 0 && viewportSize != new Vector2(spec.Width, spec.Height))
            {
                framebuffer.Resize((int)viewportSize.X, (int)viewportSize.Y);
                var aspectRatio = viewportSize.X / viewportSize.Y;
                var zoomLevel   = 0.5f;
                orthoCamera.SetProjection(-aspectRatio * zoomLevel, aspectRatio * zoomLevel, -zoomLevel, zoomLevel);
            }

            framebuffer.Bind();

            if (Input.IsKeyPressed(Key.A))
            {
                orthoCamera.Position += new OpenTK.Mathematics.Vector3(1, 0, 0) * orthoCamera.Speed * (EnableDeltaTime ? Time.deltaTime : 1);
            }
            if (Input.IsKeyPressed(Key.D))
            {
                orthoCamera.Position += new OpenTK.Mathematics.Vector3(-1, 0, 0) * orthoCamera.Speed * (EnableDeltaTime ? Time.deltaTime : 1);
            }
            if (Input.IsKeyPressed(Key.W))
            {
                orthoCamera.Position += new OpenTK.Mathematics.Vector3(0, 1, 0) * orthoCamera.Speed * (EnableDeltaTime ? Time.deltaTime : 1);
            }
            if (Input.IsKeyPressed(Key.S))
            {
                orthoCamera.Position += new OpenTK.Mathematics.Vector3(0, -1, 0) * orthoCamera.Speed * (EnableDeltaTime ? Time.deltaTime : 1);
            }

            if (Input.IsKeyPressed(Key.Left))
            {
                squarePos += new Vector3(-1, 0, 0) * squareSpeed * (EnableDeltaTime ? Time.deltaTime : 1);
            }
            if (Input.IsKeyPressed(Key.Right))
            {
                squarePos += new Vector3(1, 0, 0) * squareSpeed * (EnableDeltaTime ? Time.deltaTime : 1);
            }
            if (Input.IsKeyPressed(Key.Up))
            {
                squarePos += new Vector3(0, 1, 0) * squareSpeed * (EnableDeltaTime ? Time.deltaTime : 1);
            }
            if (Input.IsKeyPressed(Key.Down))
            {
                squarePos += new Vector3(0, -1, 0) * squareSpeed * (EnableDeltaTime ? Time.deltaTime : 1);
            }

            Renderer.Clear();

            Renderer.BeginScene(orthoCamera);

            checkerboard.Bind();
            Renderer.Submit(vertexArray, shader, OpenTK.Mathematics.Matrix4.CreateTranslation(squarePos.ToVec3()));
            cherno.Bind();
            Renderer.Submit(vertexArray, shader, OpenTK.Mathematics.Matrix4.CreateTranslation(squarePos.ToVec3()));

            Renderer.EndScene();
            framebuffer.Unbind();
        }
Пример #4
0
        public override void OnRender(FrameEventArgs e)
        {
            ImmediateMode.MandatoryLogic();

            int width  = 100;
            int height = 100;

            angle += 3 * (float)e.Time;
            moveX += 100f * (float)e.Time;

            t.Position = new Vector2(mouseX, mouseY);
            t.Rotation = angle;
            t.Scale    = new Vector2(100, 100);
            shader.Bind();
            shader.SetMatrix("projectionMatrix", t.TransformationMatrix * projection);
            shader.SetVector("inputColor", new Vector4(0, 0, 1, 1));
            shader.SetInt("tex", 0);
            tex.Bind();
            batch.Begin();
            for (int x1 = 0; x1 < 1000; x1++)
            {
                batch.Submit(VertexFactory.GetQuad());
            }
            batch.End();
            tex.Unbind();
            shader.Unbind();
            // ImmediateMode.RenderQuad(x, y, 500, 500, new Vector4(1, 1, 1, 1));
            //ImmediateMode.RenderVerticies(new Vector2(x,y), new Vector2(100,100), angle, VertexGenerator.GetQuad(), PrimitiveType.Quads, Vector4.One);

            base.OnRender(e);
        }
Пример #5
0
        public static void RegenerateMipmapsFromTexture2D(NutTexture tex)
        {
            if (!TextureFormatTools.IsCompressed(tex.pixelInternalFormat))
            {
                return;
            }

            Rendering.OpenTkSharedResources.dummyResourceWindow.MakeCurrent();

            // Create an OpenGL texture with generated mipmaps.
            Texture2D texture2D = new Texture2D();

            texture2D.LoadImageData(tex.Width, tex.Height, tex.surfaces[0].mipmaps[0], (InternalFormat)tex.pixelInternalFormat);

            texture2D.Bind();

            for (int i = 0; i < tex.surfaces[0].mipmaps.Count; i++)
            {
                // Get the image size for the current mip level of the bound texture.
                int imageSize;
                GL.GetTexLevelParameter(TextureTarget.Texture2D, i,
                                        GetTextureParameter.TextureCompressedImageSize, out imageSize);

                byte[] mipLevelData = new byte[imageSize];

                // Replace the Nut texture with the OpenGL texture's data.
                GL.GetCompressedTexImage(TextureTarget.Texture2D, i, mipLevelData);
                tex.surfaces[0].mipmaps[i] = mipLevelData;
            }
        }
Пример #6
0
        public static void Init()
        {
            MissingTexture = new Texture2D();
            MissingTexture.Bind();

            MissingTexture.Param(TextureParameterName.TextureMagFilter, TextureMagFilter.Nearest);
            MissingTexture.Param(TextureParameterName.TextureMinFilter, TextureMinFilter.Nearest);
            MissingTexture.Param(TextureParameterName.TextureWrapS, TextureWrapMode.ClampToEdge);
            MissingTexture.Param(TextureParameterName.TextureWrapT, TextureWrapMode.ClampToEdge);

            const int width  = 16;
            const int height = 16;

            var pixels = new byte[height, width, 3];

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var isMagenta = x < 8 ^ y < 8;
                    pixels[y, x, 0] = isMagenta ? byte.MaxValue : byte.MinValue;
                    pixels[y, x, 1] = 0;
                    pixels[y, x, 2] = isMagenta ? byte.MaxValue : byte.MinValue;
                }
            }

            MissingTexture.Data(width, height, pixels);
        }
Пример #7
0
        protected override void DoRender(RenderEventArgs e)
        {
            if (blend)
            {
                GL.Enable(GL.GL_BLEND);
                GL.BlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
            }

            shaderProgram.Bind();

            shaderProgram.SetUniform(FontElement.strcolor, 1.0f, 1.0f, 1.0f, 1.0f);
            GL.ActiveTexture(GL.GL_TEXTURE0);
            GL.Enable(GL.GL_TEXTURE_2D);
            texture.Bind();
            shaderProgram.SetUniform(strtex, 0);

            this.shaderProgram.Bind();
            this.shaderProgram.SetUniformMatrix4(strMVP, mvp.to_array());

            GL.BindVertexArray(vao[0]);
            GL.DrawArrays(this.mode, 0, this.vertexCount);
            GL.BindVertexArray(0);

            texture.Unbind();
            this.shaderProgram.Unbind();
            if (blend)
            {
                GL.Disable(GL.GL_BLEND);
            }
        }
Пример #8
0
        public virtual void Bind( )
        {
            if (TCol != null)
            {
                TCol.Bind(0);
            }

            if (TNorm != null)
            {
                TNorm.Bind(1);
            }

            //if (TSpec != null) TSpec.Bind(2);

            if (TEnv != null)
            {
                TEnv.Bind(2);
            }

            if (TSpec != null)
            {
                TSpec.Bind(3);
            }

            Active = this;
        }
Пример #9
0
        public void Render(object Sender, FrameEventArgs E)
        {
            Timekeeper.Start();

            GL.Clear(ClearBufferMask.ColorBufferBit);

            // PlayerView.Setup(800, 800);
            // PlayerView.Update();
            //Spritebatch.Begin();
            Texture.Bind();
            //    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            CurrentShader.Enable();
            Sprite.mov(mov);
            Sprite.Draw();
            CurrentShader.Disable();

            //  GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GameScreen.SwapBuffers();



            frames++;
            if (Timekeeper.GetElapsed().Seconds == 1)
            {
                RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() FPS " + frames);
                Timekeeper.Reset();
                frames = 0;
            }
            // RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() MS " + Timekeeper.GetTime().Milliseconds.ToString());
        }
Пример #10
0
        //private void DrawInternal(Texture2D tex, Rectangle? srcRect, Rectangle destRect, Color4 color, Vector2 scale, float dx, float dy, float depth, float rot)
        //{
        //    if (CurrentTexture.TextureId != -1 && tex.TextureId != CurrentTexture.TextureId)
        //        Flush();

        //    CurrentTexture = tex;

        //    if (indexCount + 6 >= MAX_INDICES || vertexCount + 4 >= MAX_VERTICES)
        //        Flush();

        //    Rectangle src = srcRect ?? tex.Bounds;

        //    Quaternion quat = new Quaternion(rot, 0, 0);
        //    Vector2 pos = new Vector2(destRect.X, destRect.Y);
        //    Vector2 size = new Vector2(destRect.Width * scale.X, destRect.Height*scale.Y);

        //    float sin = (float)Math.Sin(rot);
        //    float cos = (float)Math.Sin(rot);

        //    float x = pos.X;
        //    float y = pos.Y;
        //    float w = size.X;
        //    float h = size.Y;

        //    // Top left
        //    Vertices[vertexCount++] = new Vertex2D(
        //        pos: new Vector3(x + dx * cos - dy * sin, y + dx * sin + dy * cos, depth),
        //        text: new Vector2(src.X / (float)tex.Width, src.Y / (float)tex.Height),
        //        color: color
        //    );

        //    // Top right
        //    Vertices[vertexCount++] = new Vertex2D(
        //        pos: new Vector3(
        //            x + (dx + w) * cos - dy * sin,
        //            y + (dx + w) * sin + dy * cos,
        //            depth
        //        ),
        //        text: new Vector2(
        //            (src.X + src.Width) / (float)tex.Width,
        //            src.Y / (float)tex.Height
        //        ),
        //        color: color
        //    );

        //    // Bottom Left
        //    Vertices[vertexCount++] = new Vertex2D(
        //        pos: new Vector3(
        //            x + dx * cos - (dy + h) * sin,
        //            y + dx * sin + (dy + h) * cos,
        //            depth
        //        ),
        //        text: new Vector2(
        //            src.X / (float)tex.Width,
        //            (src.Y + src.Height) / (float)tex.Height
        //        ),
        //        color: color
        //    );

        //    // Bottom Right
        //    Vertices[vertexCount++] = new Vertex2D(
        //        pos: new Vector3(
        //            x + (dx + w) * cos - (dy + h) * sin,
        //            y + (dx + w) * sin + (dy + h) * cos,
        //            depth
        //        ),
        //        text: new Vector2(
        //            (src.X + src.Width) / (float)tex.Width,
        //            (src.Y + src.Height) / (float)tex.Height
        //        ),
        //        color: color
        //    );

        //    indexCount += 6;

        //}

        public void Flush()
        {
            if (indexCount == 0)
            {
                return;
            }

            program.Use(() =>
            {
                GL.BindVertexArray(abo);

                vbo.UploadData(Vertices);

                vbo.PointTo(program.Attrib("v_pos"), 2, 0);
                vbo.PointTo(program.Attrib("v_tex"), 2, 3 * sizeof(float));
                vbo.PointTo(program.Attrib("v_col"), 4, 5 * sizeof(float));

                CurrentTexture.Bind();

                ibo.Bind();

                program["MVP"] = ViewProjectionMatrix;

                GL.DrawElements(BeginMode.Triangles, ibo.Buffer.Count, DrawElementsType.UnsignedInt, 0);

                GL.BindVertexArray(0);

                Array.Clear(Vertices, 0, Vertices.Length);

                vertexCount = 0;
                indexCount  = 0;
            });
        }
Пример #11
0
        void element_BeforeRendering(object sender, Objects.RenderEventArgs e)
        {
            var       element = sender as FontElement;
            Texture2D texture = element.texture;

            texture.Bind();

            if (element.blend)
            {
                GL.Enable(GL.GL_BLEND);
                GL.BlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
            }

            ShaderProgram shaderProgram = element.shaderProgram;

            shaderProgram.Bind();

            shaderProgram.SetUniform(FontElement.strcolor, 1.0f, 1.0f, 1.0f, 1.0f);
            shaderProgram.SetUniform(FontElement.strtex, texture.Name);

            mat4 projectionMatrix = this.camera.GetProjectionMat4();
            mat4 viewMatrix       = this.camera.GetViewMat4();
            mat4 modelMatrix      = mat4.identity();
            IMVP iMVP             = sender as IMVP;

            iMVP.SetShaderProgram(projectionMatrix * viewMatrix * modelMatrix);
        }
Пример #12
0
        protected override void Render()
        {
            shader.Use();

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    var e = board[x, y];

                    if (e == 'X')
                    {
                        xtexture.Bind(OpenTK.Graphics.OpenGL4.TextureUnit.Texture0);
                    }
                    else if (e == 'O')
                    {
                        otexture.Bind(OpenTK.Graphics.OpenGL4.TextureUnit.Texture0);
                    }
                    else
                    {
                        Texture2D.Unbind();
                    }

                    shader.SetVec2("offset", x - 1, y - 1);
                    vao.DrawElements(OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, 6, OpenTK.Graphics.OpenGL4.DrawElementsType.UnsignedInt);
                }
            }
        }
Пример #13
0
        public static Texture2D CreateTexture2D(NutTexture nutTexture, int surfaceIndex = 0)
        {
            bool compressedFormatWithMipMaps = nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgbaS3tcDxt1Ext ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgbaS3tcDxt3Ext ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgbaS3tcDxt5Ext ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRedRgtc1 ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgRgtc2;

            if (compressedFormatWithMipMaps)
            {
                if (nutTexture.surfaces[0].mipmaps.Count > 1 && nutTexture.isDds)
                {
                    // Reading mip maps past the first level is only supported for DDS currently.
                    return(new Texture2D(nutTexture.Width, nutTexture.Height, nutTexture.surfaces[surfaceIndex].mipmaps, true,
                                         (InternalFormat)nutTexture.pixelInternalFormat));
                }
                else
                {
                    // Only load the first level and generate the rest.
                    return(new Texture2D(nutTexture.Width, nutTexture.Height,
                                         nutTexture.surfaces[surfaceIndex].mipmaps, false,
                                         (InternalFormat)nutTexture.pixelInternalFormat));
                }
            }
            else
            {
                Texture2D texture = new Texture2D(nutTexture.Width, nutTexture.Height);
                texture.Bind();
                AutoGenerateMipMaps(nutTexture);
                return(texture);
            }
        }
Пример #14
0
        /// <summary>
        /// Bind the material
        /// </summary>
        public void Bind()
        {
            ShaderProgram.Bind();

            Matrix4 projection = Camera.Current.Projection;

            GL.UniformMatrix4(ShaderMembers[0].Location, false, ref projection);

            Matrix4 view = Camera.Current.View;

            GL.UniformMatrix4(ShaderMembers[1].Location, false, ref view);

            GameObject go = SceneManager.CurrentScene.CurrentObject;

            if (go != null)
            {
                Matrix4 model = Matrix4.Identity;

                Vector3 axis;
                float   angle;

                go.LocalTransform.Rotation.ToAxisAngle(out axis, out angle);

                model *= Matrix4.CreateScale(go.LocalTransform.Scale);

                model *= Matrix4.CreateFromAxisAngle(axis, angle);

                model *= Matrix4.CreateTranslation(go.LocalTransform.Position);

                GL.UniformMatrix4(ShaderMembers[2].Location, false, ref model);
            }

            int locDiffuse = ShaderProgram.GetVariableLocation("diffuseMap");

            GL.Uniform1(locDiffuse, 0);
            DiffuseTexture?.Bind();

            GameObject[] lights = GameObject.FindWithComponent <Light>();

            if (lights.Length > 0)
            {
                int locNormal = ShaderProgram.GetVariableLocation("normalMap");

                GL.Uniform1(locNormal, 1);
                NormalTexture?.Bind();

                foreach (GameObject light in lights) // TODO: fix this in shader
                {
                    int lightPosition = ShaderProgram.GetVariableLocation("lightPos");
                    GL.Uniform3(lightPosition, light.LocalTransform.Position);
                }

                int camPosition = ShaderProgram.GetVariableLocation("viewPos");
                GL.Uniform3(camPosition, Camera.Current.Parent.LocalTransform.Position);

                int normalMappingTrueLoc = ShaderProgram.GetVariableLocation("normalMapping");
                GL.Uniform1(normalMappingTrueLoc, 1);
            }
        }
Пример #15
0
 protected virtual void CreateTextureBuffer(int width, int height)
 {
     _textureBuffer = new Texture2D();
     _textureBuffer.Bind();
     _textureBuffer.SetStorage(width, height);
     _framebuffer.AttachTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, _textureBuffer, 0);
     _textureBuffer.Unbind();
 }
Пример #16
0
        public static void DrawTexturedQuad(Matrix4 transform, Texture2D texture, Vector2 size, Vector4 texCoords, float yOffset = 0)
        {
            bool wasTexEnabled = GL.IsEnabled(EnableCap.Texture2D);

            GL.Enable(EnableCap.Texture2D);

            var positions = new Vector4(0, 0, size.X, size.Y);

            VertVT CreateVert(Vector2 pos, Vector2 tex)
            {
                return(new VertVT(new Vector3(pos.X, yOffset, pos.Y), tex));
            }

            var quadVerts = new VertVT[]
            {
                CreateVert(positions.Xy, texCoords.Xy),
                CreateVert(positions.Xw, texCoords.Xw),
                CreateVert(positions.Zw, texCoords.Zw),
                CreateVert(positions.Zy, texCoords.Zy)
            };

            SimpleTextureShader.Use();
            SimpleTextureShader.ModelMatrix.Set(transform);
            texture.Bind(TextureUnit.Texture5);
            SimpleTextureShader.Texture.Set(TextureUnit.Texture5);
            //SimpleTextureShader.Texture.BindTexture(TextureUnit.Texture5, texture);

            var vertBuffer = new VertexArrayBuffer <VertVT>();

            vertBuffer.SetElements(quadVerts);
            vertBuffer.Bind();
            vertBuffer.BindAttribute(SimpleTextureShader.Position, 0);
            vertBuffer.BindAttribute(SimpleTextureShader.TexCoord, 12);

            vertBuffer.DrawArray(PrimitiveType.Quads, 0, 4);
            vertBuffer.Dispose();

            SimpleTextureShader.Texture.Set(TextureUnit.Texture0);
            texture.Bind(TextureUnit.Texture0);

            if (!wasTexEnabled)
            {
                GL.Disable(EnableCap.Texture2D);
            }
        }
Пример #17
0
 /// <summary>
 /// Draws the sprite.
 /// </summary>
 public void Draw()
 {
     Texture.Bind();
     VBO.BindVertexArray();
     //GL.DrawArrays(PrimitiveType.Triangles, 0, 4);
     VBO.BindIndexBuffer();
     GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, 0);
     Texture.Unbind();
 }
Пример #18
0
 public void DrawTexture(Texture2D texture)
 {
     GL.Viewport(this.ViewportRect);
     texture.Bind();
     this.ViewportShader.Use(shader => {
         this.ViewportTarget.Geometry.Material.Diffuse = texture;
         this.ViewportTarget.Position = new Vector3(this.Position.X, this.Position.Y, 0);
         this.ViewportTarget.Draw(shader, Matrix);
     });
 }
Пример #19
0
 public static void RectBlur2(int x, int y, int w, int h, Texture2D img, Vector4 col, float blur)
 {
     BFX2.Col  = col;
     BFX2.Blur = blur;
     Bind();
     GenQuad(x, y, w, h, col, col);
     img.Bind(0);
     DraqQuadBlur2();
     img.Release(0);
     Release();
 }
Пример #20
0
        /// <summary>
        /// Binds a texture to a sampler in the shader
        /// TODO: Refactor or remove this
        /// </summary>
        /// <param name="textureUnit">The texture unit to bind the texture to</param>
        /// <param name="uniform">The uniform name where the texture should be bound.</param>
        /// <param name="texture">The texture to bind.</param>
        public void BindTexture2D(TextureUnit textureUnit, TextureUniform uniform, Texture2D texture)
        {
            Enable();

            GL.ActiveTexture(textureUnit);
            texture.Bind();

            int textureVariableHandle = GL.GetUniformLocation(this.NativeShaderProgramID, uniform.ToString());

            GL.Uniform1(textureVariableHandle, (int)uniform);
        }
Пример #21
0
        /// <summary>
        /// Draws the sprite.
        /// </summary>
        public void Draw()
        {
            if (Texture == null)
            {
                Rect.Draw();
                return;
            }

            Texture.Bind();
            Rect.Draw();
            Texture.Unbind();
        }
Пример #22
0
        //------------------------------------------------------------------------------------------------------------------------
        //														RenderSelf()
        //------------------------------------------------------------------------------------------------------------------------
        protected override void RenderSelf(GLContext glContext)
        {
            if (game != null)
            {
                Vector2[] bounds = GetExtents();
                float     maxX   = float.MinValue;
                float     maxY   = float.MinValue;
                float     minX   = float.MaxValue;
                float     minY   = float.MaxValue;
                for (int i = 0; i < 4; i++)
                {
                    if (bounds[i].x > maxX)
                    {
                        maxX = bounds[i].x;
                    }
                    if (bounds[i].x < minX)
                    {
                        minX = bounds[i].x;
                    }
                    if (bounds[i].y > maxY)
                    {
                        maxY = bounds[i].y;
                    }
                    if (bounds[i].y < minY)
                    {
                        minY = bounds[i].y;
                    }
                }

                bool test = (maxX < game.RenderRange.left) || (maxY < game.RenderRange.top) ||
                            (minX >= game.RenderRange.right) || (minY >= game.RenderRange.bottom);
                if (test == false)
                {
                    if (blendMode != null)
                    {
                        blendMode.enable();
                    }
                    _texture.Bind();
                    glContext.SetColor((byte)((_color >> 16) & 0xFF),
                                       (byte)((_color >> 8) & 0xFF),
                                       (byte)(_color & 0xFF),
                                       (byte)(_alpha * 0xFF));
                    glContext.DrawQuad(GetArea(), _uvs);
                    glContext.SetColor(1, 1, 1, 1);
                    _texture.Unbind();
                    if (blendMode != null)
                    {
                        BlendMode.NORMAL.enable();
                    }
                }
            }
        }
Пример #23
0
        public override void PostRender(Texture2D bb)
        {
            BBloom.Bind( );

            FusionEngine.PostProcess.PostProcessRender.PBuf.BB.Bind(0);
            pi.Bind(1);

            DrawQuad( );

            pi.Release(1);
            FusionEngine.PostProcess.PostProcessRender.PBuf.BB.Release(0);
            BBloom.Release( );
        }
Пример #24
0
        /// <summary>
        /// Sets the texture of the shader.
        /// </summary>
        /// <param name="texture">The texture.</param>
        public void SetTexture(Texture2D texture)
        {
            Enable();

            GL.ActiveTexture(TextureUnit.Texture0);

            texture.Bind();

            int textureVariableHandle = GL.GetUniformLocation(this.NativeShaderProgramID, TextureIdentifier);
            int textureUnit           = 0;

            GL.Uniform1(textureVariableHandle, 1, ref textureUnit);
        }
Пример #25
0
 //------------------------------------------------------------------------------------------------------------------------
 //														Render()
 //------------------------------------------------------------------------------------------------------------------------
 override protected void RenderSelf(GLContext glContext)
 {
     if (_invalidate)
     {
         _texture.UpdateGLTexture();
         _invalidate = false;
     }
     _texture.Bind();
     glContext.SetColor((byte)((_color >> 16) & 0xFF),
                        (byte)((_color >> 8) & 0xFF),
                        (byte)(_color & 0xFF),
                        _alpha);
     glContext.DrawQuad(_bounds, _uvs);
     _texture.Unbind();
 }
Пример #26
0
        public static Texture2D GenerateTexture(int[] pixelArray, int width, int height)
        {
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            var texture = new Texture2D(width, height);

            texture.Bind();
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0,
                          OpenTK.Graphics.OpenGL4.PixelFormat.Rgba, PixelType.UnsignedByte, pixelArray);

            Console.WriteLine(GL.GetError().ToString());

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            return(texture);
        }
Пример #27
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Viewport(0, 0, Width, Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            vao.Bind();
            shader.Bind();
            shader.Uniform1("tex", 0);
            GL.ActiveTexture(TextureUnit.Texture0);
            texture.Bind();
            indexVbo.Bind();
            GL.DrawElements(BeginMode.Triangles, indexVbo.Length,
                            DrawElementsType.UnsignedInt, IntPtr.Zero);

            SwapBuffers();
        }
Пример #28
0
 public static void Rect(int x, int y, int w, int h, Texture2D img, Vector4 tc, Vector4 bc)
 {
     QFX.Col = tc;
     Bind( );
     GenQuad(x, y, w, h, tc, bc);
     img.Bind(0);
     DrawQuad( );
     img.Release(0);
     // GL.Begin(BeginMode.Quads);
     // GL.Vertex2(x, y);
     //GL.Vertex2(x + width, y);
     //GL.Vertex2(x + width, y + height);
     //GL.Vertex2(x, y + height);
     //GL.End();
     Release( );
 }
Пример #29
0
        protected override void OnLoad()
        {
            GL.ClearColor(Color4.CornflowerBlue);

            FadeSettings = FadeSettings.Default();

            _renderProgram = RenderProgram.Create();

            _textureOut = new Texture2D(SizedInternalFormat.Rgba8, _width, _height);
            _textureOut.SetFilter(TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            _textureOut.Bind(TextureUnit.Texture0);

            _agentProgram = AgentProgram.Create(_width, _height, _textureOut, _numberOfAgents, AgentSettings.Default());

            _fadeProgram = FadeProgram.Create(_width, _height, _textureOut, FadeSettings.Default());
        }
Пример #30
0
 private void CreateTextures(OpenGL gl, IEnumerable <Mesh> meshes)
 {
     foreach (var mesh in meshes.Where(m => m.material.TextureMapDiffuse != null))
     {
         //  Create a new texture and bind it.
         var texture = new Texture2D();
         texture.Create(gl);
         texture.Bind(gl);
         texture.SetParameter(gl, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
         texture.SetParameter(gl, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
         texture.SetParameter(gl, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP_TO_EDGE);
         texture.SetParameter(gl, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP_TO_EDGE);
         texture.SetImage(gl, (Bitmap)mesh.material.TextureMapDiffuse.Image);
         texture.Unbind(gl);
         meshTextures[mesh] = texture;
     }
 }
Пример #31
0
 public void DrawTexture(Texture2D texture)
 {
     GL.Viewport (this.ViewportRect);
     texture.Bind ();
     this.ViewportShader.Use (shader => {
         this.ViewportTarget.Geometry.Material.Diffuse = texture;
         this.ViewportTarget.Position = new Vector3(this.Position.X, this.Position.Y, 0);
         this.ViewportTarget.Draw (shader, Matrix);
     });
 }