Exemple #1
0
        private void load()
        {
            models = new ContentManager <VertexBufferObject>("Data/Models/", new LoadContentFunction <VertexBufferObject>(
                                                                 (string name, string path) =>
                                                                 new VertexBufferObject(OBJLoader.loadModelfromOBJ(path + name + ".obj"))));
            textures = new ContentManager <Texture>("Data/Textures/", new LoadContentFunction <Texture>(
                                                        (string name, string path) =>
                                                        Texture.fromFile(path + name + ".png")));

            Mesh[] meshes = OBJLoader.loadModelfromOBJ("Data/Models/Motorrad.obj");
            models.add("motorcycle", new VertexBufferObject(meshes[0]));
            models.add("wheel", new VertexBufferObject(meshes[1]));
            textures.add("motorcycle", Texture.fromFile("Data/Textures/Motorrad.png"));

            Mesh[] tmmeshes = OBJLoader.loadModelfromOBJ("Data/Models/tm.obj");
            models.add("tachometer", new VertexBufferObject(tmmeshes[1]));
            models.add("tachometer|", new VertexBufferObject(tmmeshes[0]));
            textures.add("tachometer", Texture.fromFile("Data/Textures/tm2.png"));
            textures.add("tachometer|", Texture.fromFile("Data/Textures/tm.png"));

            meshes = OBJLoader.loadModelfromOBJ("Data/Models/tree.obj");
            models.add("tree", new VertexBufferObject(meshes[1]));
            models.add("leaf", new VertexBufferObject(meshes[0]));
            //textures.add("leafs",Texture.fromFile("Data/Textures/leafs.png",5));

            grassModel   = new VertexBufferObject(OBJLoader.loadModelfromOBJ("Data/Models/grass.obj")[0]);
            grassTexture = Texture.fromFile("Data/Textures/grass.png", 5);

            //Framebuffer
            GL.GenFramebuffers(1, out framebuffer);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer);

            //Depth texture
            GL.GenTextures(1, out depthTextureArray);
            GL.BindTexture(TextureTarget.Texture2DArray, depthTextureArray);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            //GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureCompareMode, (int)TextureCompareMode.CompareRToTexture);
            GL.TexImage3D(TextureTarget.Texture2DArray, 0, PixelInternalFormat.DepthComponent16, depthTextureWidth, depthTextureWidth, 3, 0, PixelFormat.DepthComponent, PixelType.Float, new IntPtr(0));
            GL.BindTexture(TextureTarget.Texture2DArray, 0);

            //--> framebuffer
            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, depthTextureArray, 0);

            GL.DrawBuffer(DrawBufferMode.None);
            GL.ReadBuffer(ReadBufferMode.None);

            FramebufferErrorCode ec = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (ec != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception("Framebuffer konnte nicht erstellt werden!");
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
Exemple #2
0
        private void load()
        {
            models = new ContentManager<VertexBufferObject>("Data/Models/", new LoadContentFunction<VertexBufferObject>(
                (string name, string path) =>
                    new VertexBufferObject(OBJLoader.loadModelfromOBJ(path + name + ".obj"))));
            textures = new ContentManager<Texture>("Data/Textures/", new LoadContentFunction<Texture>(
                (string name, string path) =>
                    Texture.fromFile(path + name + ".png")));

            Mesh[] meshes = OBJLoader.loadModelfromOBJ("Data/Models/Motorrad.obj");
            models.add("motorcycle", new VertexBufferObject(meshes[0]));
            models.add("wheel", new VertexBufferObject(meshes[1]));
            textures.add("motorcycle", Texture.fromFile("Data/Textures/Motorrad.png"));

            Mesh[] tmmeshes = OBJLoader.loadModelfromOBJ("Data/Models/tm.obj");
            models.add("tachometer", new VertexBufferObject(tmmeshes[1]));
            models.add("tachometer|", new VertexBufferObject(tmmeshes[0]));
            textures.add("tachometer", Texture.fromFile("Data/Textures/tm2.png"));
            textures.add("tachometer|", Texture.fromFile("Data/Textures/tm.png"));

            meshes = OBJLoader.loadModelfromOBJ("Data/Models/tree.obj");
            models.add("tree", new VertexBufferObject(meshes[1]));
            models.add("leaf", new VertexBufferObject(meshes[0]));
            //textures.add("leafs",Texture.fromFile("Data/Textures/leafs.png",5));

            grassModel = new VertexBufferObject(OBJLoader.loadModelfromOBJ("Data/Models/grass.obj")[0]);
            grassTexture = Texture.fromFile("Data/Textures/grass.png",5);

            //Framebuffer
            GL.GenFramebuffers(1, out framebuffer);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer);

            //Depth texture
            GL.GenTextures(1, out depthTextureArray);
            GL.BindTexture(TextureTarget.Texture2DArray, depthTextureArray);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            //GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureCompareMode, (int)TextureCompareMode.CompareRToTexture);
            GL.TexImage3D(TextureTarget.Texture2DArray, 0, PixelInternalFormat.DepthComponent16, depthTextureWidth, depthTextureWidth, 3, 0, PixelFormat.DepthComponent, PixelType.Float, new IntPtr(0));
            GL.BindTexture(TextureTarget.Texture2DArray, 0);

            //--> framebuffer
            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, depthTextureArray, 0);

            GL.DrawBuffer(DrawBufferMode.None);
            GL.ReadBuffer(ReadBufferMode.None);

            FramebufferErrorCode ec = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            if (ec != FramebufferErrorCode.FramebufferComplete)
                throw new Exception("Framebuffer konnte nicht erstellt werden!");

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }