Esempio n. 1
0
        private void prepareTerrain(Terrain terrain)
        {
            RawModel rawModel = terrain.model;

            Gl.BindVertexArray(rawModel.vaoID);
            Gl.EnableVertexAttribArray(0);
            Gl.EnableVertexAttribArray(1);
            Gl.EnableVertexAttribArray(2);
            ModelTexture texture = terrain.texture;

            shader.loadVariables(texture.shineDamper, texture.reflectivity);
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(TextureTarget.Texture2d, texture.textureId);
        }
Esempio n. 2
0
        private void prepareTexturedModel(TexturedModel model)
        {
            RawModel rawModel = model.rawModel;

            Gl.BindVertexArray(rawModel.vaoID);
            Gl.EnableVertexAttribArray(0);
            Gl.EnableVertexAttribArray(1);
            Gl.EnableVertexAttribArray(2);
            ModelTexture texture = model.modelTexture;

            if (texture.isHasTransparency)
            {
                MasterRenderer.disableCulling();
            }
            shader.loadFakeLighting(texture.isUseFakeLighting);
            shader.loadVariables(texture.shineDamper, texture.reflectivity);
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(TextureTarget.Texture2d, model.modelTexture.textureId);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Initialize OpenGL
            Gl.Initialize();

            // If the library isn't in the environment path we need to set it
            Glfw.ConfigureNativesDirectory("..\\..\\libs/glfw-3.2.1.bin.WIN32/lib-mingw");

            // Initialize the GLFW
            if (!Glfw.Init())
            {
                Environment.Exit(-1);
            }

            // Create a windowed mode window and its OpenGL context
            var window = Glfw.CreateWindow(width, height, "Unreal Engine 4");


            if (!window)
            {
                Glfw.Terminate();
                Environment.Exit(-1);
            }

            // set window icon
            Glfw.Image icon = Utils.getImage("..\\..\\res/logo.png");
            Glfw.SetWindowIcon(window, icon);

            // Make the window's context current
            Glfw.MakeContextCurrent(window);

            // create loder and renderer
            Loader loader = new Loader();


            // create models
            RawModel      fern         = OBJLoader.loadObjModel("fern", loader);
            ModelTexture  fernTexture  = new ModelTexture(loader.loadTexture("..\\..\\res/fern.png"));
            TexturedModel texturedFern = new TexturedModel(fern, fernTexture);

            texturedFern.modelTexture.shineDamper       = 10;
            texturedFern.modelTexture.reflectivity      = 0;
            texturedFern.modelTexture.isHasTransparency = true;

            RawModel      grass         = OBJLoader.loadObjModel("grassModel", loader);
            ModelTexture  grassTexture  = new ModelTexture(loader.loadTexture("..\\..\\res/grassTexture.png"));
            TexturedModel texturedGrass = new TexturedModel(grass, grassTexture);

            texturedGrass.modelTexture.shineDamper       = 10;
            texturedGrass.modelTexture.reflectivity      = 0;
            texturedGrass.modelTexture.isHasTransparency = true;
            texturedGrass.modelTexture.isUseFakeLighting = true;

            RawModel      model       = OBJLoader.loadObjModel("lowPolyTree", loader);
            ModelTexture  texture     = new ModelTexture(loader.loadTexture("..\\..\\res/lowPolyTree.png"));
            TexturedModel staticModel = new TexturedModel(model, texture);

            staticModel.modelTexture.shineDamper  = 10;
            staticModel.modelTexture.reflectivity = 0f;
            Entity entity = new Entity(staticModel, new Vertex3f(0, 0, -25), 0, 0, 0, 1);
            Light  light  = new Light(new Vertex3f(0, 0, -20), new Vertex3f(1f, 1f, 1f));

            Random       rand           = new Random();
            ModelTexture terrainTexture = new ModelTexture(loader.loadTexture("..\\..\\res/grass.png"));

            terrainTexture.shineDamper  = 10;
            terrainTexture.reflectivity = 0;
            Terrain terrain  = new Terrain(800, 0, loader, terrainTexture);
            Terrain terrain2 = new Terrain(800, -800, loader, terrainTexture);

            Random random = new Random();

            Camera camera = new Camera();

            List <Entity> allTrees = new List <Entity>();
            List <Entity> allGrass = new List <Entity>();
            List <Entity> allFerns = new List <Entity>();

            for (int i = 0; i < 1000; i++)
            {
                double x = random.NextDouble() * -1600 + 800;
                double y = 0;
                double z = random.NextDouble() * -2410;
                allTrees.Add(new Entity(staticModel, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, rand.Next(1, 4)));
            }
            for (int i = 0; i < 1000; i++)
            {
                double x = random.NextDouble() * -1600 + 800;
                double y = 0;
                double z = random.NextDouble() * -2410;
                allGrass.Add(new Entity(texturedGrass, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3));
            }
            for (int i = 0; i < 1000; i++)
            {
                double x = random.NextDouble() * -1600 + 800;
                double y = 0;
                double z = random.NextDouble() * -2410;
                allFerns.Add(new Entity(texturedFern, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3));
            }

            MasterRenderer renderer = new MasterRenderer(new WinowInfo(width, height));

            // Loop until the user closes the window
            while (!Glfw.WindowShouldClose(window))
            {
                entity.increaseRotation(0, 1, 0);

                // Render here
                camera.move(window);

                renderer.processTerrain(terrain);
                renderer.processTerrain(terrain2);

                foreach (Entity tree in allTrees)
                {
                    renderer.processEntity(tree);
                }
                foreach (Entity gr in allGrass)
                {
                    renderer.processEntity(gr);
                }
                foreach (Entity fr in allFerns)
                {
                    renderer.processEntity(fr);
                }


                renderer.render(light, camera);
                Glfw.SwapBuffers(window);

                // Poll for and process events
                Glfw.PollEvents();
            }

            // clean memory
            renderer.cleanUP();
            loader.CleanUp();

            // terminate program
            Glfw.Terminate();
        }