Exemplo n.º 1
0
 public static void UpdateLevel(OpenGlRenderer renderer, List <GameObject>[] level)
 {
     //Console.WriteLine(renderer.level.Length);
     Modell combined = CombineModells.Combine(CombineModells.GameObjectToModellArray(Init.ChunksToGameObjects(Init.NearChunck(level.ToArray(), renderer.player_pos, 50)).ToArray()));
     //Console.WriteLine(combined.vertices.Length);
     //Console.WriteLine(combined.uv.Length);
     //Console.WriteLine(combined.normal.Length);
     //renderer.UpdateBuffers(combined.vertices, combined.uv, combined.normal);
 }
Exemplo n.º 2
0
        void loaded(object o, EventArgs e)
        {
            input.lastPos = new Vector2(Mouse.GetCursorState().X, Mouse.GetCursorState().Y);
            //texture = LoadResources.ReadTexture(Directory.GetCurrentDirectory() + @"\Mods\Default\Textures\earth.jpg");
            //Change clear color
            GL.ClearColor(Color.Black);
            //Render polygons in a correct order
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.TextureCoordArray);
            //Setup buffers

            //Vertex buffer

            VEB = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, VEB);
            GL.BufferData <Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(Vector3.SizeInBytes * vertexBuffer.Length),
                                    vertexBuffer, BufferUsageHint.DynamicDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            //Uv buffer

            UVB = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, UVB);
            GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * uvBuffer.Length),
                                    uvBuffer, BufferUsageHint.DynamicDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            //Normal buffer

            NOB = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, UVB);
            GL.BufferData <Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(Vector3.SizeInBytes * normalBuffer.Length),
                                    normalBuffer, BufferUsageHint.DynamicDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            level = LevelGenerator.GenerateTerrain3D(20, 20, 20, .05f, 0, .5f);
            //Console.WriteLine(renderer.level.Length);
            Modell combined = CombineModells.Combine(CombineModells.GameObjectToModellArray(Init.ChunksToGameObjects(Init.NearChunck(level.ToArray(), player_pos, 9999)).ToArray()));

            //Console.WriteLine(combined.vertices.Length);
            //Console.WriteLine(combined.uv.Length);
            //Console.WriteLine(combined.normal.Length);

            UpdateBuffers(combined.vertices, combined.uv, combined.normal, combined.textures, combined.colors);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Modell     mesh   = LoadResources.ReadModell(Directory.GetCurrentDirectory() + @"\Mods\Default\Modells\cube.obj");//LoadObj.LoadModellFromObj(Directory.GetCurrentDirectory()+@"\Mods\Default\Modells\cube.obj");
            GameWindow window = new GameWindow(640, 480);

            List <GameObject>[] localLevel = LevelGenerator.GenerateTerrain3D(20, 20, 20, .05f, 0, .5f);
            OpenGlRenderer      renderer   = new OpenGlRenderer(window);

            renderer.ImmediateRendering = false;
            renderer.Quad = false;
            GameObject obj = new GameObject("test", new Vector3(1, 3, 2), Vector3.Zero, Vector3.One, mesh);

            renderer.level = localLevel;
            //Console.WriteLine(renderer.level.Length);
            Modell combined = CombineModells.Combine(CombineModells.GameObjectToModellArray(ChunksToGameObjects(NearChunck(renderer.level.ToArray(), renderer.player_pos, 9999)).ToArray()));

            //Console.WriteLine(combined.vertices.Length);
            //Console.WriteLine(combined.uv.Length);
            //Console.WriteLine(combined.normal.Length);
            renderer.UpdateBuffers(combined.vertices, combined.uv, combined.normal, combined.textures, combined.colors);
            window.Run(1 / DisplayDevice.Default.RefreshRate);
        }