コード例 #1
0
ファイル: HelloTriangleWindow.cs プロジェクト: Lazzu/Hatzap
        protected override void OnLoad(EventArgs e)
        {
            PackageManager.BasePath = "../../Assets/";

            // Load shaders
            ShaderManager.LoadCollection("Shaders/collection.xml");
            shader = ShaderManager.Get("hellotriangle");

            // Generate triangle
            batch = new VertexBatch();
            batch.StartBatch(PrimitiveType.Triangles);
            batch.Add(new Vector3(-1, -1, 0)); // Bottom left
            batch.Add(new Vector3(1, -1, 0));  // Bottom right
            batch.Add(new Vector3(0, 1, 0));  // Top
            batch.EndBatch();
        }
コード例 #2
0
ファイル: TextureExampleWindow.cs プロジェクト: Lazzu/Hatzap
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            PackageManager.BasePath = "../../Assets/";

            // Load shaders
            ShaderManager.LoadCollection("Shaders/collection.xml");
            shader = ShaderManager.Get("texturedquad");

            // Create screen-filling quad
            batch = new VertexBatch();
            batch.StartBatch(PrimitiveType.TriangleStrip);
            batch.Add(new Vector3(-1, -1, 0)); // Bottom left
            batch.Add(new Vector3(1, -1, 0));  // Bottom right
            batch.Add(new Vector3(-1, 1, 0));  // Top left
            batch.Add(new Vector3(1, 1, 0));   // Top Right
            batch.EndBatch();

            // Load texture
            textures = new TextureManager();
            texture = textures.Get("Textures/concreteslabs.tex", true);
        }
コード例 #3
0
ファイル: Framebuffer.cs プロジェクト: Lazzu/Hatzap
        void Initialize()
        {
            var textureQuality = new TextureQuality()
            {
                TextureWrapMode = TextureWrapMode.ClampToEdge,
                Filtering = TextureFiltering.Nearest,
            };

            TextureTarget target;

            int texID = GL.GenTexture();
            var msaa = GL.GetInteger(GetPName.MaxSamples);

            if (MSAA < 0)
                MSAA = 0;

            if (MSAA > msaa)
                MSAA = msaa;

            switch(MSAA)
            {
                case 1:
                case 2:
                case 4:
                case 8:
                case 16:
                case 32:
                case 64:
                case 128:
                case 256:
                    target = TextureTarget.Texture2DMultisample;

                    GL.BindTexture(target, texID);
                    GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, MSAA, PixelInternalFormat.Rgba, Width, Height, true);

                    break;
                default:
                    target = TextureTarget.Texture2D;

                    GL.BindTexture(target, texID);
                    GL.TexImage2D(target, 0, PixelInternalFormat.Rgba, Width, Height, 0, PixelFormat.Rgba, PixelType.Byte, IntPtr.Zero);

                    break;
            }

            GL.BindTexture(target, 0);

            Texture = new Texture(texID, Width, Height, target, PixelInternalFormat.Rgba);
            Texture.Quality = textureQuality;

            Texture.Bind();
            Texture.UpdateQuality();
            Texture.UnBind();

            /*texture.Bind();
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1); // automatic mipmap
            texture.UnBind();*/

            // create a renderbuffer object to store depth info
            GL.GenRenderbuffers(1, out rboId);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rboId);

            if(MSAA > 0)
            {
                GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, MSAA, RenderbufferStorage.DepthComponent32, Width, Height);
            }
            else
            {
                GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent32, Width, Height);
            }

            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);

            // create a framebuffer object
            GL.GenFramebuffers(1, out fbo);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo);

            // attach the texture to FBO color attachment point
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer,        // 1. fbo target: GL_FRAMEBUFFER
                                   FramebufferAttachment.ColorAttachment0,  // 2. attachment point
                                   Texture.TextureTarget,         // 3. tex target: GL_TEXTURE_2D
                                   Texture.ID,             // 4. tex ID
                                   0);                    // 5. mipmap level: 0(base)

            // attach the renderbuffer to depth attachment point
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer,      // 1. fbo target: GL_FRAMEBUFFER
                                      FramebufferAttachment.DepthAttachment, // 2. attachment point
                                      RenderbufferTarget.Renderbuffer,     // 3. rbo target: GL_RENDERBUFFER
                                      rboId);              // 4. rbo ID

            // check FBO status
            var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            if (status != FramebufferErrorCode.FramebufferComplete)
            {
                Complete = false;
                Console.WriteLine("ERROR: Can not create framebuffer because " + status.ToString());
            }
            else
            {
                Complete = true;
            }

            // switch back to window-system-provided framebuffer
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            if (!Complete)
                return;

            var error = GL.GetError();

            while(error != ErrorCode.NoError)
            {
                Debug.WriteLine("Error creating FBO: " + error.ToString());
                error = GL.GetError();
            }

            batch = new VertexBatch();
            batch.StartBatch(PrimitiveType.Triangles);
            batch.Add(new Vector3(-1, -1, 0)); // Bottom left
            batch.Add(new Vector3(1, -1, 0));  // Bottom right
            batch.Add(new Vector3(-1, 1, 0));  // Top left
            batch.Add(new Vector3(1, -1, 0));  // Bottom right
            batch.Add(new Vector3(1, 1, 0)); // Top right
            batch.Add(new Vector3(-1, 1, 0));  // Top left
            batch.EndBatch();
        }