Example #1
0
        public static ShaderProgram Load(ShaderProgramInfo shaderProgram)
        {
            ShaderProgram program = new ShaderProgram(shaderProgram.Name);

            List<Shader> shaders = new List<Shader>();

            foreach (var shader in shaderProgram.Shaders)
            {
                Shader s = LoadShader(shader.Path, shader.Type);
                if(s != null)
                {
                    program.AttachShader(s);
                    shaders.Add(s);
                }
                else
                {
                    Debug.WriteLine("Unable to load {1} file {0}", shader.Path, shader.Type);
                }
            }

            program.Link();

            foreach (var shader in shaders)
            {
                shader.Destroy();
            }

            programs.Add(program.Name, program);

            return program;
        }
Example #2
0
        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();
        }
Example #3
0
        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);
        }
Example #4
0
        protected override void OnLoad(EventArgs e)
        {
            PackageManager.BasePath = "../../Assets/";

            ShaderManager.LoadCollection("Shaders/collection.xml");

            shader = ShaderManager.Get("Text");

            //FontManager.LoadCollection("Fonts/fontCollection.fnt");
            //font = FontManager.Get("Arial");

            textures = new TextureManager();

            font = new Font();
            font.LoadBMFont("Fonts/OpenSans-Regular.ttf_sdf.txt");
            font.Texture = textures.Get("Textures/OpenSans-Regular.ttf_sdf.tex", true);

            text = new GuiText();
            text.Font = font;

            text.Text = "This is rendered with SDF technology! (now you should say ooooooooh!)";

            text.HorizontalAlignment = HorizontalAlignment.Centered;
        }
Example #5
0
        protected override void OnLoad(EventArgs e)
        {
            Debug.WriteLine("OnLoad()");

            /*thread = new Thread(new ThreadStart(() =>
            {
                view = WebCore.CreateWebView(Width, Height, WebViewType.Offscreen);

                //WebCore.AutoUpdatePeriod = 30;

                view.IsTransparent = true;

                finishedLoading = false;

                var path = Path.Combine(new String[] {
                    Directory.GetCurrentDirectory(),
                    "TestWebPages\\index.html"
                });

                path = "http://lasoft.fi/";

                // Load some content.
                view.Source = new Uri(path);

                // Handle the LoadingFrameComplete event.
                // For this example, we use a lambda expression.
                view.LoadingFrameComplete += (s, eargs) =>
                {
                    if (!eargs.IsMainFrame)
                        return;

                    UploadWebpageToGPU((WebView)s);
                    finishedLoading = true;
                };

                if (WebCore.UpdateState == WebCoreUpdateState.NotUpdating)
                    WebCore.Run();

            }));

            thread.Start();*/

            GPUCapabilities.Initialize();

            Debug.WriteLine("GPUCapabilities.Version=" + GPUCapabilities.Version);
            Debug.WriteLine("GPUCapabilities.GLSL=" + GPUCapabilities.GLSL);
            Debug.WriteLine("GPUCapabilities.Instancing=" + GPUCapabilities.Instancing);
            Debug.WriteLine("GPUCapabilities.MaxVaryingFloats=" + GPUCapabilities.MaxVaryingFloats);
            Debug.WriteLine("GPUCapabilities.MaxVaryingVectors=" + GPUCapabilities.MaxVaryingVectors);
            Debug.WriteLine("GPUCapabilities.SeamlessCubemaps=" + GPUCapabilities.SeamlessCubemaps);
            Debug.WriteLine("GPUCapabilities.TextureCompression=" + GPUCapabilities.TextureCompression);
            Debug.WriteLine("GPUCapabilities.AnisotrophicFiltering=" + GPUCapabilities.AnisotrophicFiltering);
            Debug.WriteLine("GPUCapabilities.MaxAnisotrophyLevel=" + GPUCapabilities.MaxAnisotrophyLevel);

            if (GPUCapabilities.SeamlessCubemaps)
                GL.Enable(EnableCap.TextureCubeMapSeamless);

            GLState.DepthTest = true;
            GLState.AlphaBleding = true;
            GLState.CullFace = true;

            SceneManager.Initialize(500, 5, 20, Vector3.Zero);
            SceneManager.CullByObject = false;

            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = true;

            viewPort = new Vector2(Width, Height);

            camera = new Hatzap.Camera(this);

            camera.SetAsCurrent();

            camera.Position = new Vector3(0, 1, 1);
            camera.Target = new Vector3(-1, 0, 0);

            camera.Update(0);
            camera.DirectionLock = true;

            camera.Rotate(new Vector2(-(float)Math.PI / 2.5f, 0));

            // Now camera.Position changes whenever Target changes, and the camera angle stays locked.
            // Camera's distance from it's target can be controlled from camera.Distance property now.

            FontCollection fonts = new FontCollection();

            fonts.Fonts.Add(new FontInfo()
            {
                FontFamily = "OpenSans-Regular",
                FontDataFile = "Assets/Fonts/OpenSans-Regular.ttf_sdf.txt",
                FontTextureFile = "Assets/Fonts/OpenSans-Regular.ttf_sdf.png"
            });

            XML.Write.ToFile(fonts, "Assets/Fonts/collection.xml");

            //Console.WriteLine("Test test ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ");

            FontManager.LoadCollection(fonts);

            ShaderCollection collection = new ShaderCollection();

            collection.ShaderPrograms.Add(new ShaderProgramInfo()
            {
                Shaders = new List<ShaderInfo>(new[]{ new ShaderInfo() {
                    Path = "Assets/Shaders/Model.vert",
                    Type = ShaderType.VertexShader
                },new ShaderInfo() {
                    Path = "Assets/Shaders/Model.frag",
                    Type = ShaderType.FragmentShader
                }}),
                Name = "Model"
            });

            collection.ShaderPrograms.Add(new ShaderProgramInfo()
            {
                Shaders = new List<ShaderInfo>(new[]{ new ShaderInfo() {
                    Path = "Assets/Shaders/Text.vert",
                    Type = ShaderType.VertexShader
                },new ShaderInfo() {
                    Path = "Assets/Shaders/Text.frag",
                    Type = ShaderType.FragmentShader
                }}),
                Name = "Text"
            });

            collection.ShaderPrograms.Add(new ShaderProgramInfo()
            {
                Shaders = new List<ShaderInfo>(new[]{ new ShaderInfo() {
                    Path = "Assets/Shaders/Gui.vert",
                    Type = ShaderType.VertexShader
                },new ShaderInfo() {
                    Path = "Assets/Shaders/Gui.frag",
                    Type = ShaderType.FragmentShader
                }}),
                Name = "Gui"
            });

            collection.ShaderPrograms.Add(new ShaderProgramInfo()
            {
                Shaders = new List<ShaderInfo>(new[]{ new ShaderInfo() {
                    Path = "Assets/Shaders/GuiImage.vert",
                    Type = ShaderType.VertexShader
                },new ShaderInfo() {
                    Path = "Assets/Shaders/GuiImage.frag",
                    Type = ShaderType.FragmentShader
                }}),
                Name = "Gui.Image"
            });

            collection.ShaderPrograms.Add(new ShaderProgramInfo()
            {
                Shaders = new List<ShaderInfo>(new[]{ new ShaderInfo() {
                    Path = "Assets/Shaders/SimpleModel2.vert",
                    Type = ShaderType.VertexShader
                },new ShaderInfo() {
                    Path = "Assets/Shaders/SimpleModel2.frag",
                    Type = ShaderType.FragmentShader
                },/*new ShaderInfo() {
                    Path = "Assets/Shaders/SimpleModel.geom",
                    Type = ShaderType.GeometryShader
                }*/}),
                Name = "SimpleModel"
            });

            collection.ShaderPrograms.Add(new ShaderProgramInfo()
            {
                Shaders = new List<ShaderInfo>(new[]{ new ShaderInfo() {
                    Path = "Assets/Shaders/SimpleModel2.vert",
                    Type = ShaderType.VertexShader
                },new ShaderInfo() {
                    Path = "Assets/Shaders/SimpleModel1.frag",
                    Type = ShaderType.FragmentShader
                },/*new ShaderInfo() {
                    Path = "Assets/Shaders/SimpleModel.geom",
                    Type = ShaderType.GeometryShader
                }*/}),
                Name = "Textureless"
            });

            //XML.Write.ToFile(collection, "Assets/Shaders/collection.xml");

            ShaderManager.LoadCollection(collection);

            Time.Initialize();
            UserInput.Initialize(this, typeof(AccurateMouse), typeof(Hatzap.Input.Keyboard));
            UserInput.Mouse.ClickInterval = 0.5f;
            GuiRoot.Initialize(this);

            GuiRoot.Root.Texture = new TextureArray();

            TextureMeta guiTextureMeta = new TextureMeta()
            {
                FileName = "Assets/Textures/greySheet.png",
                Width = 512,
                Height = 512,
                PixelInternalFormat = PixelInternalFormat.Rgba,
                PixelFormat = PixelFormat.Bgra,
                PixelType = PixelType.UnsignedByte,
                Precompressed = false,
                Quality = new TextureQuality()
                {
                    Anisotrophy = 0,
                    Filtering = TextureFiltering.Nearest,
                    TextureWrapMode_S = OpenTK.Graphics.OpenGL.TextureWrapMode.Clamp,
                    TextureWrapMode_T = OpenTK.Graphics.OpenGL.TextureWrapMode.Clamp,
                },
            };

            GuiRoot.Root.Texture.Load(guiTextureMeta);

            ElementCollection guiElements = new ElementCollection()
            {
                Elements = new List<WidgetInfo> {
                    new WidgetInfo(){
                        WidgetType = typeof(Button).ToString(),
                        Slices = new List<GuiTextureRegion> {
                            new GuiTextureRegion() { // Top left
                                Offset = new Vector2(49,433),
                                Size = new Vector2(6,4),
                                Page = 0
                            }, new GuiTextureRegion() { // Top center
                                Offset = new Vector2(55,433),
                                Size = new Vector2(37,4),
                                Page = 0
                            }, new GuiTextureRegion() { // Top Right
                                Offset = new Vector2(92,433),
                                Size = new Vector2(6,4),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle left
                                Offset = new Vector2(49,437),
                                Size = new Vector2(6,36),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle center
                                Offset = new Vector2(55,437),
                                Size = new Vector2(37,36),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle right
                                Offset = new Vector2(92,437),
                                Size = new Vector2(6,36),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom left
                                Offset = new Vector2(49,473),
                                Size = new Vector2(6,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom center
                                Offset = new Vector2(55,473),
                                Size = new Vector2(37,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom right
                                Offset = new Vector2(92,473),
                                Size = new Vector2(6,5),
                                Page = 0
                            },
                        },
                    },
                    new WidgetInfo(){
                        WidgetType = typeof(Window).ToString(),
                        Slices = new List<GuiTextureRegion> {
                             new GuiTextureRegion() { // Top left
                                Offset = new Vector2(190,98),
                                Size = new Vector2(7,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Top center
                                Offset = new Vector2(195,98),
                                Size = new Vector2(86,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Top Right
                                Offset = new Vector2(283,98),
                                Size = new Vector2(7,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle left
                                Offset = new Vector2(190,103),
                                Size = new Vector2(7,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle center
                                Offset = new Vector2(197,103),
                                Size = new Vector2(86,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle right
                                Offset = new Vector2(283,103),
                                Size = new Vector2(7,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle left
                                Offset = new Vector2(190,103),
                                Size = new Vector2(7,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle center
                                Offset = new Vector2(197,103),
                                Size = new Vector2(86,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle right
                                Offset = new Vector2(283,103),
                                Size = new Vector2(7,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom left
                                Offset = new Vector2(190,192),
                                Size = new Vector2(7,6),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom center
                                Offset = new Vector2(197,192),
                                Size = new Vector2(86,6),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom right
                                Offset = new Vector2(283,192),
                                Size = new Vector2(7,6),
                                Page = 0
                            }
                        },
                    },
                    new WidgetInfo(){
                        WidgetType = typeof(Panel).ToString(),
                        Slices = new List<GuiTextureRegion> {
                            new GuiTextureRegion() { // Top left
                                Offset = new Vector2(190,98),
                                Size = new Vector2(7,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Top center
                                Offset = new Vector2(195,98),
                                Size = new Vector2(86,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Top Right
                                Offset = new Vector2(283,98),
                                Size = new Vector2(7,5),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle left
                                Offset = new Vector2(190,103),
                                Size = new Vector2(7,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle center
                                Offset = new Vector2(197,103),
                                Size = new Vector2(86,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Middle right
                                Offset = new Vector2(283,103),
                                Size = new Vector2(7,89),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom left
                                Offset = new Vector2(190,192),
                                Size = new Vector2(7,6),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom center
                                Offset = new Vector2(197,192),
                                Size = new Vector2(86,6),
                                Page = 0
                            }, new GuiTextureRegion() { // Bottom right
                                Offset = new Vector2(283,192),
                                Size = new Vector2(7,6),
                                Page = 0
                            }
                        },
                    },
                }
            };

            XML.Write.ToFile(guiElements, "Assets/Gui/elements.xml");

            GridContainer mainGuiGrid = new GridContainer();
            mainGuiGrid.Columns = 1;
            mainGuiGrid.Rows = 3;
            mainGuiGrid.CellWidths.Add(1280);
            mainGuiGrid.RowHeights.Add(30);
            mainGuiGrid.RowHeights.Add(0);
            mainGuiGrid.RowHeights.Add(30);
            mainGuiGrid.Anchor = new Anchor();
            mainGuiGrid.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
            mainGuiGrid.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
            mainGuiGrid.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;
            mainGuiGrid.Anchor.Directions[AnchorDirection.Bottom] = AnchorType.Snap;
            mainGuiGrid.Position = new Vector2(0, 0);
            mainGuiGrid.Size = new Vector2(400, 200);

            Panel leftPanel = new Panel();
            leftPanel.Anchor = new Anchor();
            leftPanel.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
            leftPanel.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
            leftPanel.Anchor.Directions[AnchorDirection.Bottom] = AnchorType.Snap;

            leftPanel.Position = new Vector2(100, 100);
            leftPanel.Size = new Vector2(300, 10);
            leftPanel.Color = new Vector4(0.1f, 0.1f, 0.1f, 1f);
            leftPanel.RightAnchorOffset = -10.0f;

            leftPanel.TextureRegion = guiElements.GetInfo(leftPanel).Slices.ToArray();

            Panel menuBar = new Panel();
            menuBar.Anchor = new Anchor();
            menuBar.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
            menuBar.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
            menuBar.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;

            menuBar.Position = new Vector2(100, 100);
            menuBar.Size = new Vector2(300, 30);
            menuBar.Color = new Vector4(0.1f, 0.1f, 0.1f, 1f);

            menuBar.TextureRegion = guiElements.GetInfo(leftPanel).Slices.ToArray();

            Panel bottomBar = new Panel();
            bottomBar.Anchor = new Anchor();
            bottomBar.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
            bottomBar.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;
            bottomBar.Anchor.Directions[AnchorDirection.Bottom] = AnchorType.Snap;

            bottomBar.Position = new Vector2(0, 690);
            bottomBar.Size = new Vector2(0, 30);
            bottomBar.Color = new Vector4(0.1f, 0.1f, 0.1f, 1f);

            bottomBar.TextureRegion = guiElements.GetInfo(leftPanel).Slices.ToArray();

            #region StackContainer test
            StackContainer stack = new StackContainer();
            {
                Button btn = new Button();
                Button btn2 = new Button();
                Button btn3 = new Button();
                Button btn4 = new Button();

                stack.AddChildWidget(btn);
                stack.AddChildWidget(btn2);
                stack.AddChildWidget(btn3);
                stack.AddChildWidget(btn4);

                btn.Color = new Vector4(1.5f, 1.5f, 1.5f, 1);
                btn.Text = "Button 1";
                btn.TextColor = new Vector4(0, 0, 0, 1);
                btn.OnClick += (m) =>
                {
                    //btn.Text = "Clicked " + m.ToString();
                };
                btn.Anchor = new Anchor();
                btn.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
                btn.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;
                btn.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
                btn.Position = new Vector2(100, 100);
                btn.Size = new Vector2(150, 50);
                btn.TextureRegion = guiElements.Elements[0].Slices.ToArray();

                btn2.Color = new Vector4(0.2f, 0.2f, 0.2f, 1);
                btn2.Text = "Button 2";
                btn2.OnClick += (m) =>
                {
                    btn2.Text = "Clicked " + m.ToString();
                };
                btn2.Anchor = new Anchor();
                btn2.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
                btn2.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;
                btn2.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
                btn2.Position = new Vector2(300, 100);
                btn2.Size = new Vector2(150, 50);
                btn2.TextureRegion = guiElements.Elements[0].Slices.ToArray();

                btn3.Text = "Button 3";
                btn3.OnClick += (m) =>
                {
                    var r = new Hatzap.Utilities.Random();
                    btn3.Color = new Vector4((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble(), 1);
                    //btn3.Z = btn4.Z + 1;
                };
                btn3.Anchor = new Anchor();
                btn3.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
                btn3.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;
                btn3.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
                btn3.Position = new Vector2(100, 200);
                btn3.Size = new Vector2(150, 50);
                btn3.TextureRegion = guiElements.Elements[0].Slices.ToArray();

                btn4.Color = new Vector4(1, 1, 1, 0.5f);
                btn4.Text = "Button 4";
                btn4.OnClick += (m) =>
                {
                    //btn4.Text = "Clicked " + m.ToString();
                    //btn4.Z = btn3.Z + 1;
                };
                btn4.Anchor = new Anchor();
                btn4.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
                btn4.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;
                btn4.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
                btn4.Position = new Vector2(150, 200);
                btn4.Size = new Vector2(150, 50);
                btn4.TextureRegion = guiElements.GetInfo(btn4).Slices.ToArray();
            }

            stack.Anchor = new Anchor();
            stack.Anchor.Directions[AnchorDirection.Left] = AnchorType.Snap;
            stack.Anchor.Directions[AnchorDirection.Top] = AnchorType.Snap;
            stack.Anchor.Directions[AnchorDirection.Right] = AnchorType.Snap;
            stack.Anchor.Directions[AnchorDirection.Bottom] = AnchorType.Snap;

            stack.RightAnchorOffset = 5;
            stack.LeftAnchorOffset = 5;
            stack.TopAnchorOffset = 5;
            #endregion

            var image = new Hatzap.Gui.Widgets.Image();
            var lblText = new Label();

            Window window = new Window();
            window.TextureRegion = guiElements.GetInfo(window).Slices.ToArray();
            window.Position = new Vector2(1200, 600);
            window.Size = new Vector2(300, 200);
            window.TitleHeight = 20;
            window.TitleColor = new Vector4(79f / 255f / 0.5f, 193f / 255f / 0.5f, 233f / 255f / 0.5f, 1f);
            window.Color = new Vector4(1f / (210f / 255f), 1f / (210f / 255f), 1f / (210f / 255f), 1f);

            leftPanel.AddChildWidget(stack);

            mainGuiGrid.AddChildWidget(menuBar);
            mainGuiGrid.AddChildWidget(leftPanel);
            mainGuiGrid.AddChildWidget(bottomBar);

            GuiRoot.Root.AddWidget(mainGuiGrid);

            UserInput.Keyboard.CaptureText = true;

            modelShader = ShaderManager.Get("Model");
            textShader = ShaderManager.Get("Text");

            //Create a new importer
            AssimpContext importer = new AssimpContext();

            //This is how we add a configuration (each config is its own class)
            //NormalSmoothingAngleConfig config = new NormalSmoothingAngleConfig(66.0f);
            //importer.SetConfig(config);

            var flags = PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessSteps.Triangulate | PostProcessSteps.SortByPrimitiveType | PostProcessSteps.FlipUVs;

            //Import the model. All configs are set. The model
            //is imported, loaded into managed memory. Then the unmanaged memory is released, and everything is reset.
            Scene model = importer.ImportFile("Assets/Models/cube.fbx", flags);

            mesh = new Hatzap.Models.Mesh();

            Assimp.Mesh aMesh = null;

            foreach (var item in model.Meshes)
            {
                if (item.PrimitiveType != Assimp.PrimitiveType.Triangle)
                    continue;

                aMesh = item;
                break;
            }

            if (aMesh != null)
            {
                //mesh.AssimpMesh = aMesh;
            }
            else
            {
                Debug.WriteLine("ERROR: No triangle meshes found in imported model.");
            }

            //End of example
            importer.Dispose();

            TextureMeta shipTextureMeta = new TextureMeta()
            {
                FileName = "Assets/Textures/sh3.jpg,Assets/Textures/sh3_n.png,Assets/Textures/sh3_s.jpg",
                PixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext,
                PixelFormat = PixelFormat.Bgra,
                PixelType = PixelType.UnsignedByte,
                Width = 1024,
                Height = 1024,
                Quality = new TextureQuality()
                {
                    Filtering = TextureFiltering.Trilinear,
                    Anisotrophy = 32,
                    Mipmaps = true,
                    TextureWrapMode_S = OpenTK.Graphics.OpenGL.TextureWrapMode.Repeat,
                    TextureWrapMode_T = OpenTK.Graphics.OpenGL.TextureWrapMode.Repeat
                }
            };

            shipTexture = new TextureArray();
            shipTexture.Load(shipTextureMeta);

            font = FontManager.Get("OpenSans-Regular");

            fpsText = new GuiText();
            fpsText.Font = font;
            fpsText.FontSize = 8f;
            fpsText.Weight = 1.2f;
            fpsText.Smooth = 2.5f;
            fpsText.LineHeight = 50.0f;
            fpsText.Color = new Vector4(1, 1, 1, 1);
            fpsText.Text = "FPS: Calculating..";

            int n = 5;
            int sizeScale = 7;

            var rand = new Hatzap.Utilities.Random();

            for (int x = -n; x <= n; x++)
            {
                for (int y = -n; y <= n; y++)
                {
                    Hatzap.Models.Material spaceShipMaterial = new Hatzap.Models.Material();

                    bool transparent = rand.NextDouble() < 0.5;

                    float transparency = (float)rand.NextDouble();

                    transparency += 0.05f;

                    if (!(transparency < 1.0f))
                    {
                        transparency = 1.0f;
                        transparent = false;
                    }

                    spaceShipMaterial.Transparent = transparent;

                    spaceShipMaterial.UniformData = new List<IUniformData> {
                        new UniformDataVector4()
                        {
                            Name = "Color",
                            Data = new Vector4((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), transparency)
                        }
                    };

                    for (int z = -n; z <= n; z++)
                    {
                        var spaceShip = new Model();
                        spaceShip.Texture = shipTexture;
                        //spaceShip.Shader = ShaderManager.Get("Textureless");
                        spaceShip.Shader = ShaderManager.Get("Model");
                        spaceShip.Mesh = mesh;
                        spaceShip.Transform.Static = true;
                        spaceShip.Transform.Position = new Vector3((x + (float)(rand.NextDouble() - 0.5)) * sizeScale, (y + (float)(rand.NextDouble() - 0.5)) * sizeScale, (z + (float)(rand.NextDouble() - 0.5)) * sizeScale);
                        spaceShip.Transform.Rotation = Quaternion.FromEulerAngles(x * 360.0f / n / (float)Math.PI, y * 360.0f / n / (float)Math.PI, z * 360.0f / n / (float)Math.PI);
                        spaceShip.Material = spaceShipMaterial;

                        SceneManager.Insert(spaceShip);
                    }
                }
            }

            Debug.WriteLine("OnLoad() ends");

            base.OnLoad(e);
        }
Example #6
0
 public void RenderOnScreen(ShaderProgram shader)
 {
     shader.Enable();
     shader.SendUniform("ScreenSize", ref size);
     shader.SendUniform("MSAA_Samples", MSAA);
     Texture.Bind();
     batch.Render();
     Texture.UnBind();
     shader.Disable();
 }
Example #7
0
        public void Draw(ShaderProgram shader)
        {
            if (text == string.Empty)
                return;

            if(dirty)
            {
                dirty = false;

                Upload();
            }

            if (indices == null || vertices == null)
                return;

            Font.Texture.Bind();

            GL.BindVertexArray(vao);

            if (mustDescribe)
            {
                int stride = BlittableValueType.StrideOf(vertices);

                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);

                // Vertex
                int vertexLocation = shader.GetAttribLocation("vertex");
                if(vertexLocation > -1)
                {
                    GL.EnableVertexAttribArray(vertexLocation);
                    GL.VertexAttribPointer(vertexLocation, 2, VertexAttribPointerType.Float, false, stride, 0);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for vertex: " + vertexLocation);
                }

                // TCoord
                int uvLocation = shader.GetAttribLocation("uv");
                if(uvLocation > -1)
                {
                    GL.EnableVertexAttribArray(uvLocation);
                    GL.VertexAttribPointer(uvLocation, 2, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for uv: " + uvLocation);
                }
                // Color
                int colorLocation = shader.GetAttribLocation("vColor");
                if(colorLocation > -1)
                {
                    GL.EnableVertexAttribArray(colorLocation);
                    GL.VertexAttribPointer(colorLocation, 4, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes * 2);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for vColor: " + colorLocation);
                }
                // BorderColor
                int borderLocation = shader.GetAttribLocation("vBorderColor");
                if (borderLocation > -1)
                {
                    GL.EnableVertexAttribArray(borderLocation);
                    GL.VertexAttribPointer(borderLocation, 4, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes * 2 + Vector4.SizeInBytes);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for vBorderColor: " + borderLocation);
                }
                // Settings
                /*int settingsLocation = shader.GetAttribLocation("vSettings");
                GL.EnableVertexAttribArray(settingsLocation);
                GL.VertexAttribPointer(settingsLocation, 3, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes * 2 + Vector4.SizeInBytes * 2);*/

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, ebo);

                mustDescribe = false;
            }

            //float smooth = (1f - (fontsize / 150f)) * 0.5f * this.weight * this.smooth;

            if (smooth < 0f)
                smooth = 0f;
            else if (smooth > 0.5f)
                smooth = 0.5f;

            //float weight = Hatzap.Utilities.MathHelper.Lerp(0f, 2f, 1f - (fontsize / 100f * this.weight));
            //float weight = (float)Math.Pow(1.5f - (fontsize / 150f), this.weight) * this.weight * 0.75f;

            /*if (weight < 0.75f)
                weight = 0.75f;*/

            CalculatedWeight = weight;

            Vector4 settings = new Vector4(fontsize, weight, border, smooth);

            shader.SendUniform("Settings", ref settings);

            GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero);

            GL.BindVertexArray(0);
        }
Example #8
0
        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL settings
            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.CullFace = true;
            GLState.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha);

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

            // Load shaders
            ShaderManager.LoadCollection("Shaders/collection.xml");
            fboShader = ShaderManager.Get("framebufferexample");
            blurShader = ShaderManager.Get("framebufferexample.blur");
            msaaShader = ShaderManager.Get("framebufferexample.msaa");
            fxaaShader = ShaderManager.Get("framebufferexample.fxaa");

            // Initialize framebuffer
            if(msaa)
            {
                fbo = new Framebuffer(Width, Height, 32);
            }
            else
            {
                fbo = new Framebuffer(Width, Height, 0);
            }

            // Load other stuff
            LoadMeshStuff();

            textShader = ShaderManager.Get("Text");

            font = new Font();
            font.LoadBMFont("Fonts/OpenSans-Regular.ttf_sdf.txt");
            font.Texture = textures.Get("Textures/OpenSans-Regular.ttf_sdf.tex", true);

            text = new GuiText();
            text.Font = font;
            text.Text = GenerateInfoText();
        }
Example #9
0
 void gw_Load(object sender, EventArgs e)
 {
     renderer = new GuiRenderer();
     shader = ShaderManager.Get("Gui");
 }
Example #10
0
        public void BeginBatch(SpriteAtlas atlas)
        {
            current = atlas;

            if (vao == 0)
            {
                program = ShaderManager.Get("sprite.shader");

                vao = GL.GenVertexArray();
                GL.GenBuffers(2, vbo);

                GL.BindVertexArray(vao);
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[0]);

                int vertex = program.GetAttribLocation("vertex");
                int uv = program.GetAttribLocation("uv");
                int position = program.GetAttribLocation("position");
                int size = program.GetAttribLocation("size");
                int rotation = program.GetAttribLocation("rotation");
                int color = program.GetAttribLocation("color");

                int stride = BlittableValueType.StrideOf(new SpriteRenderData());

                int offset = 0;

                GL.EnableVertexAttribArray(vertex);
                GL.VertexAttribPointer(vertex, 3, VertexAttribPointerType.Float, false, stride, offset);

                offset += Vector3.SizeInBytes;

                if(uv != -1)
                {
                    GL.EnableVertexAttribArray(uv);
                    GL.VertexAttribPointer(uv, 2, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector2.SizeInBytes;

                if(position != -1)
                {
                    GL.EnableVertexAttribArray(position);
                    GL.VertexAttribPointer(position, 3, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector3.SizeInBytes;

                if(size != -1)
                {
                    GL.EnableVertexAttribArray(size);
                    GL.VertexAttribPointer(size, 2, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector2.SizeInBytes;

                if(rotation != -1)
                {
                    GL.EnableVertexAttribArray(rotation);
                    GL.VertexAttribPointer(rotation, 1, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += sizeof(float);

                if (color != -1)
                {
                    GL.EnableVertexAttribArray(color);
                    GL.VertexAttribPointer(color, 4, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector4.SizeInBytes;

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo[1]);

                GL.BindVertexArray(0);
            }
        }