Exemple #1
0
 public void OnClosed(EventArgs e)
 {
     entryPoint.OnClose();
     RenderEngine.CleanUp();
     GL.BindVertexArray(0);
     GL.BindTexture(TextureTarget.Texture2D, 0);
     GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
     GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
     RenderDataLoader.CleanUp();
 }
        public void OnClose()
        {
            standardMaterial.Shader.CleanUp();
            uiMaterial.Shader.CleanUp();
            arialFontMaterial.Shader.CleanUp();
            invertColorPostProcessing.CleanUp();

            RenderDataLoader.DeleteFrameBuffer(camera.fboId);
            RenderDataLoader.DeleteRenderBuffer(camera.bufId);
            RenderDataLoader.DeleteTexture(camera.texId);

            RenderDataLoader.DeleteFrameBuffer(secondCamera.fboId);
            RenderDataLoader.DeleteRenderBuffer(secondCamera.bufId);
            RenderDataLoader.DeleteTexture(secondCamera.texId);
        }
        public static Mesh RegenerateMesh(string text, FontData font, Mesh mesh, double fontSize, double lineHeight)
        {
            char[] chars = text.ToCharArray();

            Queue <Vector3d> positions     = new Queue <Vector3d>();
            Queue <Vector2d> textureCoords = new Queue <Vector2d>();
            Queue <int>      triangles     = new Queue <int>();

            double cursorPosition = 0;
            int    lineNumber     = 0;

            for (int i = 0; i < chars.Length; i++)
            {
                if (chars[i] == '\n')
                {
                    cursorPosition = 0;
                    lineNumber++;
                }
                else if (font.characterData.ContainsKey(chars[i]))
                {
                    FontData.CharacterData charData = font.characterData[chars[i]];
                    triangles.Enqueue(positions.Count);
                    triangles.Enqueue(positions.Count + 1);
                    triangles.Enqueue(positions.Count + 2);
                    triangles.Enqueue(positions.Count + 2);
                    triangles.Enqueue(positions.Count + 3);
                    triangles.Enqueue(positions.Count);

                    positions.Enqueue(new Vector3d(cursorPosition + charData.CharacterOffset.X * fontSize, -lineNumber * lineHeight * fontSize - charData.CharacterOffset.Y * fontSize, 0));
                    positions.Enqueue(new Vector3d(cursorPosition + charData.CharacterOffset.X * fontSize, -lineNumber * lineHeight * fontSize - charData.CharacterOffset.Y * fontSize - charData.Height * fontSize, 0));
                    positions.Enqueue(new Vector3d(cursorPosition + charData.CharacterOffset.X * fontSize + charData.Width * fontSize, -lineNumber * lineHeight * fontSize - charData.CharacterOffset.Y * fontSize - charData.Height * fontSize, 0));
                    positions.Enqueue(new Vector3d(cursorPosition + charData.CharacterOffset.X * fontSize + charData.Width * fontSize, -lineNumber * lineHeight * fontSize - charData.CharacterOffset.Y * fontSize, 0));

                    textureCoords.Enqueue(charData.CharacterTopLeft);
                    textureCoords.Enqueue(new Vector2d(charData.CharacterTopLeft.X, charData.CharacterBottomRight.Y));
                    textureCoords.Enqueue(charData.CharacterBottomRight);
                    textureCoords.Enqueue(new Vector2d(charData.CharacterBottomRight.X, charData.CharacterTopLeft.Y));

                    cursorPosition += charData.XAdvance * fontSize;
                }
                else
                {
                    cursorPosition += 20 * fontSize;
                }
            }

            return(RenderDataLoader.LoadMeshData2d(positions.ToArray(), triangles.ToArray(), textureCoords.ToArray(), mesh.VaoID));
        }
        public void OnLoad()
        {
            arialFont                 = new FontData("Arial", "./Game/Fonts/Arial.fnt", 1024);
            arialFontMaterial         = new Material(new UIShader(arialFont.TextureId), false, false, false);
            invertColorPostProcessing = new InvertedColorPostProcessing();
            engineStartTime           = DateTime.UtcNow;

            light        = new Light(new Vector3d(10000000, 10000000, 10000000), new Vector3d(0, 1, 0), 100000000, 3f);
            mainLight    = new Light(new Vector3d(-10000000, 10000000, 10000000), new Vector3d(1, 0, 0), 100000000, 3f);
            anotherLight = new Light(new Vector3d(0, -10000000, 10000000), new Vector3d(0, 0, 1), 100000000, 3f);
            camera       = new Camera(RenderDataLoader.GenerateFrameBuffer(), RenderDataLoader.GenerateTexture(), RenderDataLoader.GenerateRenderBuffer())
            {
                Position       = new Vector3d(0, 0, 5),
                Rotation       = new Vector3d(0, 0, 0),
                FarPlane       = 1000f,
                NearPlane      = 0.01f,
                FOV            = 60,
                IsPerspective  = true,
                ViewPortOffset = Vector2.Zero,
                ViewPortSize   = Vector2.One,
                ClearColor     = new Vector4(0.2f, 0.2f, 0.2f, 1f)
            };

            secondCamera = new Camera(RenderDataLoader.GenerateFrameBuffer(), RenderDataLoader.GenerateTexture(), RenderDataLoader.GenerateRenderBuffer())
            {
                Position       = new Vector3d(0, 0, 0),
                Rotation       = new Vector3d(0, 0, 0),
                FarPlane       = 1000f,
                NearPlane      = 0.01f,
                FOV            = 60,
                IsPerspective  = true,
                ViewPortOffset = Vector2.One * -0.5f,
                ViewPortSize   = Vector2.One * 0.5f,
                ClearColor     = new Vector4(0, 0, 0, 0),
                PostProcessing = new Material(invertColorPostProcessing, false, false, false)
            };

            treeMesh = OBJLoader.LoadObjModel("Tree");

            treeTexture      = RenderDataLoader.LoadTexture("Tree");
            standardMaterial = new Material(new StaticShader(treeTexture), true, true, false);
            uiMaterial       = new Material(new UIShader(treeTexture), false, false, false);
        }
        public FontData(string textureLocation, string fontLocation, int resolution)
        {
            TextureId = RenderDataLoader.LoadTexture(textureLocation);

            ParseFontFile(fontLocation, resolution);
        }