Пример #1
0
        void loadContent()
        {
            scenes = new List<Scene>();
            setProjectionMatrix();

            Dictionary<Enums.Textures, Texture> textures = new Dictionary<Enums.Textures, Texture>();
            Dictionary<Enums.MeshVBOs, MeshVBOs> meshVBOs = new Dictionary<Enums.MeshVBOs, MeshVBOs>();
            Dictionary<Enums.Shaders, ShaderProgram> shaders = new Dictionary<Enums.Shaders, ShaderProgram>();

            ShaderProgram defaultShader = new ShaderProgram(File.ReadAllText("content/shaders/defaultShader.vert"), File.ReadAllText("content/shaders/defaultShader.frag"), "defaultShader");
            //defaultShader.writeAllInfoLogs();
            Console.WriteLine(defaultShader.ProgramInfoLog);
            Console.WriteLine(defaultShader.ShaderInfoLog);
            defaultShader.Use();
            defaultShader.setUniform("lightPos", new Vector3(1,1,1));
            defaultShader.setUniform("ambientCoefficient", .1f);
            defaultShader.setUniform("lightIntensities", Vector3.One);

            ShaderProgram earthShader = new ShaderProgram(File.ReadAllText("content/shaders/earthShader.vert"), File.ReadAllText("content/shaders/earthShader.frag"), "earthShader");
            //earthShader.writeAllInfoLogs();
            Console.WriteLine(earthShader.ProgramInfoLog);
            earthShader.Use();
            earthShader.setUniform("lightPos", Vector3.Zero);
            earthShader.setUniform("lightIntensities", Vector3.One);

            ShaderProgram sunShader = new ShaderProgram(File.ReadAllText("content/shaders/defaultShader.vert"), File.ReadAllText("content/shaders/sunShader.frag"), "sunShader");
            Console.WriteLine(sunShader.ProgramInfoLog);
            //sunShader.writeAllInfoLogs();

            ShaderProgram lineShader = new ShaderProgram(File.ReadAllText("content/shaders/lineShader.vert"), File.ReadAllText("content/shaders/lineShader.frag"), "lineShader");
            Console.WriteLine(lineShader.ProgramInfoLog);
            //lineShader.writeAllInfoLogs();

            shaders.Add(Enums.Shaders.default_, defaultShader);
            shaders.Add(Enums.Shaders.earth, earthShader);
            shaders.Add(Enums.Shaders.sun, sunShader);
            shaders.Add(Enums.Shaders.line, lineShader);

            Console.Write("Loaded Shaders...");

            PlanetParameters planetParams = PlanetParameters.readFromFile("content/planetInfo.txt");
            ObjLoader loader = new ObjLoader();

            meshVBOs.Add(Enums.MeshVBOs.planet, loader.loadVBOS("content/models/sphere.obj"));
            meshVBOs.Add(Enums.MeshVBOs.saturnRings, loader.loadVBOS("content/models/saturnRings.obj"));
            meshVBOs.Add(Enums.MeshVBOs.uranusRings, loader.loadVBOS("content/models/uranusRings.obj"));

            Console.Write("Loading Textures...");

            textures.Add(Enums.Textures.starsT, new Texture("content/textures/stars.jpg"));
            textures.Add(Enums.Textures.sunT, new Texture("content/textures/sun4096g.jpg"));
            textures.Add(Enums.Textures.mercury, new Texture("content/textures/mercury4096.jpg"));
            textures.Add(Enums.Textures.venusT, new Texture("content/textures/venus4096.jpg"));
            textures.Add(Enums.Textures.earthT, new Texture("content/textures/earth4096.jpg"));
            textures.Add(Enums.Textures.earth_SpecT, new Texture("content/textures/earth_Spec4096.png"));
            textures.Add(Enums.Textures.earth_NightT, new Texture("content/textures/earth_Night4096.jpg"));
            textures.Add(Enums.Textures.earth_NormalT, new Texture("content/textures/earth_Normal4096.jpg"));
            textures.Add(Enums.Textures.earty_CloudsT, new Texture("content/textures/earth_Clouds4096.jpg"));
            textures.Add(Enums.Textures.moonT, new Texture("content/textures/moon4096.jpg"));
            textures.Add(Enums.Textures.marsT, new Texture("content/textures/mars4096.jpg"));
            textures.Add(Enums.Textures.jupiterT, new Texture("content/textures/jupiter4096.jpg"));
            textures.Add(Enums.Textures.saturnT, new Texture("content/textures/saturn2048.jpg"));
            textures.Add(Enums.Textures.uranusT, new Texture("content/textures/uranus2048.png"));
            textures.Add(Enums.Textures.neptuneT, new Texture("content/textures/neptune1024.png"));
            textures.Add(Enums.Textures.plutoT, new Texture("content/textures/pluto1024.jpg"));
            textures.Add(Enums.Textures.saturn_RingsT, new Texture("content/textures/saturnRings.png"));
            textures.Add(Enums.Textures.uranus_RingsT, new Texture("content/textures/uranusRings.png"));

            Console.Write(" done!\n");

            solarSystemScene = new SolarSystemScene(planetParams, meshVBOs, textures, shaders, hoursPerSecond, ZAxisLine, this.glPannel);
            scenes.Add(solarSystemScene);

            //planetSizeScene = new PlanetSizeScene(meshVBOs, textures, shaders);
            //scenes.Add(planetSizeScene);

            activeScene = scenes[0];

            Console.WriteLine("Created Scenes");
        }
Пример #2
0
        private void LoadContent()
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            scenes = new List <Scene>();

            ContentManager contentManager = new ContentManager($@"{Environment.CurrentDirectory}\content\");

            contentManager.ShaderFolder  = @"shaders\";
            contentManager.TextureFolder = @"textures\";
            contentManager.MeshFolder    = @"models\";

            //loading the shaders
            ShaderProgram defaultShader = contentManager.LoadShader("default");

            defaultShader.Initialize = () =>
            {
                defaultShader.Bind();
                defaultShader.SetUniform("lightPos", new Vector3(0, 0, 0));
                defaultShader.SetUniform("ambientCoefficient", .01f);
                defaultShader.SetUniform("lightIntensities", Vector3.One);
            };
            defaultShader.Init();

            //s = defaultShader;
            ShaderProgram earthShader = contentManager.LoadShader("earth");

            earthShader.Initialize = () =>
            {
                earthShader.Bind();
                //earthShader.SetUniform("lightIntensities", Vector3.One);
                earthShader.SetUniform("texture", 0);
                earthShader.SetUniform("specularTexture", 1);
                earthShader.SetUniform("nightTexture", 2);
                //earthShader.SetUniform("normalTexture", 3);
                //earthShader.SetUniform("cloudsTexture", 4);
            };
            earthShader.Init();

            ShaderProgram sunShader = contentManager.LoadShader("sunShader");

            ShaderProgram lineShader = contentManager.LoadShader("lineShader");

            Console.WriteLine($"loaded shaders: {watch.ElapsedMilliseconds}");
            watch.Restart();

            //loading models
            PlanetParameters planetParams = PlanetParameters.readFromFile("content/planetInfo.txt");

            contentManager.LoadVao("saturnRings");
            contentManager.LoadVao("sphere");
            contentManager.LoadVao("uranusRings");

            Console.WriteLine($"loaded meshes: {watch.ElapsedMilliseconds}");
            watch.Restart();

            //loading the textures
            contentManager.LoadTexture("sun4096g.jpg", "sun");
            contentManager.LoadTexture("mercury4096.jpg", "mercury");
            contentManager.LoadTexture("venus4096.jpg", "venus");
            contentManager.LoadTexture("earth4096.jpg", "earth");
            contentManager.LoadTexture("earth_Spec4096.png", "earth_spec");
            contentManager.LoadTexture("earth_Night4096.jpg", "earth_night");
            contentManager.LoadTexture("earth_Normal4096.jpg", "earth_normal");
            contentManager.LoadTexture("earth_Clouds4096.jpg", "earth_clouds");
            contentManager.LoadTexture("moon4096.jpg", "moon");
            contentManager.LoadTexture("mars4096.jpg", "mars");
            contentManager.LoadTexture("jupiter4096.jpg", "jupiter");
            contentManager.LoadTexture("saturn2048.jpg", "saturn");
            contentManager.LoadTexture("uranus2048.png", "uranus");
            contentManager.LoadTexture("neptune1024.png", "neptune");
            contentManager.LoadTexture("pluto1024.jpg", "pluto");
            //contentManager.LoadTexture("saturnRings.png");
            //contentManager.LoadTexture("uranusRings.png");

            Console.WriteLine($"loaded textures: {watch.ElapsedMilliseconds}");
            watch.Restart();

            var solarSystemScene = new SolarSystemScene(this, planetParams, contentManager);

            //var planetSizeScene = new PlanetSIzeScene(context, planetParams, contentManager, 1);

            scenes.Add(solarSystemScene);
            // _scenes.Add(planetSizeScene);
            currentScene = scenes[0];

            Console.WriteLine($"created scenes: {watch.ElapsedMilliseconds}");
            watch.Stop();
        }