} //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); }