Example #1
0
        void IDualityBackend.Init()
        {
            activeInstance = this;

            // ToDo: Hardcoded size
            cachedCanvasSize = new Point2(720, 405);

            htmlCanvas = HtmlHelper.AddCanvas("game", cachedCanvasSize.X, cachedCanvasSize.Y);

            // ToDo: Use WebGLContextAttributes instead
            using (JSObject contextAttributes = new JSObject()) {
                contextAttributes.SetObjectProperty("premultipliedAlpha", false);
                GL = new WebGL2RenderingContext(htmlCanvas);
            }

            if (!GL.IsAvailable)
            {
                using (var app = (JSObject)Runtime.GetGlobalObject("App")) {
                    app.Invoke("webglNotSupported");
                }

                throw new NotSupportedException("This browser does not support WebGL 2");
            }

            GraphicsBackend.LogOpenGLSpecs();
        }
Example #2
0
        void IDualityBackend.Init()
        {
            activeInstance = this;

            using (var app = (JSObject)Runtime.GetGlobalObject("App")) {
                cachedCanvasSize.X = (int)app.GetObjectProperty("defaultWidth");
                cachedCanvasSize.Y = (int)app.GetObjectProperty("defaultHeight");
            }

            htmlCanvas = HtmlHelper.AddCanvas("game", cachedCanvasSize.X, cachedCanvasSize.Y);

            if (!WebGLRenderingContext.IsSupported)
            {
                using (var app = (JSObject)Runtime.GetGlobalObject("App")) {
                    app.Invoke("webglNotSupported");
                }

                throw new NotSupportedException("This browser does not support WebGL 1");
            }

            // ToDo: Use WebGLContextAttributes instead
            using (JSObject contextAttributes = new JSObject()) {
                contextAttributes.SetObjectProperty("premultipliedAlpha", false);
                GL = new WebGLRenderingContext(htmlCanvas);
            }

            GraphicsBackend.LogOpenGLSpecs();
        }
Example #3
0
#pragma warning disable CC0061 // Asynchronous methods should return a Task instead of void
        static async void Main()
#pragma warning restore CC0061 // Asynchronous methods should return a Task instead of void
        {
            if (!WebGL2RenderingContextBase.IsSupported)
            {
                HtmlHelper.AddParagraph("We are sorry, but your browser does not seem to support WebGL2.");
                HtmlHelper.AddParagraph("See the <a href=\"https://github.com/WaveEngine/WebGL.NET\">GitHub repo</a>.");
                return;
            }

            HtmlHelper.AddHeader1("WebGL.NET Samples Gallery");

            HtmlHelper.AddParagraph(
                "A collection of WebGL samples translated from .NET/C# into WebAssembly. " +
                "See the <a href=\"https://github.com/WaveEngine/WebGL.NET\">GitHub repo</a>.");

            samples = new ISample[]
            {
                new Triangle(),
                new RotatingCube(),
                new Texture2D(),
                new TexturedCubeFromHTMLImage(),
                new TexturedCubeFromAssets(),
                // TODO: Report issue with monolinker (remove Linker workaround project)
                new LoadGLTF(),
                new TransformFeedback(),
                new PointerLock(),
            };

            foreach (var sample in samples)
            {
                var sampleName = sample.GetType().Name;

                HtmlHelper.AddHeader2(sampleName);
                HtmlHelper.AddParagraph(sample.Description);

                var divCanvasName = $"div_canvas_{sampleName}";
                var canvasName    = $"canvas_{sampleName}";
                using (var canvas = HtmlHelper.AddCanvas(divCanvasName, canvasName, CanvasWidth, CanvasHeight))
                {
                    await sample.InitAsync(canvas, CanvasColor);

                    sample.Run();

                    if (sample.EnableFullScreen)
                    {
                        var fullscreenButtonName = $"fullscreen_{sampleName}";
                        HtmlHelper.AddButton(fullscreenButtonName, "Enter fullscreen");
                        AddFullScreenHandler(sample, fullscreenButtonName, divCanvasName, canvasName);
                    }
                }
            }

            AddEnterFullScreenHandler();

            AddGenerationStamp();

            RequestAnimationFrame();
        }