private static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                return(-1);
            }

            Thread.CurrentThread.Name = "main";

            Lumberjack.Init();

            Lumberjack.Debug("Loading configuration");
            Config = ConfigContainer.Load();

            if (Config.UnpackTextures)
            {
                Lumberjack.Debug("Unpacking textures");
                ZipFile.ExtractToDirectory("Resources/assets.zip", "Resources");
                Config.UnpackTextures = false;
                Config.Save();
            }

            Lumberjack.Debug("Loading window");
            new MainWindow(args)
            {
                VSync = VSyncMode.Off
            }.Run();

            return(0);
        }
示例#2
0
        private void OnLoad(object sender, EventArgs e)
        {
            Lumberjack.Debug("Loading window state");
            // Set up lighting
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.ColorMaterial);

            // Set up caps
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.RescaleNormal);
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.CullFace);

            // Set up blending
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            // Set background color
            GL.ClearColor(Color.FromArgb(255, 13, 13, 13));

            // Init keyboard to ensure first frame won't NPE
            _keyboard = Keyboard.GetState();

            Lumberjack.Debug("Loading render engine");
            _mappingEngine = new MappingEngine();
            _renderEngine  = new RenderEngine(this, _mappingEngine);

            _camera = new Camera();

            Lumberjack.Debug("Loading world");
            _structure = StructureLoader.Load(_args[0]);
            _renderEngine.LoadStructure(_structure);
        }
示例#3
0
        private static void OnGlMessage(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userparam)
        {
            if (severity == DebugSeverity.DebugSeverityNotification || SuppressedGlMessages.Contains(id))
            {
                return;
            }

            var msg = Marshal.PtrToStringAnsi(message, length);

            Lumberjack.Debug("OpenGL", msg);
        }
示例#4
0
        public void Init(Flat6Window window)
        {
            Window = window;

            Lumberjack.Debug("Creating framebuffers");
            FramebufferScene = new Framebuffer(8);
            FramebufferScene.Init(Window.Width, Window.Height);
            FramebufferInterface = new Framebuffer(8);
            FramebufferInterface.Init(Window.Width, Window.Height);

            CreateScreenVao();

            Lumberjack.Debug("Creating shaders");
            ShaderDefault = new ShaderProgram(EmbeddedResources.FsDefault, EmbeddedResources.VsDefault);
            ShaderDefault.Uniforms.SetValue("texModel", 0);
            ShaderDefault.Uniforms.SetValue("texRandom", 1);

            ShaderScreen = new ShaderProgram(EmbeddedResources.FsScreen, EmbeddedResources.VsScreen);
            ShaderScreen.Uniforms.SetValue("width", Window.Width);
            ShaderScreen.Uniforms.SetValue("height", Window.Height);
            ShaderScreen.Uniforms.SetValue("texScene", 0);
            ShaderScreen.Uniforms.SetValue("texInterface", 1);
            ShaderScreen.Uniforms.SetValue("samplesScene", FramebufferScene.Width);
            ShaderScreen.Uniforms.SetValue("samplesInterface", FramebufferInterface.Samples);

            TextureDefault = TexturePointer.Create(EmbeddedResources.ImgNoTexture);
            TextureRandom  = TexturePointer.Create(EmbeddedResources.ImgRandom);

            Lumberjack.Debug("Creating NanoVG context");
            Nvg = GlNanoVg.CreateGl(NvgCreateFlags.StencilStrokes);
            Nvg.CreateFont("engine_mono", EmbeddedResources.IBMPlexMono_Text);

            // Just so ProcGraph is happy for now, TODO
            Nvg.CreateFont("sans", EmbeddedResources.IBMPlexMono_Text);

            UserInterface = new DebugUserInterface();

            Lumberjack.Debug("Creating scene");
            Camera = new Camera();
            Scene  = new Scene();

            Flat6Window.SuppressGlMessage(131218); // "Shader will be recompiled due to..."

            WindowCreated?.Invoke(this, EventArgs.Empty);
        }
示例#5
0
        private void OnLoad(object sender, EventArgs e)
        {
            Lumberjack.Debug("Setting default graphics state");
            // Set up lighting
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.ColorMaterial);

            // Set up caps
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.RescaleNormal);
            GL.Enable(EnableCap.DebugOutput);
            GL.DebugMessageCallback(DebugCallback, IntPtr.Zero);

            // Set up blending
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            // Set background color
            GL.ClearColor(Color.CornflowerBlue);
        }
示例#6
0
        public static TexturePointer Create(string imagePath)
        {
            // TODO: have option to stream images from baked texture bundle
            // Proposed format:

            /*
             * int32: numImages
             * headerEntry * [numImages]: entries[]
             * byte[] * [numImages]: images
             *
             * headerEntry<
             * int32: width
             * int32: height
             * int64: offset
             * int64: length
             * >
             */
            Lumberjack.Debug($"Loading image {imagePath}");
            using (var b = new Bitmap(imagePath))
            {
                return(Create(b));
            }
        }
        public BlockAtlas(MappingEngine mappings, int textureResolution)
        {
            Lumberjack.Debug("Generating texture atlas");
            var pointers   = new List <TexturePointer>();
            var resolution = new Size(textureResolution, textureResolution);

            foreach (var set in mappings.Mappings)
            {
                if (set.Texture.Count == 0)
                {
                    continue;
                }
                foreach (var texture in set.Texture)
                {
                    if (texture.Contains(","))
                    {
                        var subTextures = texture.Split(',');
                        pointers.AddRange(subTextures.Select((subTexture, i) => new TexturePointer($"{set.Name}${i}", Path.Combine(set.TextureDir, subTexture), resolution)));
                    }
                    else
                    {
                        pointers.Add(new TexturePointer(set.Name, Path.Combine(set.TextureDir, texture),
                                                        resolution));
                    }
                }
            }

            var size   = 1024;
            var packed = Pack(size, size, pointers);

            if (!packed)
            {
                throw new ArgumentException("Failed to create texture atlas, atlas too small!");
            }

            var srcTexRect = new Rectangle(0, 0, textureResolution, textureResolution);

            var bmpAtlas = new Bitmap(size, size);

            using (var gfx = System.Drawing.Graphics.FromImage(bmpAtlas))
            {
                foreach (var pointer in pointers)
                {
                    using (var bmpTexture = Image.FromFile(pointer.TexturePath))
                        gfx.DrawImage(bmpTexture, new Rectangle(pointer.Position, pointer.Size), srcTexRect,
                                      GraphicsUnit.Pixel);

                    var minU = pointer.Position.X / (float)size;
                    var minV = pointer.Position.Y / (float)size;
                    var maxU = (pointer.Position.X + pointer.Size.Width) / (float)size;
                    var maxV = (pointer.Position.Y + pointer.Size.Height) / (float)size;

                    var blockname = pointer.TextureName.Split('$')[0];

                    if (!_atlas.ContainsKey(blockname))
                    {
                        _atlas.Add(blockname, new BlockRenderData(mappings[blockname]));
                    }

                    _atlas[blockname].Textures.Add(new TexCoord(minU, minV, maxU, maxV));
                }

                if (Program.Config.SaveAtlas)
                {
                    bmpAtlas.Save("debugatlas.png");
                    Lumberjack.Info("Saved atlas as debugatlas.png");
                }

                Texture = CreateTexture(bmpAtlas);
            }
            Lumberjack.Debug($"Packed {pointers.Count} x{textureResolution} textures in a {size}x atlas");
        }
示例#8
0
        private void OnLoad(object sender, EventArgs e)
        {
            // Init keyboard to ensure first frame won't NPE
            _keyboard = Keyboard.GetState();

            Camera = new ActorOrbitalCamera();

            //            var earth = new ActorEarth();
            //            _satellite = new ActorSatellite(25544)
            //            {
            //                Parent = earth
            //            };
            //            var track = new ActorSatelliteTrack(25544)
            //            {
            //                Parent = earth
            //            };
            //            var atmosphere = new ActorAtmosphere
            //            {
            //                Parent = earth
            //            };

            //            Scene.Actors.Add(new ActorSkybox());
            //            Scene.Actors.Add(_satellite);
            //            Scene.Actors.Add(track);
            //            Scene.Actors.Add(earth);
            //            Scene.Actors.Add(atmosphere);
            Scene.Actors.Add(new ActorDynamicSphere(1, 4, 200));

            // Create SpaceMouse
            _spaceMouse         = new SpaceMouse("SatWall");
            _spaceMouse.Motion += OnSpaceMouseMotion;

            var status = _spaceMouse.InitDevice(Window.WindowInfo.Handle);

            switch (status)
            {
            case SpaceMouseStatus.Initialized:
                Lumberjack.Debug("Created SpaceMouse.");
                _spaceMouse.StartAutoMessageCapture(Window.WindowInfo.Handle);
                break;

            case SpaceMouseStatus.LibraryNotFound:
                Lumberjack.Debug("No SpaceMouse library found.");
                break;

            case SpaceMouseStatus.DeviceLoadFailure:
                Lumberjack.Debug("SpaceMouse load failed.");
                break;
            }

            _kuat = new KuatUserInterface(Window, new KuatFont());

            _graphFrameTime = new KuatPerfGraph(Color.LawnGreen, "render", unit: "ms", max: 16, drawAverageLine: true)
            {
                Location = new Point(5, 5)
            };
            _graphTickTime = new KuatPerfGraph(Color.DodgerBlue, "tick", unit: "ms", max: 16, drawAverageLine: true)
            {
                Location = new Point(5, 45)
            };

            _kuat.Controls.Add(_graphFrameTime);
            _kuat.Controls.Add(_graphTickTime);

            UserInterface = _kuat;
        }