Exemplo n.º 1
0
        protected override void OnLoad()
        {
            base.OnLoad();

            GL.Enable(EnableCap.DebugOutput);
            DebugProc openGLDebugDelegate = new DebugProc(OpenGLDebugCallback);

            GL.DebugMessageCallback(openGLDebugDelegate, IntPtr.Zero);

            // Create shader
            shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag");
            shader.Use();

            // Create target texture
            textureHandle = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, textureHandle);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

            Random random = new Random();

            byte[] pixels = new byte[64 * 32];
            for (int i = 0; i < 64 * 32; i++)
            {
                pixels[i] = (byte)(random.NextDouble() * 255.0f);
            }
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R8, 64, 32, 0, PixelFormat.Red, PixelType.UnsignedByte, pixels);

            // Create mesh
            float[] vertices = new float[]
            {
                // vec2 position
                // vec2 texCoord

                // Top left triangle
                -1, -1, 0, 1,
                1, -1, 1, 1,
                -1, 1, 0, 0,

                // Bottom right triangle
                1, -1, 1, 1,
                1, 1, 1, 0,
                -1, 1, 0, 0,
            };

            vboHandle = GL.GenBuffer();
            vaoHandle = GL.GenVertexArray();

            GL.BindVertexArray(vaoHandle);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vboHandle);

            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0 * sizeof(float));

            GL.EnableVertexAttribArray(1);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float));

            GL.BindVertexArray(vaoHandle);
            GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StreamDraw);

            // Load program
            byte[] fileBytes = File.ReadAllBytes("Roms/life.ch8");

            // Create emulator
            ushort[] instructions = new ushort[]
            {
                0x00E0, 0xF029, 0xD115, 0x7001, 0x1200
            };

            chip8 = new Chip8(fileBytes);
            //chip8 = new Chip8(instructions);

            chip8.DumpMemory();
        }