Пример #1
0
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.SkyBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            mShader = new ShaderUtility(@"ACW/Shaders/vPassThrough.vert", @"ACW/Shaders/fLighting.frag");
            GL.UseProgram(mShader.ShaderProgramID);
            int vPositionLocation  = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation    = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int vTexCoordsLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vTexCoords");

            GL.GenVertexArrays(mVAO_IDs.Length, mVAO_IDs);
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            //ground
            Textures.LoadTexture(mTexture_ID, 0, mShader);
            Ground.GroundMethod(mVAO_IDs, mVBO_IDs, vPositionLocation, vNormalLocation, vTexCoordsLocation);

            //armadillo

            Textures.LoadTexture(mTexture_ID, 1, mShader);
            mArmadilloModelUtility = ModelUtility.LoadModel(@"Utility/Models/model.bin");
            Armadillo.ArmadilloMethod(mVAO_IDs, mVBO_IDs, mArmadilloModelUtility, vPositionLocation, vNormalLocation, vTexCoordsLocation);

            //Cylinder Model

            Textures.LoadTexture(mTexture_ID, 2, mShader);
            mCylinderModelUtility = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");
            Cylinder.CyclinderMethod(mVAO_IDs, mVBO_IDs, mCylinderModelUtility, vPositionLocation, vNormalLocation, vTexCoordsLocation);

            //Sphere Model

            Textures.LoadTexture(mTexture_ID, 3, mShader);
            mSphereModelUtility = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
            Sphere.SphereMethod(mVAO_IDs, mVBO_IDs, mSphereModelUtility, vPositionLocation, vNormalLocation, vTexCoordsLocation);

            // End

            mView = Matrix4.CreateTranslation(0.0f, -1.5f, 0.0f);
            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");

            GL.UniformMatrix4(uView, true, ref mView);

            mGroundModel = Matrix4.CreateTranslation(0.0f, 0.0f, -5.0f);

            mArmadilloModel = Matrix4.CreateTranslation(0.0f, 3.0f, -5.0f); //sets armadillo position
            Vector3 t                  = mArmadilloModel.ExtractTranslation();
            Matrix4 translation        = Matrix4.CreateTranslation(t);
            Matrix4 inverseTranslation = Matrix4.CreateTranslation(-t);

            mArmadilloModel = mArmadilloModel * inverseTranslation * Matrix4.CreateRotationY(-1.7f) * translation; // rotates armadillo

            mCylinderModel = Matrix4.CreateTranslation(0.0f, 1.0f, -5.0f);                                         //sets cylidner position

            mSphereModel = Matrix4.CreateTranslation(5.0f, currentPosition, -3.0f);                                //sets Sphere position

            base.OnLoad(e);
        }
Пример #2
0
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.DodgerBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);


            mModel  = ModelUtility.LoadModel(@"Utility/Models/lab22model.sjg");
            mShader = new ShaderUtility(@"Lab2/Shaders/vLab22.vert", @"Lab2/Shaders/fSimple.frag");
            GL.UseProgram(mShader.ShaderProgramID);

            mView = Matrix4.CreateTranslation(0, 0, -2);
            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");

            GL.UniformMatrix4(uView, true, ref mView);

            int     uProjectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uProjection");
            Matrix4 projection          = Matrix4.CreateOrthographic(10, 10, -1, 1);

            GL.UniformMatrix4(uProjectionLocation, true, ref projection);

            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vColourLocation   = GL.GetAttribLocation(mShader.ShaderProgramID, "vColour");

            mVAO_ID = GL.GenVertexArray();
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            GL.BindVertexArray(mVAO_ID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mModel.Vertices.Length * sizeof(float)), mModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mModel.Indices.Length * sizeof(float)), mModel.Indices, BufferUsageHint.StaticDraw);

            int size;

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vColourLocation);
            GL.VertexAttribPointer(vColourLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 3 * sizeof(float));

            GL.BindVertexArray(0);

            base.OnLoad(e);
        }
Пример #3
0
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.DodgerBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            //Loading stuff
            middleCube = ModelUtility.LoadModel(@"Utility/Models/cube_middle.sjg");
            endCube    = ModelUtility.LoadModel(@"Utility/Models/cube_end.sjg");
            topCube    = ModelUtility.LoadModel(@"Utility/Models/cube_top.sjg");
            sphere     = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
            cylinder   = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");
            mShader    = new ShaderUtility(@"ACW/Shaders/VertexShader.vert", @"ACW/Shaders/FragmentShader.frag");
            mView      = Matrix4.CreateTranslation(0, -0.3f, -1f);
            GL.UseProgram(mShader.ShaderProgramID);
            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormal           = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int uView             = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");

            GL.UniformMatrix4(uView, true, ref mView);
            int     uProjectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uProjection");
            Matrix4 projection          = Matrix4.CreatePerspectiveFieldOfView(1, (float)ClientRectangle.Width / ClientRectangle.Height, 0.001f, 5);

            GL.UniformMatrix4(uProjectionLocation, true, ref projection);
            for (int i = 0; i < 100; ++i)
            {
                float x = random.Next(0, 180);
                x = (x - 90) / 1000;
                float y = random.Next(0, 180);
                y = (y - 90) / 1000;
                mRedSpherePosition[i]   = new Vector3(x, 0.6f, y);
                oldRedSpherePosition[i] = mRedSpherePosition[i];
                mRedSphereVelocity[i]   = new Vector3(0, 0, 0);
            }
            for (int i = 0; i < 100; ++i)
            {
                float x = random.Next(0, 180);
                x = (x - 90) / 1000;
                float y = random.Next(0, 180);
                y = (y - 90) / 1000;
                mGreenSpherePosition[i]   = new Vector3(x, 0.6f, y);
                oldGreenSpherePosition[i] = mGreenSpherePosition[i];
                mGreenSphereVelocity[i]   = new Vector3(0, 0, 0);
            }
            mTimer = new Timer();
            mTimer.Start();

            string filepath = @"ACW/texture.jpg";

            if (System.IO.File.Exists(filepath))
            {
                Bitmap     TextureBitmap = new Bitmap(filepath);
                BitmapData TextureData   = TextureBitmap.LockBits(
                    new System.Drawing.Rectangle(0, 0, TextureBitmap.Width,
                                                 TextureBitmap.Height), ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.GenTextures(1, out mTexture_ID);
                GL.BindTexture(TextureTarget.Texture2D, mTexture_ID);
                GL.TexImage2D(TextureTarget.Texture2D,
                              0, PixelInternalFormat.Rgba, TextureData.Width, TextureData.Height,
                              0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                              PixelType.UnsignedByte, TextureData.Scan0);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                                (int)TextureMagFilter.Linear);
                TextureBitmap.UnlockBits(TextureData);
            }
            else
            {
                throw new Exception("Could not find file " + filepath);
            }

            //Vertex arrays and buffers
            GL.GenVertexArrays(mVAO_IDs.Length, mVAO_IDs);
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            //middlecube
            GL.BindVertexArray(mVAO_IDs[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(middleCube.Vertices.Length * sizeof(float)), middleCube.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(middleCube.Indices.Length * sizeof(float)), middleCube.Indices, BufferUsageHint.StaticDraw);
            int size;

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (middleCube.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (middleCube.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }
            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            GL.BindVertexArray(0);

            //endcube
            GL.BindVertexArray(mVAO_IDs[1]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[2]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(endCube.Vertices.Length * sizeof(float)), endCube.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[3]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(endCube.Indices.Length * sizeof(float)), endCube.Indices, BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (endCube.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (endCube.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }
            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            GL.BindVertexArray(0);

            //sphere
            GL.BindVertexArray(mVAO_IDs[2]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[4]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sphere.Vertices.Length * sizeof(float)), sphere.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[5]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(sphere.Indices.Length * sizeof(float)), sphere.Indices, BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (sphere.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (sphere.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }
            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            GL.BindVertexArray(0);

            //cylinder
            GL.BindVertexArray(mVAO_IDs[3]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[6]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(cylinder.Vertices.Length * sizeof(float)), cylinder.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[7]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(cylinder.Indices.Length * sizeof(float)), cylinder.Indices, BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (cylinder.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (cylinder.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }
            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            GL.BindVertexArray(0);

            //topcube
            GL.BindVertexArray(mVAO_IDs[4]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[8]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(topCube.Vertices.Length * sizeof(float)), topCube.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[9]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(topCube.Indices.Length * sizeof(float)), topCube.Indices, BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (topCube.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (topCube.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }
            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            GL.BindVertexArray(0);

            //Eye Position
            int     uEyePositionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uEyePosition");
            Vector4 eyePosition          = Vector4.Transform(new Vector4(0, 0, 0, 0), mView);

            GL.Uniform4(uEyePositionLocation, ref eyePosition);

            int     uLightPositionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight.Position");
            Vector4 lightPosition          = new Vector4(4, -4, 2f, 1);

            lightPosition = Vector4.Transform(lightPosition, mView);
            GL.Uniform4(uLightPositionLocation, lightPosition);

            int     uAmbientLightLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight.AmbientLight");
            Vector3 colour = new Vector3(1.0f, 1.0f, 0.90f);

            GL.Uniform3(uAmbientLightLocation, colour);

            int uDiffuseLightLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight.DiffuseLight");

            colour = new Vector3(1.0f, 1.0f, 0.90f);
            GL.Uniform3(uDiffuseLightLocation, colour);

            int uSpecularLightLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight.SpecularLight");

            colour = new Vector3(1.0f, 1.0f, 0.90f);
            GL.Uniform3(uSpecularLightLocation, colour);

            int uAmbientReflectivityLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.AmbientReflectivity");

            colour = new Vector3(0.2f, 0.2f, 0.2f);
            GL.Uniform3(uAmbientReflectivityLocation, colour);

            int uDiffuseReflectivityLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.DiffuseReflectivity");

            GL.Uniform3(uDiffuseReflectivityLocation, colour);

            int uSpecularReflectivityLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.SpecularReflectivity");

            GL.Uniform3(uSpecularReflectivityLocation, colour);

            int   uShininessLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.Shininess");
            float Shininess          = 30;

            GL.Uniform1(uShininessLocation, Shininess);


            base.OnLoad(e);
        }
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.SkyBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            mShader = new ShaderUtility(@"Lab3/Shaders/vLighting.vert", @"Lab3/Shaders/fPassThrough.frag");
            GL.UseProgram(mShader.ShaderProgramID);
            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");

            GL.GenVertexArrays(mVAO_IDs.Length, mVAO_IDs);
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            float[] vertices = new float[] { -10, 0, -10, 0, 1, 0,
                                             -10, 0, 10, 0, 1, 0,
                                             10, 0, 10, 0, 1, 0,
                                             10, 0, -10, 0, 1, 0, };

            GL.BindVertexArray(mVAO_IDs[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);

            int size;

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            mSphereModelUtility = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");

            GL.BindVertexArray(mVAO_IDs[1]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSphereModelUtility.Vertices.Length * sizeof(float)), mSphereModelUtility.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[2]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSphereModelUtility.Indices.Length * sizeof(float)), mSphereModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.BindVertexArray(0);

            mView = Matrix4.CreateTranslation(0, -1.5f, 0);
            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");

            GL.UniformMatrix4(uView, true, ref mView);

            mGroundModel = Matrix4.CreateTranslation(0, 0, -5f);
            mSphereModel = Matrix4.CreateTranslation(0, 1, -5f);

            base.OnLoad(e);
        }
Пример #5
0
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.LightSkyBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            mShader = new ShaderUtility(@"ACW/Shaders/vPassThrough.vert", @"ACW/Shaders/fLighting.frag");//Sets the shaders for the program

            GL.UseProgram(mShader.ShaderProgramID);

            int vPositionLocation  = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation    = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int vTexCoordsLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vTexCoords");

            //(54-56)Saves the location of shader locations as variables
            GL.GenVertexArrays(mVAO_IDs.Length, mVAO_IDs);
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            float[] vertices = new float[] { -10, 0, -10, 0, 1, 0, 0.0f, 0.0f,
                                             -10, 0, 10, 0, 1, 0, 0.0f, 1.0f,
                                             10, 0, 10, 0, 1, 0, 1.0f, 1.0f,
                                             10, 0, -10, 0, 1, 0, 1.0f, 0.0f };
            //(61-64)Sets up the ground vertices and texture coordinates
            GL.BindVertexArray(mVAO_IDs[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);

            int size;

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }
            //(71-75)Binds the ground vertex array and saves it on the graphics card
            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 12);

            GL.EnableVertexAttribArray(vTexCoordsLocation);
            GL.VertexAttribPointer(vTexCoordsLocation, 2, VertexAttribPointerType.Float, false, 8 * sizeof(float), 24);
            //(77-84)Gets the location of the position coordinates, normal coordinates and texture coordinates
            string filepath = @"ACW/texture.jpg";

            if (System.IO.File.Exists(filepath))
            {
                Bitmap     TextureBitmap = new Bitmap(filepath);
                BitmapData TextureData   = TextureBitmap.LockBits(
                    new System.Drawing.Rectangle(0, 0, TextureBitmap.Width,
                                                 TextureBitmap.Height), ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                GL.ActiveTexture(TextureUnit.Texture0);
                GL.GenTextures(1, out mTexture_IDs[0]);
                GL.BindTexture(TextureTarget.Texture2D, mTexture_IDs[0]);
                GL.TexImage2D(TextureTarget.Texture2D,
                              0, PixelInternalFormat.Rgba, TextureData.Width, TextureData.Height,
                              0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                              PixelType.UnsignedByte, TextureData.Scan0);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                                (int)TextureMagFilter.Linear);
                TextureBitmap.UnlockBits(TextureData);

                int uTextureSamplerLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uTextureSampler[0]");
                GL.Uniform1(uTextureSamplerLocation, 0);
            }
            else
            {
                throw new Exception("Could not find file " + filepath);
            }
            //(86-114)Loads the ground texture onto the graphics card and saves its location to the texture sampler array
            mArmadilloManModelUtility = ModelUtility.LoadModel(@"Utility/Models/model.bin");
            BufferSetup(vPositionLocation, vNormalLocation, vTexCoordsLocation, mVAO_IDs[1], mVBO_IDs[1], mVBO_IDs[2], 6, mArmadilloManModelUtility);

            filepath = @"ACW/space.jpg";
            if (System.IO.File.Exists(filepath))
            {
                Bitmap     TextureBitmap = new Bitmap(filepath);
                BitmapData TextureData   = TextureBitmap.LockBits(
                    new System.Drawing.Rectangle(0, 0, TextureBitmap.Width,
                                                 TextureBitmap.Height), ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                GL.ActiveTexture(TextureUnit.Texture1);
                GL.GenTextures(1, out mTexture_IDs[1]);
                GL.BindTexture(TextureTarget.Texture2D, mTexture_IDs[1]);
                GL.TexImage2D(TextureTarget.Texture2D,
                              0, PixelInternalFormat.Rgba, TextureData.Width, TextureData.Height,
                              0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                              PixelType.UnsignedByte, TextureData.Scan0);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                                (int)TextureMagFilter.Linear);
                TextureBitmap.UnlockBits(TextureData);

                int uTextureSamplerLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uTextureSampler[1]");
                GL.Uniform1(uTextureSamplerLocation, 1);
            }
            else
            {
                throw new Exception("Could not find file " + filepath);
            }
            //(119-147)Loads the armadillo man model texture onto the graphics card and saves its location to the texture sampler array
            mCylinderModelUtility = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");
            BufferSetup(vPositionLocation, vNormalLocation, vTexCoordsLocation, mVAO_IDs[2], mVBO_IDs[3], mVBO_IDs[4], 6, mCylinderModelUtility);

            filepath = @"ACW/metaltexture.jpg";
            if (System.IO.File.Exists(filepath))
            {
                Bitmap     TextureBitmap = new Bitmap(filepath);
                BitmapData TextureData   = TextureBitmap.LockBits(
                    new System.Drawing.Rectangle(0, 0, TextureBitmap.Width,
                                                 TextureBitmap.Height), ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                GL.ActiveTexture(TextureUnit.Texture2);
                GL.GenTextures(1, out mTexture_IDs[2]);
                GL.BindTexture(TextureTarget.Texture2D, mTexture_IDs[2]);
                GL.TexImage2D(TextureTarget.Texture2D,
                              0, PixelInternalFormat.Rgba, TextureData.Width, TextureData.Height,
                              0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                              PixelType.UnsignedByte, TextureData.Scan0);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                                (int)TextureMagFilter.Linear);
                TextureBitmap.UnlockBits(TextureData);

                int uTextureSamplerLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uTextureSampler[2]");
                GL.Uniform1(uTextureSamplerLocation, 2);
            }
            else
            {
                throw new Exception("Could not find file " + filepath);
            }
            //(152-180)Loads the cylinder texture onto the graphics card and saves its location to the texture sampler array
            mBallModelUtility = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
            BufferSetup(vPositionLocation, vNormalLocation, vTexCoordsLocation, mVAO_IDs[3], mVBO_IDs[5], mVBO_IDs[6], 2, mBallModelUtility);

            filepath = @"ACW/texture2.jpg";
            if (System.IO.File.Exists(filepath))
            {
                Bitmap     TextureBitmap = new Bitmap(filepath);
                BitmapData TextureData   = TextureBitmap.LockBits(
                    new System.Drawing.Rectangle(0, 0, TextureBitmap.Width,
                                                 TextureBitmap.Height), ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                GL.ActiveTexture(TextureUnit.Texture3);
                GL.GenTextures(1, out mTexture_IDs[3]);
                GL.BindTexture(TextureTarget.Texture2D, mTexture_IDs[3]);
                GL.TexImage2D(TextureTarget.Texture2D,
                              0, PixelInternalFormat.Rgba, TextureData.Width, TextureData.Height,
                              0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                              PixelType.UnsignedByte, TextureData.Scan0);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                                (int)TextureMagFilter.Linear);
                TextureBitmap.UnlockBits(TextureData);

                int uTextureSamplerLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uTextureSampler[3]");
                GL.Uniform1(uTextureSamplerLocation, 3);
            }
            else
            {
                throw new Exception("Could not find file " + filepath);
            }
            //(182-213)Loads the ball texture onto the graphics card and saves its location to the texture sampler array
            GL.BindVertexArray(0);

            mView = Matrix4.CreateTranslation(0, -3.0f, 0);
            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");

            GL.UniformMatrix4(uView, true, ref mView);
            //(217-219)Sets the camera location
            mGroundModel       = Matrix4.CreateTranslation(0, 0, -5f);
            mArmadilloManModel = Matrix4.CreateRotationY(-1.7f) * Matrix4.CreateTranslation(-0.1f, 2.8f, -5f);
            mCylinderModel     = Matrix4.CreateTranslation(3, 1, 0f);
            mBallModel         = Matrix4.CreateTranslation(0, 1, -5f);
            //(221-224)Sets the location of the models and the ground
            LightPosition();
            MaterialSetter();

            int     uEyePositionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uEyePosition");
            Vector4 lightPosition        = Vector4.Transform(new Vector4(2, 1, -8.5f, 1), mView);

            GL.Uniform4(uEyePositionLocation, lightPosition);
            //(229-231)Updates the eye position for specular lighting calculations
            base.OnLoad(e);
        }
Пример #6
0
        protected override void OnLoad(EventArgs e)
        {
            // On  load methods to  reading shaders ,models , textures ...
            GL.ClearColor(Color4.Black);
            GL.Enable(EnableCap.DepthTest);
            Camera.Type = CameraType.FreeCam;

            mShader = new ShaderUtility(@"ACW/Shaders/vSdr.vert", @"ACW/Shaders/fLight.frag");

            mSphereModel   = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
            mCubeModel     = ModelUtility.LoadModel(@"Utility/Models/MainCube.sjg");
            mCylinderModel = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");


            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation   = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int vTexCoords        = GL.GetAttribLocation(mShader.ShaderProgramID, "vTexCoords");

            int size;

            GL.UseProgram(mShader.ShaderProgramID);

            GL.GenVertexArrays(mVAO.Length, mVAO);
            GL.GenBuffers(mVBO.Length, mVBO);

            //Textures
            Txt1 = new Texture(@"ACW/Shaders/tx2.jpg", TextureUnit.Texture0);
            Txt2 = new Texture(@"ACW/Shaders/tx.jpg", TextureUnit.Texture1);

            #region Spheres
            GL.BindVertexArray(mVAO[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSphereModel.Vertices.Length * sizeof(float)), mSphereModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSphereModel.Indices.Length * sizeof(float)), mSphereModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion // Binds Spheres

            #region Cubes
            GL.BindVertexArray(mVAO[1]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[2]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCubeModel.Vertices.Length * sizeof(float)), mCubeModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[3]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCubeModel.Indices.Length * sizeof(float)), mCubeModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 8 * sizeof(float), 3 * sizeof(float));

            GL.EnableVertexAttribArray(vTexCoords);
            GL.VertexAttribPointer(vTexCoords, 2, VertexAttribPointerType.Float, true, 8 * sizeof(float), 6 * sizeof(float));
            #endregion  // Bind Cubes

            #region Cylinders
            GL.BindVertexArray(mVAO[2]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[4]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCylinderModel.Vertices.Length * sizeof(float)), mCylinderModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[5]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCylinderModel.Indices.Length * sizeof(float)), mCylinderModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion


            //Checking acctivity o gravity is on
            if (gravityAcceleration.Y == 0)
            {
                gravityOn = false;
            }
            else
            {
                gravityOn = true;
            }

            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");
            GL.UniformMatrix4(uView, true, ref mView);

            //Manages the projection for resizing the window
            int     uProjectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uProjection");
            Matrix4 projection          = Matrix4.CreatePerspectiveFieldOfView(1, (float)ClientRectangle.Width / ClientRectangle.Height, 0.5f, viewDistance);
            GL.UniformMatrix4(uProjectionLocation, true, ref projection);


            Light.Inside();
            Level.Inside();
            EmitterBox.Inside();
            SpotLight.Inside();



            GL.BindVertexArray(0);

            base.OnLoad(e);
        }
Пример #7
0
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.LightGoldenrodYellow);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            mShader = new ShaderUtility(@"Lab3/Shaders/vPassThrough.vert", @"Lab3/Shaders/fLighting.frag");
            GL.UseProgram(mShader.ShaderProgramID);
            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation   = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");

            GL.GenVertexArrays(mVAO_IDs.Length, mVAO_IDs);
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            float[] vertices = new float[] { -10, 0, -10, 0, 1, 0,
                                             -10, 0, 10, 0, 1, 0,
                                             10, 0, 10, 0, 1, 0,
                                             10, 0, -10, 0, 1, 0, };

            #region bind ground

            GL.BindVertexArray(mVAO_IDs[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);

            int size;
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            #endregion

            #region bind Sphere

            mSphereModelUtility = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");

            GL.BindVertexArray(mVAO_IDs[1]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSphereModelUtility.Vertices.Length * sizeof(float)), mSphereModelUtility.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[2]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSphereModelUtility.Indices.Length * sizeof(float)), mSphereModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            #endregion

            #region bind other model (dragon)

            mOtherModelUtility = ModelUtility.LoadModel(@"Utility/Models/model.bin");

            GL.BindVertexArray(mVAO_IDs[2]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[3]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mOtherModelUtility.Vertices.Length * sizeof(float)), mOtherModelUtility.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[4]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mOtherModelUtility.Indices.Length * sizeof(float)), mOtherModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mOtherModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mOtherModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            #endregion

            #region bind cylinder

            mCylinderModelUtility = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");

            GL.BindVertexArray(mVAO_IDs[3]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[5]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCylinderModelUtility.Vertices.Length * sizeof(float)), mCylinderModelUtility.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[6]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCylinderModelUtility.Indices.Length * sizeof(float)), mCylinderModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }


            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            #endregion
            GL.BindVertexArray(0);

            mView = Matrix4.CreateTranslation(0, -1.5f, 0);
            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");
            GL.UniformMatrix4(uView, true, ref mView);
            mEyePosition = new Vector4(0, 1.5f, 0, 1);
            int uEyePosition = GL.GetUniformLocation(mShader.ShaderProgramID, "uEyePosition");
            GL.Uniform4(uEyePosition, mEyePosition);



            mGroundModel   = Matrix4.CreateTranslation(0, 0, -5f);
            mSphereModel   = Matrix4.CreateTranslation(0, 1, -5f);
            mOtherModel    = Matrix4.CreateTranslation(0, 0.75f, -5f);
            mCylinderModel = Matrix4.CreateTranslation(0, 0.5f, -5f);

            #region Lighting

            int     uLightDirectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLightPosition");
            Vector4 uLightPosition          = Vector4.Transform(new Vector4(2, 2, -9.5f, 1), mView);
            GL.Uniform4(uLightDirectionLocation, uLightPosition);


            #endregion

            base.OnLoad(e);
        }
Пример #8
0
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.DodgerBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            mModel  = ModelUtility.LoadModel(@"Utility/Models/lab22model.sjg");
            mShader = new ShaderUtility(@"Lab2/Shaders/vLab22.vert", @"Lab2/Shaders/fSimple.frag");
            GL.UseProgram(mShader.ShaderProgramID);
            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vColourLocation   = GL.GetAttribLocation(mShader.ShaderProgramID, "vColour");

            //mView = Matrix4.Identity;
            mView = Matrix4.CreateTranslation(0, 0, -2);
            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");

            GL.UniformMatrix4(uView, true, ref mView);

            if (mShader != null)
            {
                int uProjectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uProjection");
                //int windowHeight = this.ClientRectangle.Height;
                //int windowWidth = this.ClientRectangle.Width;

                Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(1, (float)ClientRectangle.Width / ClientRectangle.Height, 0.5f, 5);
            }

            /*
             * if (windowHeight > windowWidth)
             * {
             *  if (windowWidth < 1)
             *  {
             *      windowWidth = 1;
             *  }
             *  float ratio = (float) windowHeight / windowWidth;
             *  Console.Write(ratio);
             *  Matrix4 projection = Matrix4.CreateOrthographic(ratio * 10, 10, -1, 1);
             *
             *  GL.UniformMatrix4(uProjectionLocation, true, ref projection);
             * }
             * else
             * {
             *  if (windowHeight < 1)
             *  {
             *      windowHeight = 1;
             *  }
             *  float ratio = (float) windowWidth / windowHeight;
             *  Console.Write(ratio + ":" + windowHeight + ":" + windowWidth);
             *  Matrix4 projection = Matrix4.CreateOrthographic(10, ratio * 10, -1, 1);
             *  GL.UniformMatrix4(uProjectionLocation, true, ref projection);
             * }
             * }*/

            mVAO_ID = GL.GenVertexArray();
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            GL.BindVertexArray(mVAO_ID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mModel.Vertices.Length * sizeof(float)), mModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mModel.Indices.Length * sizeof(float)), mModel.Indices, BufferUsageHint.StaticDraw);

            int size;

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
            GL.EnableVertexAttribArray(vColourLocation);
            GL.VertexAttribPointer(vColourLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 3 * sizeof(float));

            GL.BindVertexArray(0);

            base.OnLoad(e);
        }
Пример #9
0
        }  //Update

        protected override void OnLoad(EventArgs e)
        {
            //Init
            GL.ClearColor(Color4.Black);
            GL.Enable(EnableCap.DepthTest);

            Camera.Type = CameraType.Static;

            mShader = new ShaderUtility(@"ACW/Shaders/s.vert", @"ACW/Shaders/Light.frag");

            mSphereModel   = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
            mCubeModel     = ModelUtility.LoadModel(@"Utility/Models/MainCube.sjg");
            mCylinderModel = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");
            mParticleCube  = ModelUtility.LoadModel(@"Utility/Models/Particle_Cube.sjg");

            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation   = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int vTexCoords        = GL.GetAttribLocation(mShader.ShaderProgramID, "vTexCoords");

            int size;

            GL.UseProgram(mShader.ShaderProgramID);

            GL.GenVertexArrays(mVAO.Length, mVAO);
            GL.GenBuffers(mVBO.Length, mVBO);

            //Textures
            BrickWall = new Texture(@"ACW/Textures/BrickWall.jpg", TextureUnit.Texture0);

            //Frame buffers
            Bottom_Portal = new Frame_Buffer(TextureUnit.Texture2, FramebufferAttachment.ColorAttachment0);
            Top_Portal    = new Frame_Buffer(TextureUnit.Texture3, FramebufferAttachment.ColorAttachment0);

            #region Sphere
            GL.BindVertexArray(mVAO[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSphereModel.Vertices.Length * sizeof(float)), mSphereModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSphereModel.Indices.Length * sizeof(float)), mSphereModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion

            #region Cube
            GL.BindVertexArray(mVAO[1]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[2]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCubeModel.Vertices.Length * sizeof(float)), mCubeModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[3]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCubeModel.Indices.Length * sizeof(float)), mCubeModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 8 * sizeof(float), 3 * sizeof(float));

            GL.EnableVertexAttribArray(vTexCoords);
            GL.VertexAttribPointer(vTexCoords, 2, VertexAttribPointerType.Float, true, 8 * sizeof(float), 6 * sizeof(float));
            #endregion

            #region Cylinder
            GL.BindVertexArray(mVAO[2]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[4]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCylinderModel.Vertices.Length * sizeof(float)), mCylinderModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[5]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCylinderModel.Indices.Length * sizeof(float)), mCylinderModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion

            #region General Init
            //Checks if gravity is on
            if (gravityAcceleration.Y == 0)
            {
                gravityOn = false;
            }
            else
            {
                gravityOn = true;
            }

            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");
            GL.UniformMatrix4(uView, true, ref mView);

            //Manages the projection for resizing the window
            int     uProjectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uProjection");
            Matrix4 projection          = Matrix4.CreatePerspectiveFieldOfView(1, (float)ClientRectangle.Width / ClientRectangle.Height, 0.5f, viewDistance);
            GL.UniformMatrix4(uProjectionLocation, true, ref projection);
            #endregion

            //---------------INIT-----------------//
            Light.Init();
            Level.Init();
            Emitter.Init();
            SpotLight.Init();

            float spawnRate = 0.01f;
            float lifetime  = 2f;
            ActiveParticleSystems.Add(new Floating_CubeSystem(mParticleCube, new Vector3(-100, -100, 100), 200, 200, 200, lifetime, spawnRate, 100, Material.white)); //1
            ActiveParticleSystems.Add(new Floating_CubeSystem(mParticleCube, new Vector3(-5, -15, 5), 10, 10, lifetime, 0.2f, 100, Material.crimson_Red));            //1
            //------------------------------------//

            GL.BindVertexArray(0);

            base.OnLoad(e);
        }
Пример #10
0
        protected override void OnLoad(EventArgs e)
        {
            // Set some GL state
            GL.ClearColor(Color4.White);
            GL.Enable(EnableCap.CullFace);

            //Shader Initialisation/Lighting
            mShader = new ShaderUtility(@"Lab3/Shaders/vLighting.vert", @"Lab3/Shaders/fLighting.frag");
            GL.UseProgram(mShader.ShaderProgramID);

            mView = Matrix4.CreateTranslation(0, -5, 2);

            Vector3[] colour = { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) };

            for (int i = 0; i < 3; i++)
            {
                uLightPositionLocation[i] = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[" + i + "].Position");
                //Vector3 colour = new Vector3(0.1f, 0.0f, 0.0f);
                lightPosition[i] = lightOrigins[i];// new Vector4(2+ i, 4 - i, -8.5f, 1);
                lightPosition[i] = Vector4.Transform(lightPosition[i], mView);
                GL.Uniform4(uLightPositionLocation[i], lightPosition[i]);

                uAmbientLightLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[" + i + "].AmbientLight");
                GL.Uniform3(uAmbientLightLocation, colour[i] / 10);
                uDiffuseLightLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[" + i + "].DiffuseLight");
                GL.Uniform3(uDiffuseLightLocation, colour[i]);
                uSpecularLightLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[" + i + "].SpecularLight");
                GL.Uniform3(uSpecularLightLocation, colour[i]);
            }
            uAmbientLightReflect = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.AmbientReflectivity");
            Vector3 reflection = new Vector3(0.3f, 0.3f, 0.3f);

            GL.Uniform3(uAmbientLightReflect, reflection);
            uDiffuseLightReflect = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.DiffuseReflectivity");
            GL.Uniform3(uDiffuseLightReflect, reflection);
            uSpecularLightReflect = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.SpecularReflectivity");
            GL.Uniform3(uSpecularLightReflect, reflection);
            uShine = GL.GetUniformLocation(mShader.ShaderProgramID, "uMaterial.Shininess");
            GL.Uniform1(uShine, 0.2f);

            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormal           = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");

            uEyePos = GL.GetUniformLocation(mShader.ShaderProgramID, "uEyePosition");
            Console.WriteLine(mView);
            GL.Uniform4(uEyePos, mView.Row3);

            GL.GenVertexArrays(mVAO_IDs.Length, mVAO_IDs);
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);
            //Ground verticies?
            float[] vertices = new float[] { -10, 0, -10, 0, 1, 0,
                                             -10, 0, 10, 0, 1, 0,
                                             10, 0, 10, 0, 1, 0,
                                             10, 0, -10, 0, 1, 0, };
            //Ground...
            GL.BindVertexArray(mVAO_IDs[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);

            int size;

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            /*
             * mSphereModelUtility = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
             *
             * GL.BindVertexArray(mVAO_IDs[1]);
             * GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[1]);
             * GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSphereModelUtility.Vertices.Length * sizeof(float)), mSphereModelUtility.Vertices, BufferUsageHint.StaticDraw);
             * GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[2]);
             * GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSphereModelUtility.Indices.Length * sizeof(float)), mSphereModelUtility.Indices, BufferUsageHint.StaticDraw);
             *
             * GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
             * if (mSphereModelUtility.Vertices.Length * sizeof(float) != size)
             * {
             *  throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
             * }
             *
             * GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
             * if (mSphereModelUtility.Indices.Length * sizeof(float) != size)
             * {
             *  throw new ApplicationException("Index data not loaded onto graphics card correctly");
             * }
             *
             * GL.EnableVertexAttribArray(vPositionLocation);
             * GL.EnableVertexAttribArray(vNormal);
             * GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
             * GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
             */
            //PEDESTAL
            mPedestalModelUtility = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");

            GL.BindVertexArray(mVAO_IDs[1]);
            //Model Verticies
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mPedestalModelUtility.Vertices.Length * sizeof(float)), mPedestalModelUtility.Vertices, BufferUsageHint.StaticDraw);
            //Model Indicies
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[2]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mPedestalModelUtility.Indices.Length * sizeof(float)), mPedestalModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mPedestalModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mPedestalModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);      //Read in 3 from 0 of 6
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float)); //Read in 3 from 3 of 6
            //MODEL
            mSupriseModelUtility = ModelUtility.LoadModel(@"Utility/Models/model.bin");

            GL.BindVertexArray(mVAO_IDs[2]);
            //Model Verticies
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[3]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSupriseModelUtility.Vertices.Length * sizeof(float)), mSupriseModelUtility.Vertices, BufferUsageHint.StaticDraw);
            //Model Indicies
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[4]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSupriseModelUtility.Indices.Length * sizeof(float)), mSupriseModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSupriseModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSupriseModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.EnableVertexAttribArray(vNormal);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);      //Read in 3 from 0 of 6
            GL.VertexAttribPointer(vNormal, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float)); //Read in 3 from 3 of 6


            GL.BindVertexArray(0);
            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");

            GL.UniformMatrix4(uView, true, ref mView);

            mGroundModel = Matrix4.CreateTranslation(0, 0, -5f);
            //mSphereModel = Matrix4.CreateTranslation(0, 1, -5f);
            mPedestal     = Matrix4.CreateTranslation(0, 1, -5f); //X.Y.Z
            mSupriseModel = Matrix4.CreateTranslation(0, 2, -5f);

            base.OnLoad(e);
        }
        protected override void OnLoad(EventArgs e)
        {
            int size;

            // Set some GL state
            GL.ClearColor(Color4.White);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            mShader = new ShaderUtility(@"Lab3/Shaders/vPassThrough.vert", @"Lab3/Shaders/fLighting.frag");
            GL.UseProgram(mShader.ShaderProgramID);

            int vPositionLocation       = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation         = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int uView                   = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");
            int uEyePositionLocation    = GL.GetUniformLocation(mShader.ShaderProgramID, "uEyePosition");
            int uLightPositionLocation0 = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[0].Position");
            int uAmbientLightLocation0  = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[0].AmbientLight");
            int uDiffuseLightLocation0  = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[0].DiffuseLight");
            int uSpecularLightLocation0 = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[0].SpecularLight");
            int uLightPositionLocation1 = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[1].Position");
            int uAmbientLightLocation1  = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[1].AmbientLight");
            int uDiffuseLightLocation1  = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[1].DiffuseLight");
            int uSpecularLightLocation1 = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[1].SpecularLight");
            int uLightPositionLocation2 = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[2].Position");
            int uAmbientLightLocation2  = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[2].AmbientLight");
            int uDiffuseLightLocation2  = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[2].DiffuseLight");
            int uSpecularLightLocation2 = GL.GetUniformLocation(mShader.ShaderProgramID, "uLight[2].SpecularLight");

            GL.GenVertexArrays(mVAO_IDs.Length, mVAO_IDs);
            GL.GenBuffers(mVBO_IDs.Length, mVBO_IDs);

            float[] vertices = new float[] { -10, 0, -10, 0, 1, 0,
                                             -10, 0, 10, 0, 1, 0,
                                             10, 0, 10, 0, 1, 0,
                                             10, 0, -10, 0, 1, 0 };

            GL.BindVertexArray(mVAO_IDs[0]);

            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);

            if (vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.BindVertexArray(0);

            mModelModelUtility = ModelUtility.LoadModel(@"Utility/Models/model1.bin");

            GL.BindVertexArray(mVAO_IDs[1]);

            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mModelModelUtility.Vertices.Length * sizeof(float)), mModelModelUtility.Vertices, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[2]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mModelModelUtility.Indices.Length * sizeof(float)), mModelModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);

            if (mModelModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);

            if (mModelModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.BindVertexArray(0);

            mCylinderModelUtility = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");

            GL.BindVertexArray(mVAO_IDs[2]);

            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO_IDs[3]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCylinderModelUtility.Vertices.Length * sizeof(float)), mCylinderModelUtility.Vertices, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO_IDs[4]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCylinderModelUtility.Indices.Length * sizeof(float)), mCylinderModelUtility.Indices, BufferUsageHint.StaticDraw);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);

            if (mCylinderModelUtility.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);

            if (mCylinderModelUtility.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.BindVertexArray(0);

            mView = Matrix4.CreateTranslation(0, -1.5f, 0);
            GL.UniformMatrix4(uView, true, ref mView);

            mGroundModel   = Matrix4.CreateTranslation(0, 0, -5f);
            mModelModel    = Matrix4.CreateTranslation(0, 1, -5f);
            mCylinderModel = Matrix4.CreateTranslation(0, 0, -5f);

            Vector4 eyePosition = Vector4.Transform(new Vector4(0, 0, 0, 1), mView);

            GL.Uniform4(uEyePositionLocation, eyePosition);

            Vector4 lightPosition0 = Vector4.Transform(new Vector4(2, 4, -8.5f, 1), mView);

            GL.Uniform4(uLightPositionLocation0, lightPosition0);

            Vector4 lightPosition1 = Vector4.Transform(new Vector4(0, 6, -8.5f, 1), mView);

            GL.Uniform4(uLightPositionLocation1, lightPosition1);

            Vector4 lightPosition2 = Vector4.Transform(new Vector4(-2, 4, -8.5f, 1), mView);

            GL.Uniform4(uLightPositionLocation2, lightPosition2);

            Vector3 colour0 = new Vector3(1.0f, 0.0f, 0.0f);

            GL.Uniform3(uAmbientLightLocation0, colour0);
            GL.Uniform3(uDiffuseLightLocation0, colour0);
            GL.Uniform3(uSpecularLightLocation0, colour0);

            Vector3 colour1 = new Vector3(0.0f, 1.0f, 0.0f);

            GL.Uniform3(uAmbientLightLocation1, colour1);
            GL.Uniform3(uDiffuseLightLocation1, colour1);
            GL.Uniform3(uSpecularLightLocation1, colour1);

            Vector3 colour2 = new Vector3(0.0f, 0.0f, 1.0f);

            GL.Uniform3(uAmbientLightLocation2, colour2);
            GL.Uniform3(uDiffuseLightLocation2, colour2);
            GL.Uniform3(uSpecularLightLocation2, colour2);

            base.OnLoad(e);
        }