Example #1
0
        public GuiLayer(Window w, GlProgram pgm, IVertexCoder <GuiVertex> coder, Font fnt)
        {
            _win   = w ?? throw new ArgumentNullException(nameof(w));
            _pgm   = pgm ?? throw new ArgumentNullException(nameof(pgm));
            _array = new VertexArray <GuiVertex>(coder, 4)
            {
                [0] = new GuiVertex(new Vector2(0, 0), new Vector2(0, 1)),
                [1] = new GuiVertex(new Vector2(1, 0), new Vector2(1, 1)),
                [2] = new GuiVertex(new Vector2(1, 1), new Vector2(1, 0)),
                [3] = new GuiVertex(new Vector2(0, 1), new Vector2(0, 0))
            };
            _indices = new IndexBuffer(6, _array)
            {
                [0] = 0,
                [1] = 1,
                [2] = 2,
                [3] = 0,
                [4] = 2,
                [5] = 3,
            };
            _font = fnt ?? throw new ArgumentNullException(nameof(fnt));

            _uColor = pgm.GetUniform("uColor");
            _uColor.EnsureType(new ShaderElementType(PrimitiveTypes.Float, 4));
            _uTexture = pgm.GetUniform("uTexture");
            _uTexture.EnsureType(new ShaderElementType(PrimitiveTypes.Sampler, 2));
            _uTextureEnabled = pgm.GetUniform("uTextureEnabled");
            _uTextureEnabled.EnsureType(new ShaderElementType(PrimitiveTypes.Bool, 1));
            _uTransform = pgm.GetUniform("uTransform");
            _uTransform.EnsureType(new ShaderElementType(PrimitiveTypes.Matrix, 4));
            _uScale = pgm.GetUniform("uScale");
            _uScale.EnsureType(new ShaderElementType(PrimitiveTypes.Float, 2));
        }
Example #2
0
        /// <summary>
        /// Init shaders registered in global repository 'programs'.
        /// </summary>
        /// <returns>True if succeeded.</returns>
        bool SetupShaders()
        {
            activeProgram = null;

            foreach (var programInfo in programs.Values)
            {
                if (programInfo.Setup())
                {
                    activeProgram = programInfo.program;
                }
            }

            if (activeProgram == null)
            {
                return(false);
            }

            GlProgramInfo defInfo;

            if (programs.TryGetValue("default", out defInfo) &&
                defInfo.program != null)
            {
                activeProgram = defInfo.program;
            }

            return(true);
        }
 /// <summary>
 /// Installs a given program as part of the current rendering state, then draws this array object.
 /// </summary>
 /// <typeparam name="TAttr1">The type of the 1st attribute buffer object of the VAO.</typeparam>
 /// <param name="vao">The VAO to use.</param>
 /// <param name="program">The program to use.</param>
 /// <param name="count">The number of vertices to draw, or -1 to draw all vertices.</param>
 public static void Draw <TAttr1>(
     this IVertexArrayObject <TAttr1> vao,
     GlProgram program,
     int count = -1)
     where TAttr1 : struct
 {
     program.Use();
     vao.Draw(count);
 }
 /// <summary>
 /// Installs a given program as part of the current rendering state, then draws this array object.
 /// </summary>
 /// <typeparam name="TAttr1">The type of the 1st attribute buffer object of the VAO.</typeparam>
 /// <typeparam name="TAttr2">The type of the 2nd attribute buffer object of the VAO.</typeparam>
 /// <typeparam name="TUbo1">The type of the 1st uniform buffer object of the program.</typeparam>
 /// <param name="vao">The VAO to use.</param>
 /// <param name="program">The program to use.</param>
 /// <param name="count">The number of vertices to draw, or -1 to draw all vertices.</param>
 public static void Draw <TAttr1, TAttr2, TUbo1>(
     this IVertexArrayObject <TAttr1, TAttr2> vao,
     GlProgram <TUbo1> program,
     int count = -1)
     where TAttr1 : struct
     where TAttr2 : struct
     where TUbo1 : struct
 {
     program.Use();
     vao.Draw(count);
 }
Example #5
0
        public void DestroyResources()
        {
            DestroyTexture();

            activeProgram = null;
            programs.Clear();

            if (VBOid != null &&
                VBOid[0] != 0)
            {
                GL.DeleteBuffers(2, VBOid);
                VBOid = null;
            }
        }
Example #6
0
        protected override void OnInitialize()
        {
            SphereModel sphere = new SphereModel(_coder, SPHERE_BREAKUPS);

            GlProgram wProgram = new GlProgram(
                new Shader(ShaderTypes.Vertex, File.ReadAllText(Path.Combine(SHADERS_DIR, WORLD_SHADERS, "vertex.glsl"))),
                new Shader(ShaderTypes.Fragment, File.ReadAllText(Path.Combine(SHADERS_DIR, WORLD_SHADERS, "fragment.glsl")))
                );

            GlProgram gProgram = new GlProgram(
                new Shader(ShaderTypes.Vertex, File.ReadAllText(Path.Combine(SHADERS_DIR, GUI_SHADERS, "vertex.glsl"))),
                new Shader(ShaderTypes.Fragment, File.ReadAllText(Path.Combine(SHADERS_DIR, GUI_SHADERS, "fragment.glsl")))
                );

            _universe.Add(new SpaceObject(2, 100000, sphere)
            {
                Position = new Vector3(0, 0, 0)
            });
            _universe.Add(new SpaceObject(8, 50, sphere)
            {
                Position = new Vector3(-500, -500, 0), Velocity = new Vector3(30f, 0, -5f)
            });
            _universe.Add(new SpaceObject(0, 250, sphere)
            {
                Position = new Vector3(500, -500, 0), Velocity = new Vector3(30f, 0, 5f)
            });
            _universe.Add(_rocket = new RocketObject(55, new RocketModel(_coder))
            {
                Position = new Vector3(500, 500, 500), Velocity = new Vector3(-30f, 0f, 0f)
            });

            RenderHandle handle = new RenderHandle(this, wProgram);

            _layer = new SceneLayer(_universe, handle);
            AddLayer(_layer);
            _cam = new OrbitalCamera(_layer.Camera)
            {
                Distance = 250
            };
            Font fnt = new Font(Path.Combine(ASSETS_DIR, FONT_DIR, FONT_FILE));

            AddLayer(new GuiFuelLayer(_rocket, this, gProgram, new GuiVertexCoder(), fnt));
            GuiLayer tutorial = new GuiLayer(this, gProgram, new GuiVertexCoder(), fnt);

            tutorial.Add(_tutorialLbl);
            AddLayer(tutorial);
            Background = new Color(50, 50, 50, 255);
            base.OnInitialize();
        }
Example #7
0
        public RenderHandle(Window win, GlProgram program)
        {
            Window       = win ?? throw new ArgumentNullException(nameof(win));
            Program      = program;
            _uModel      = program.GetUniform(UNIFORM_MODEL);
            _uView       = program.GetUniform(UNIFORM_VIEW);
            _uProjection = program.GetUniform(UNIFORM_PROJECTION);
            _uShade      = program.GetUniform(UNIFORM_SHADE);
            _uMaterial   = new MaterialUniform(program.GetUniform($"{UNIFORM_MATERIAL}.ambient"), program.GetUniform($"{UNIFORM_MATERIAL}.diffusion"), program.GetUniform($"{UNIFORM_MATERIAL}.color"));
            _uLightCount = program.GetUniform(UNIFORM_LIGHT_COUNT);

            for (uint i = 0; i < LIGHT_LIMIT; i++)
            {
                _uLight[i] = new LightUniform(program.GetUniform($"{UNIFORM_LIGHT}[{i}].position"), program.GetUniform($"{UNIFORM_LIGHT}[{i}].color"), program.GetUniform($"{UNIFORM_LIGHT}[{i}].intensity"));
            }

            _uModel.EnsureType(new ShaderElementType(PrimitiveTypes.Matrix, 4));
            _uView.EnsureType(new ShaderElementType(PrimitiveTypes.Matrix, 4));
            _uProjection.EnsureType(new ShaderElementType(PrimitiveTypes.Matrix, 4));
            _uShade.EnsureType(new ShaderElementType(PrimitiveTypes.Bool, 1));
        }
Example #8
0
 public void Create()
 {
     _Program = new GlProgram(_VertexSourceGL, _FragmentSourceGL);
 }
Example #9
0
 public GuiFuelLayer(RocketObject rkt, Window w, GlProgram pgm, IVertexCoder <GuiVertex> coder, Font fnt) : base(w, pgm, coder, fnt)
 {
     _rkt     = rkt ?? throw new ArgumentNullException(nameof(rkt));
     _fuelPbr = new ProgressBar();
     Add(_fuelPbr);
 }
Example #10
0
 public void Create()
 {
     // Create program
     _Program = new GlProgram(_VertexSourceGLES2, _FragmentSourceGLES2);
 }