Exemplo n.º 1
0
        public void Init()
        {
            a = EPrimitiveMesh.GetPrimitiveMesh(EPrimitiveMesh.PrimitiveType.ScreenPlane);
            b = new EGammaCorrectionMat();

            sceneBuffer = new TextureFrameBuffer();

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, sceneBuffer.frameBuffer);

            GL.BindTexture(TextureTarget.Texture2D, sceneBuffer.texture); // color
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                          EWindow.GLWidth, EWindow.GLHeight,
                          0, (PixelFormat)PixelInternalFormat.Rgba, PixelType.UnsignedByte,
                          IntPtr.Zero);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.BindTexture(TextureTarget.Texture2D, sceneBuffer.texture2); // depth
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent32,
                          EWindow.GLWidth, EWindow.GLHeight,
                          0, (PixelFormat)PixelInternalFormat.DepthComponent, PixelType.Int,
                          IntPtr.Zero);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            ////Create color attachment texture
            GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, sceneBuffer.texture, 0);
            GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, sceneBuffer.texture2, 0);

            //No need for renderbuffer object since we don't need stencil buffer yet
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
Exemplo n.º 2
0
        public static EMesh GetPrimitiveMesh(PrimitiveType type)
        {
            switch (type)
            {
            case PrimitiveType.Cube:
            {
                EMesh cube = new EMesh("Cube");
                cube.Load(EEngine.BuildIn + "cube.obj");
                cube.Compile();
                return(cube);
            }

            case PrimitiveType.Plane:
            {
                EMesh plane = new EMesh("Plane");
                plane.Load(EEngine.BuildIn + "plane.obj");
                plane.Compile();
                return(plane);
            }

            case PrimitiveType.Triangle:
            {
                break;
            }

            case PrimitiveType.Sphere:
            {
                EMesh sphere = new EMesh("Sphere");
                sphere.Load(EEngine.BuildIn + "sphere.obj");
                sphere.Compile();
                return(sphere);
            }

            case PrimitiveType.Cone:
            {
                break;
            }

            case PrimitiveType.Capsule:
            {
                break;
            }

            case PrimitiveType.Cylinder:
            {
                break;
            }

            case PrimitiveType.torus:
            {
                break;
            }

            case PrimitiveType.ScreenPlane:
            {
                EMesh screenPlane = new EMesh("ScreenPlane");
                screenPlane.vertice = new Vector3[]
                {
                    new Vector3(-1f, 1f, 0),
                    new Vector3(1f, 1f, 0),
                    new Vector3(1f, -1f, 0),
                    new Vector3(-1f, -1f, 0),
                };
                screenPlane.textureCoordinate = new Vector2[]
                {
                    new Vector2(0, 1),
                    new Vector2(1, 1),
                    new Vector2(1, 0),
                    new Vector2(0, 0),
                };
                screenPlane.normal = new Vector3[]
                {
                    new Vector3(0, 0, 1)
                };
                screenPlane.faces = new EFace[][]
                {
                    new EFace[]
                    {
                        new EFace {
                            normal = 0, uv = 0, vertex = 0
                        },
                        new EFace {
                            normal = 0, uv = 1, vertex = 1
                        },
                        new EFace {
                            normal = 0, uv = 2, vertex = 2
                        },
                        new EFace {
                            normal = 0, uv = 3, vertex = 3
                        },
                    }
                };
                screenPlane.Compile();
                return(screenPlane);
            }
            }
            return(null);
        }