Пример #1
0
 protected override void OnRenderFrame(FrameEventArgs e)
 {
     GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
     GL.ClearColor(Color.Blue);
     EngineCore.Render();
     GL.Flush();
     SwapBuffers();
 }
Пример #2
0
        public override void Draw()
        {
            GL.Enable(EnableCap.ClipDistance0);

            float dist = 2 * (EngineCore.gameCamera.position.Y - position.Y);

            EngineCore.gameCamera.position.Y -= dist;
            EngineCore.gameCamera.rotation.X *= -1;
            EngineCore.gameCamera.CalculateMatrices(false);

            EngineCore.shaders["Default"].SetClippingPlane(new Vector4(0, 1, 0, -position.Y + 0.1f));
            reflection.Bind();
            EngineCore.RenderWithout(this);
            reflection.UnBind();

            EngineCore.gameCamera.position.Y += dist;
            EngineCore.gameCamera.rotation.X *= -1;
            EngineCore.gameCamera.CalculateMatrices(false);


            EngineCore.shaders["Default"].SetClippingPlane(new Vector4(0, -1, 0, position.Y + 0.1f));
            refraction.Bind();
            EngineCore.RenderWithout(this);
            refraction.UnBind();

            EngineCore.shaders["Default"].SetClippingPlane(new Vector4(0, 0, 0, 0));

            GL.Disable(EnableCap.ClipDistance0);

            GL.UseProgram(GetShader().ProgramID);

            GL.BindVertexArray(GetMesh().vaoID);
            GetShader().currentObject = this;
            GetShader().Start();

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, reflection.textureAttachment);

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, refraction.textureAttachment);

            GL.ActiveTexture(TextureUnit.Texture2);
            GL.BindTexture(TextureTarget.Texture2D, GetTexture().texID); //DuDv Map

            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture2D, GetNormalMap().texID);

            GL.ActiveTexture(TextureUnit.Texture4);
            GL.BindTexture(TextureTarget.Texture2D, refraction.depthTextureAttachment);

            GL.DrawElements(PrimitiveType.Triangles, GetMesh().indices.Count, DrawElementsType.UnsignedInt, 0);

            GetShader().Stop();
            GL.BindVertexArray(0);
        }
Пример #3
0
        public FrameBuffer(Vector2 imgScale, string name, bool depthTexture, bool texture = true)
        {
            this.imgScale = imgScale;
            this.texture  = texture;

            GL.GenFramebuffers(1, out frameBuffer);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);
            if (texture)
            {
                GL.DrawBuffer(DrawBufferMode.ColorAttachment0);

                textureAttachment = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, textureAttachment);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, (int)imgScale.X, (int)imgScale.Y, 0, PixelFormat.Rgb, PixelType.UnsignedByte, (IntPtr)null);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, textureAttachment, 0);
            }
            else
            {
                GL.DrawBuffer(DrawBufferMode.None);
                GL.ReadBuffer(ReadBufferMode.None);
            }



            if (depthTexture)
            {
                depthTextureAttachment = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, depthTextureAttachment);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, (int)imgScale.X, (int)imgScale.Y, 0, PixelFormat.DepthComponent, PixelType.Float, (IntPtr)null);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachmentExt, depthTextureAttachment, 0);
            }
            else
            {
                GL.GenRenderbuffers(1, out depthBuffer);
                GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBuffer);
                GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent, (int)imgScale.X, (int)imgScale.Y);
                GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthBuffer);
            }


            UnBind();

            Texture fbo = new Texture(textureAttachment, (int)imgScale.X, (int)imgScale.Y);

            EngineCore.AddTexture(fbo, name);
        }
Пример #4
0
        public void LoadShaderFromFile(String filename, ShaderType type)
        {
            string fullFilename = "Assets/Shaders/" + filename;

            EngineCore.CheckFilepath(fullFilename);
            string shaderBody = File.ReadAllText(fullFilename);

            if (type == ShaderType.VertexShader)
            {
                VShaderID = LoadShader(shaderBody, type);
            }
            else if (type == ShaderType.FragmentShader)
            {
                FShaderID = LoadShader(shaderBody, type);
            }
        }
Пример #5
0
 public void AddUniform(string name, int location, UniformDataType type)
 {
     EngineCore.CheckDuplicateName(Uniforms.Keys, name);
     Uniforms.Add(name, new Uniform(location, type));
     UniformsFilled.Add(name, false);
 }
Пример #6
0
 public void AddAttribute(string name, int location)
 {
     EngineCore.CheckDuplicateName(Attributes.Keys, name);
     Attributes.Add(name, location);
 }
Пример #7
0
        static void Main(string[] args)
        {
            Window w = new Window(1920, 1080);

            EngineCore.AddImage("default.png", "default");

            DefaultShader ds            = new DefaultShader("default.vert", "default.frag");
            String        defaultShader = EngineCore.AddShader(ds, "Default");

            GUIShader gui       = new GUIShader("gui.vert", "gui.frag");
            String    guiShader = EngineCore.AddShader(gui, "GUI");

            WaterShader water       = new WaterShader("water.vert", "water.frag");
            String      waterShader = EngineCore.AddShader(water, "Water");

            SkyboxShader skybox       = new SkyboxShader("skybox.vert", "skybox.frag");
            String       skyboxShader = EngineCore.AddShader(skybox, "Skybox");

            ShadowShader shadow       = new ShadowShader("shadow.vert", "shadow.frag");
            String       shadowShader = EngineCore.AddShader(shadow, "Shadow");

            TerrainShader terrain       = new TerrainShader("terrain.vert", "terrain.frag");
            String        terrainShader = EngineCore.AddShader(terrain, "Terrain");


            String cubeModel    = EngineCore.AddModel("cubeything.obj", "cube");
            String terrainModel = EngineCore.AddModel("terrain.obj", "terrain");
            String quad         = EngineCore.AddModel("quad.obj", "Quad");
            String cubeObj      = EngineCore.AddModel("cube.obj", "Cube");

            EngineCore.AddModel("tree.obj", "tree");
            EngineCore.AddModel("rock.obj", "rock");



            Light l = new Light(new Vector3(0, 3, 0), System.Drawing.Color.White);

            ds.lights.Add(l);
            terrain.lights.Add(l);

            Light l2 = new Light(new Vector3(0, 10, 0), System.Drawing.Color.White);

            water.lights.Add(l2);

            EngineCore.AddImage("tree.png", "treeImg");
            EngineCore.AddImage("rock.png", "rockImg");

            String boatObj = EngineCore.AddModel("boat.obj", "Boat");

            EngineCore.AddImage("boards.jpg", "Boards");
            Boat boat = new Boat(new Vector3(2, 0.2f, 2), new Vector3(0, 34, 0), new Vector3(0.25f, 0.25f, 0.25f), "Boards");

            EngineCore.AddObject("Boat", boat);

            String  ground     = EngineCore.AddImage("grass.jpg", "Ground");
            Terrain terrainObj = new Terrain("New Terrain", "Ground", "heightMap.png");

            EngineCore.AddObject("Terrain", terrainObj);

            EngineCore.AddImage("dudv.png", "DuDvMap");
            EngineCore.AddImage("normal.png", "NormalMap");
            Water waterObj = new Water(new Vector3(0, 0.25f, 0), System.Drawing.Color.Blue, new Vector2(1920, 1080), "DuDvMap", new Vector3(10, 10, 10));

            waterObj.AttachNormalMap("NormalMap");
            EngineCore.AddObject("water", waterObj);

            EngineCore.AddSkybox(new string[] { "Skybox/xpos.png",
                                                "Skybox/xneg.png",
                                                "Skybox/ypos.png",
                                                "Skybox/yneg.png",
                                                "Skybox/zpos.png",
                                                "Skybox/zneg.png" }, "Skybox", 500);

            w.Run();
        }
Пример #8
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            EngineCore.gameCamera.Update();
            if (Keyboard[Key.Escape])
            {
                Exit();
            }
            EngineCore.gameCamera.rotation.Y += 0.08f * (Mouse.GetState().X - lastMousePosition.X);
            EngineCore.gameCamera.rotation.X += 0.08f * (Mouse.GetState().Y - lastMousePosition.Y);
            if (!selecting)
            {
                if (Keyboard[Key.W])
                {
                    EngineCore.gameCamera.position -= EngineCore.gameCamera.forward * 0.15f;
                }
                if (Keyboard[Key.S])
                {
                    EngineCore.gameCamera.position += EngineCore.gameCamera.forward * 0.15f;
                }
                if (Keyboard[Key.D])
                {
                    EngineCore.gameCamera.position += EngineCore.gameCamera.right * 0.15f;
                }
                if (Keyboard[Key.A])
                {
                    EngineCore.gameCamera.position -= EngineCore.gameCamera.right * 0.15f;
                }
            }
            else
            {
                if (Keyboard[Key.W])
                {
                    EngineCore.selected.position -= new Vector3(EngineCore.gameCamera.forward.X, 0, EngineCore.gameCamera.forward.Z) * 0.15f;
                }
                if (Keyboard[Key.S])
                {
                    EngineCore.selected.position += new Vector3(EngineCore.gameCamera.forward.X, 0, EngineCore.gameCamera.forward.Z) * 0.15f;
                }
                if (Keyboard[Key.D])
                {
                    EngineCore.selected.position += new Vector3(EngineCore.gameCamera.right.X, 0, EngineCore.gameCamera.right.Z) * 0.15f;
                }
                if (Keyboard[Key.A])
                {
                    EngineCore.selected.position -= new Vector3(EngineCore.gameCamera.right.X, 0, EngineCore.gameCamera.right.Z) * 0.15f;
                }
                if (Keyboard[Key.Q])
                {
                    EngineCore.selected.position.Y -= 0.025f;
                }
                if (Keyboard[Key.E])
                {
                    EngineCore.selected.position.Y += 0.025f;
                }

                EngineCore.gameCamera.position += EngineCore.gameCamera.forward * Mouse.GetState().WheelPrecise * 0.001f;
            }

            if (Keyboard[Key.Number1] && !num1Down)
            {
                RenderedEntity tree = new RenderedEntity(Vector3.Zero, new Vector3(0, rotationGenerator.Next(360), 0), Vector3.One * ((float)rotationGenerator.NextDouble() * 0.5f + 0.5f), "tree", "Default", "treeImg");
                EngineCore.AddObject("tree" + num, tree);
                num++;
                num1Down            = true;
                EngineCore.selected = tree;
                selecting           = true;
            }
            if (!Keyboard[Key.Number1])
            {
                num1Down = false;
            }

            if (Keyboard[Key.Number2] && !num2Down)
            {
                RenderedEntity rock = new RenderedEntity(Vector3.Zero, new Vector3(0, rotationGenerator.Next(360), 0), Vector3.One * ((float)rotationGenerator.NextDouble() * 0.2f + 0.2f), "rock", "Default", "rockImg");
                EngineCore.AddObject("rock" + num, rock);
                num++;
                num2Down            = true;
                EngineCore.selected = rock;
                selecting           = true;
            }
            if (!Keyboard[Key.Number2])
            {
                num2Down = false;
            }

            if (Keyboard[Key.Enter])
            {
                selecting = false;
            }

            if (Keyboard[Key.Up])
            {
                ((Water)EngineCore.gameObjects["water"]).position.Y += 0.05f;
                EngineCore.gameObjects["Boat"].position.Y           += 0.05f;
            }
            if (Keyboard[Key.Down])
            {
                ((Water)EngineCore.gameObjects["water"]).position.Y -= 0.05f;
                EngineCore.gameObjects["Boat"].position.Y           -= 0.05f;
            }
            EngineCore.gameCamera.CalculateMatrices(false);
            lastMousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
        }