コード例 #1
0
ファイル: InstancedBatch.cs プロジェクト: Lazzu/Hatzap
 public InstancedBatch(Model model)
 {
     Mesh = model.Mesh;
     Shader = model.Material.ShaderProgram;
     Vector4[] tmp = null;
     stride = BlittableValueType.StrideOf(tmp) * 4;
     attribPos = Shader.GetAttribLocation("mInstancedModelMatrix");
     pos1 = attribPos + 0;
     pos2 = attribPos + 1;
     pos3 = attribPos + 2;
     pos4 = attribPos + 3;
 }
コード例 #2
0
ファイル: CubemapExampleWindow.cs プロジェクト: Lazzu/Hatzap
        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL settings
            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.CullFace = true;
            GLState.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha);
            GL.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);

            // Set up camera
            camera = new Camera(this);
            camera.Perspective(Width, Height, (float)Math.PI / 4, 1f, 1000);
            camera.Position = new Vector3(0, 20, 200);
            camera.Target = new Vector3(0, 0, -1);
            camera.SetAsCurrent(); // Use this camera for rendering

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

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

            // Load texture
            textures = new TextureManager();
            var texture = textures.Get("Textures/cubemap.tex", true);
            texture.Quality.Mipmaps = true;

            // Load up a mesh
            MeshManager meshManager = new MeshManager();
            var mesh = meshManager.Get("Meshes/sphere.mesh", true);

            // Construct a model from shader, texture and mesh, with default material
            model = new Model()
            {
                Shader = shader,
                Texture = texture,
                Mesh = mesh,
                Material = new Material()
            };

            // set up rendering queue
            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = false;
        }
コード例 #3
0
        protected override void OnLoad(EventArgs e)
        {
            PackageManager.BasePath = "../../Assets/";

            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.CullFace = true;
            GL.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);

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

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

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

            meshes = new MeshManager();

            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.Rotate(new Vector2(-(float)Math.PI / 2.5f, 0));

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

            int n = 8;
            float sizeScale = 10.0f;

            // All objects will have the same material
            Material material = new Material();

            material.ShaderProgram = ShaderManager.Get("instancedmodel");

            // To disable instancing, use these:
            //material.ShaderProgram = ShaderManager.Get("simplemodel");
            //renderQueue.AllowInstancing = false;

            for (int x = -n; x <= n; x++)
            {
                for (int y = -n; y <= n; y++)
                {
                    for (int z = -n; z <= n; z++)
                    {
                        var instancedObject = new Model();

                        // Set shader, mesh and material (no texture)
                        instancedObject.Mesh = meshes.Get("Meshes/suzanne.mesh", true);
                        instancedObject.Material = material.Copy();

                        // Set transform
                        instancedObject.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);
                        instancedObject.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);

                        float color = 1f;
                        color = color - ((y + n) / (n * 2.0f));

                        instancedObject.Material.Add(new UniformDataVector4(){
                            Data = new Vector4(color, color, color, 1),
                            Name = "Color",
                        });

                        // Don't calculate matrices on every frame
                        instancedObject.Transform.Static = true;

                        // Insert model in the scene octree. (Because I'm lazy and didn't want
                        // to write code to update all these meshes in the queue by hand. Also
                        // culling is done by scene automatically.)
                        SceneManager.Insert(instancedObject);
                    }
                }
            }
        }
コード例 #4
0
ファイル: HatzapGameWindow.cs プロジェクト: Lazzu/Hatzap
        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);
        }
コード例 #5
0
        void LoadMeshStuff()
        {
            // Set up camera
            camera = new Camera(this);
            camera.Perspective(Width, Height, (float)Math.PI / 4, 1f, 1000);
            camera.Position = new Vector3(0, 20, 200);
            camera.Target = new Vector3(0, 0, 0);
            camera.SetAsCurrent(); // Use this camera for rendering

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

            // Load shaders
            var modelshader = ShaderManager.Get("transparentmodel");

            // Load texture
            textures = new TextureManager();
            var texture = textures.Get("Textures/lucymetal.tex", true);
            texture.Quality.Mipmaps = true;

            // Load up a mesh
            MeshManager meshManager = new MeshManager();
            var mesh = meshManager.Get("Meshes/lucy.mesh", true);

            var lucyMaterial = new Material();

            lucyMaterial.Textures.Add("textureSampler", texture);
            lucyMaterial.ShaderProgram = modelshader;

            // Construct a model from shader, texture and mesh, with default material
            model = new Model()
            {
                Mesh = mesh,
                Material = lucyMaterial
            };

            // set up rendering queue
            renderQueue = new RenderQueue()
            {
                AllowInstancing = false
            };
        }
コード例 #6
0
ファイル: RenderableTexture.cs プロジェクト: Lazzu/Hatzap
        public RenderableTexture(Texture texture)
        {
            Vector2 halfSize = new Vector2(texture.Width / 2.0f, texture.Height / 2.0f);

            model = new Model();
            model.Material = new Material() {
                Transparent = false,
                UniformData = new List<IUniformData>
                {
                    new UniformDataVector4()
                    {
                        Name = "Color",
                        Data = Vector4.One
                    },
                    new UniformDataInt()
                    {
                        Name = "textureSampler",
                        Data = 0
                    }
                },
                ShaderProgram = ShaderManager.Get("TexturedQuad")
            };
            model.Material.Textures.Add("default", texture);
            var mesh = new Mesh();
            mesh.Type = PrimitiveType.TriangleStrip;
            /*mesh.Vertices = new Vector3[]{
                new Vector3(-halfSize.X, -halfSize.Y, 0) * 100.0f,
                new Vector3(halfSize.X, -halfSize.Y, 0) * 100.0f,
                new Vector3(-halfSize.X, halfSize.Y, 0) * 100.0f,
                new Vector3(halfSize.X, halfSize.Y, 0) * 100.0f,
            };*/
            mesh.Vertices = new Vector3[]{
                new Vector3(-1, -1, 0),
                new Vector3(1, -1, 0),
                new Vector3(-1, 1, 0),
                new Vector3(1, 1, 0),
            };
            mesh.UV = new Vector3[][] {
                new Vector3[] {
                    new Vector3(0,1,0),
                    new Vector3(1,1,0),
                    new Vector3(0,0,0),
                    new Vector3(1,0,0),
                }
            };
            mesh.Indices = new uint[]{
                0,1,2,3
            };
            model.Mesh = mesh;
            model.Transform.Position = new Vector3(0, 0, 0);
            model.Transform.Scale = new Vector3(1, 1, 1);
            model.Transform.Rotation = Quaternion.Identity;

            Camera camera = new Camera(null);
            camera.SetAsCurrent();

            float w = EditorRenderer.Width / 2.0f;
            float h = EditorRenderer.Height / 2.0f;

            camera.Projection = Matrix4.CreateOrthographicOffCenter(-w, w, -h, h, -1, 1);
            camera.View = Matrix4.Identity;
        }
コード例 #7
0
        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL settings
            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.AlphaBleding = false;
            GLState.CullFace = true;
            GL.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);

            // Set up camera
            camera = new Camera(this);
            camera.Perspective(Width, Height, (float)Math.PI / 4, 1f, 1000);
            camera.Position = new Vector3(0, 20, 100);
            camera.Target = new Vector3(0, 0, -1);
            camera.SetAsCurrent();

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

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

            // Load texture
            textures = new TextureManager();
            var texture = textures.Get("Textures/concreteslabs.tex", true);
            texture.Quality.Mipmaps = true;
            texture.Quality.TextureWrapMode = TextureWrapMode.Repeat;

            // Load up a mesh
            MeshManager meshManager = new MeshManager();
            var mesh = meshManager.Get("Meshes/dragon.mesh", true);

            // Create base material
            materials = new MaterialManager();
            materials.Insert("uniformexamplematerial.mat", new Material()
            {
                UniformData = new List<IUniformData>()
                {
                    new UniformDataFloat() {
                        Name = "time",
                        Data = 0.0f
                    },
                    new UniformDataVector2() {
                        Name = "toffset",
                        Data = Vector2.Zero
                    },
                    new UniformDataVector4() {
                        Name = "color",
                        Data = Vector4.One
                    }
                }
            });

            // Construct a model from shader, texture and mesh, with default material
            model = new Model()
            {
                Shader = ShaderManager.Get("uniformexamplemodel"),
                Texture = texture,
                Mesh = mesh,
                Material = materials.Get("uniformexamplematerial.mat")
            };

            model2 = new Model()
            {
                Shader = ShaderManager.Get("uniformexamplemodel"),
                Texture = texture,
                Mesh = mesh,
                Material = materials.Get("uniformexamplematerial.mat")
            };

            model3 = new Model()
            {
                Shader = ShaderManager.Get("uniformexamplemodel"),
                Texture = texture,
                Mesh = mesh,
                Material = materials.Get("uniformexamplematerial.mat")
            };

            model.Transform.Position += new Vector3(-1, 0.5f, 0);
            model2.Transform.Position += new Vector3(1, 0.5f, 0);
            model3.Transform.Position += new Vector3(0, -0.75f, 0);

            model.Transform.Rotation *= new Quaternion(0, (float)Math.PI, 0);

            // set up rendering queue
            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = false;
        }
コード例 #8
0
        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL settings
            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.CullFace = true;
            GLState.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);

            // Set up camera
            camera = new Camera(this);
            camera.Perspective(Width, Height, (float)Math.PI / 4, 1f, 1000);
            camera.Position = new Vector3(0, 20, 200);
            camera.Target = new Vector3(0, 0, 0);
            camera.SetAsCurrent();

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

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

            // Load texture
            textures = new TextureManager();
            var texture = textures.Get("Textures/lucymetal.tex", true);
            texture.Quality.Mipmaps = true;

            var groundtexture = textures.Get("Textures/concreteslabs.tex", true);
            groundtexture.Quality.Mipmaps = true;
            groundtexture.Quality.TextureWrapMode = TextureWrapMode.Repeat;

            // Load up a mesh
            MeshManager meshManager = new MeshManager();
            var mesh = meshManager.Get("Meshes/lucy.mesh", true);
            var groundmesh = meshManager.Get("Meshes/plane.mesh", true);

            var modelMaterial = new Material()
                {
                    ShaderProgram = ShaderManager.Get("transparentmodel"),
                    Transparent = false,
                    UniformData = new List<IUniformData>()
                    {
                        new UniformDataVector4() {
                            Name = "color",
                            Data = new Vector4(1,1,1,0.75f),
                        },
                        new UniformDataFloat() {
                            Name = "specularIntensity",
                            Data = 0.5f,
                        }
                    }
                };

            modelMaterial.Textures.Add("textureSampler", texture);

            // Construct a model from shader, texture and mesh, with default material
            model = new Model()
            {
                Mesh = mesh,
                Material = modelMaterial
            };

            var modelMaterial2 = modelMaterial.Copy();
            modelMaterial2.Transparent = true;

            // Construct a model from shader, texture and mesh, with default material
            model2 = new Model()
            {
                Mesh = mesh,
                Material = modelMaterial2
            };

            var groundMaterial = modelMaterial.Copy();
            groundMaterial.Textures["textureSampler"] = groundtexture;

            // Construct a model from shader, texture and mesh, with default material
            groundplane = new Model()
            {
                Mesh = groundmesh,
                Material = groundMaterial
            };

            model.Transform.Position += new Vector3(1, 0, 0);
            model2.Transform.Position += new Vector3(-1, 0, 0);
            groundplane.Transform.Position += new Vector3(0, -1, 0);

            // set up rendering queue
            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = false;
        }