Example #1
0
        public static void Main()
        {
            var window = new MyOTKEWindow(
                gameWindowSettings: GameWindowSettings.Default,
                nativeWindowSettings: NativeWindowSettings.Default,
                lockCursor: false,
                clearColor: Color.Black())
            {
                Title        = "MyOTKE Example",
                WindowState  = WindowState.Fullscreen,
                WindowBorder = WindowBorder.Resizable,
            };

            // Obviously not ideal to have to set font globally - need to sort this out, probably via some nice
            // texture management stuff in the core lib.
            Text.Font = new Font(@"Assets\Fonts\Inconsolata\Inconsolata-Regular.ttf");

            // MyOTKEWindow has a RootComponent property. Components can be composed of other components -
            // there's even a handy CompositeComponent base class to make this easy - see the two examples
            // below, and note that MenuComponent (which consists of a single GUI component and has
            // no overrides) is only a class of its own to make disposal on button press easy.
            window.RootComponent = new MenuComponent(window);

            window.Run();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gui"/> class.
        /// </summary>
        /// <param name="view">The view from which to derive size and input.</param>
        /// <param name="initialCapacity">Initial capacity of the GUI, in vertices.</param>
        public Gui(MyOTKEWindow view, int initialCapacity)
        {
            this.view         = view;
            this.view.Resize += View_Resized;

            this.SubElements = new ElementCollection(this);

            if (program == null && programBuilder == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null && programBuilder == null)
                    {
                        programBuilder = new GlProgramBuilder()
                                         .WithVertexShaderFromEmbeddedResource("Gui.Vertex.glsl")
                                         .WithFragmentShaderFromEmbeddedResource("Gui.Fragment.glsl")
                                         .WithDefaultUniformBlock <Uniforms>();
                    }
                }
            }

            this.vertexBufferBuilder = new ReactiveBufferBuilder <Vertex>(
                PrimitiveType.Triangles,
                initialCapacity,
                new[] { 0, 2, 3, 0, 3, 1 },
                this.SubElements.Flatten());
        }
Example #3
0
            public MenuComponent(MyOTKEWindow view)
            {
                view.LockCursor = false;

                var systemInfo = new StringBuilder();

                systemInfo.AppendLine($"OpenGl version: {GL.GetString(StringName.Version)}");
                systemInfo.AppendLine($"OpenGl Shading Language version: {GL.GetString(StringName.ShadingLanguageVersion)}");
                systemInfo.AppendLine($"Vendor: {GL.GetString(StringName.Vendor)}");
                systemInfo.AppendLine($"Renderer: {GL.GetString(StringName.Renderer)}");

                AddComponent(new Gui(view, 1000)
                {
                    SubElements =
                    {
                        new Button(
                            layout: new Layout((0f,     0f), (0f,  0f), (200,   40), new Vector2(0,  70)),
                            color: Color.Blue(.5f),
                            textColor: Color.White(),
                            text: "FIRST PERSON DEMO",
                            v =>
                        {
                            view.RootComponent = new FirstPersonComponent(view);
                            this.Dispose();
                        }),
                        new Button(
                            layout: new Layout((0f,     0f), (0f,  0f), (200,   40), new Vector2(0,  10)),
                            color: Color.Blue(.5f),
                            textColor: Color.White(),
                            text: "ORBIT DEMO",
                            v =>
                        {
                            view.RootComponent = new OrbitComponent(view);
                            this.Dispose();
                        }),
                        new Button(
                            layout: new Layout((0f,     0f), (0f,  0f), (200,   40), new Vector2(0, -50)),
                            color: Color.Blue(.5f),
                            textColor: Color.White(),
                            text: "QUIT",
                            v => view.Close()),
                        new Text(
                            layout: new Layout((0f,    -1f), (0f, -1f), (1f,  100)),
                            color: Color.Grey(0.7f),
                            content: systemInfo.ToString())
                        {
                            HorizontalAlignment = 0.5f,
                        },
                    },
                });
Example #4
0
            public FirstPersonComponent(MyOTKEWindow view)
            {
                this.view = view;
                camera    = new FirstPersonCamera(
                    view,
                    movementSpeed: 3.0f,
                    rotationSpeed: 0.005f,
                    fieldOfViewRadians: (float)Math.PI / 4.0f,
                    nearPlaneDistance: 0.1f,
                    farPlaneDistance: 100f,
                    initialPosition: new Vector3(0f, 0f, 3f),
                    initialHorizontalAngleRadians: (float)Math.PI,
                    initialVerticalAngleRadians: 0f);

                var texturedTriangleVertices = new[]
                {
                    new TexturedStaticMesh.Vertex(
                        new Vector3(-1f, -1f, -2f),
                        new Vector2(0f, 0f),
                        new Vector3(0f, 0f, 1f)),
                    new TexturedStaticMesh.Vertex(
                        new Vector3(1f, -1f, -2f),
                        new Vector2(1f, 0f),
                        new Vector3(0f, 0f, 1f)),
                    new TexturedStaticMesh.Vertex(
                        new Vector3(0f, 1f, -2f),
                        new Vector2(0.5f, 1f),
                        new Vector3(0f, 0f, 1f)),
                };

                AddComponent(new TexturedStaticMesh(
                                 camera,
                                 texturedTriangleVertices,
                                 new uint[] { 0, 1, 2 },
                                 @"Assets\Textures\foo.bmp")
                {
                    AmbientLightColor = Color.Grey(),
                });

                var coloredTriangleVertices = new[]
                {
                    new ColoredStaticMesh.Vertex(
                        new Vector3(2f, 2f, -3f),
                        Color.Red(),
                        new Vector3(0f, 0f, 1f)),
                    new ColoredStaticMesh.Vertex(
                        new Vector3(-2f, 2f, -3f),
                        Color.Green(),
                        new Vector3(0f, 0f, 1f)),
                    new ColoredStaticMesh.Vertex(
                        new Vector3(0f, -2f, -3f),
                        Color.Blue(),
                        new Vector3(0f, 0f, 1f)),
                };

                AddComponent(new ColoredStaticMesh(
                                 camera,
                                 coloredTriangleVertices,
                                 new uint[] { 0, 1, 2 })
                {
                    AmbientLightColor = Color.Grey(),
                });

                AddComponent(new PrimitiveRenderer(camera, Observable.Return(cubeSubject), 12)
                {
                    AmbientLightColor      = Color.Grey(0.1f),
                    DirectedLightDirection = new Vector3(0, 1f, 0f),
                    DirectedLightColor     = Color.Grey(),
                });

                AddComponent(lines = new ColoredLines(camera)
                {
                    AmbientLightColor = Color.Grey(),
                });

                camTextElement = new Text(
                    new Layout((-1f, 1f), (-1f, 1f), (1f, 0f)),
                    color: Color.White());

                logElement = new TextStream(
                    new Layout((-1f, 1f), (-1f, 1f), (1f, 0f), new Vector2(0, -100)),
                    textColor: Color.White(),
                    10);

                AddComponent(new Gui(view, 1000)
                {
                    SubElements =
                    {
                        new Panel(
                            layout: new Layout((-1f, 0f), (-1f, 0f), (250, 1f)),
                            color: Color.White(0.05f))
                        {
                            SubElements =
                            {
                                camTextElement,
                                logElement,
                            },
                        },
                    },
                });