protected override void Dispose(bool disposing) { if (!IsDisposed && _id != 0) { // skipping if disposing as no managed resources to dispose DisposalManager.Add(() => GL.DeleteShader(_id)); _id = 0; IsDisposed = true; } }
protected override void Dispose(bool disposing) { if (!IsDisposed) { // no managed object to dispose so skipping if disposing DisposalManager.Add(() => GL.DeleteFramebuffers(1, ref _id)); _id = 0; } IsDisposed = true; }
protected override void Dispose(bool disposing) { if (!IsDisposed) { // no managed object to dispose so skipping if disposing DisposalManager.Add(() => GL.DeleteSamplers(1, new[] { _id })); _id = 0; } IsDisposed = true; }
protected override void Dispose(bool disposing) { if (!IsDisposed) { // skipping disposing as no managed resources to free DisposalManager.Add(() => GL.DeleteProgram(_id)); _id = 0; } IsDisposed = true; }
protected override void OnRenderFrame(FrameEventArgs e) { GL.Viewport(0, 0, Width, Height); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); SlicedSprite buttonSprite = new SlicedSprite(texture, 0, 0, 0, 0, 12, 11, 12, 11); //ushort[] indices; //VertexPositionColorTexture[] vertices = buttonSprite.GetVertices(200, 200, 300, 300, 0, Color4.White, out indices); //VertexBuffer vb = VertexBuffer.Create(vertices[0].VertexFormat, vertices); //IndexBuffer ib = IndexBuffer.Create(indices); //VertexArray vao = new VertexArray(vb, ib); //shader.Bind(); //Sampler sampler = Sampler.Create(texture); //shader.BindUniforms(new Dictionary<string, IUniformValue>() { {"Texture", UniformValue.Create(sampler) } //}); ////_graphicsDevice.RenderState.BlendState = BlendState.AlphaBlend; //_graphicsDevice.DrawVertexArray(vao, shader); //wireframeShader.Bind(); //wireframeShader.BindUniforms(new Dictionary<string, IUniformValue>() //{ // {"MatrixTransform", UniformValue.Create(projectionMatrix)}, // {"WIN_SCALE", UniformValue.Create((float)_graphicsDevice.ViewPort.Width, (float)_graphicsDevice.ViewPort.Height)}, // {"Diffuse", UniformValue.Create(new Color4(1.0f, 0f, 0f, 1f))} //}); //GL.Disable(EnableCap.DepthTest); //_graphicsDevice.DrawVertexArray(vao, wireframeShader); //GL.Enable(EnableCap.DepthTest); spriteBatch.Begin(SpriteSortMode.Texture, BlendState.NonPremultiplied); spriteBatch.Draw(buttonSprite, 100, 100, 100, 100, Color4.White); spriteBatch.Draw(buttonSprite, 100, 200, 200, 100, Color4.White); spriteBatch.Draw(buttonSprite, 300, 300, 100, 100, Color4.White); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Texture, new RenderState() { BlendState = BlendState.AlphaBlend }, null, _font.Shader); spriteBatch.DrawString(_font, "Test Text!!", 0, 0); spriteBatch.End(); SwapBuffers(); DisposalManager.Process(); }
protected override void Dispose(bool disposing) { if (!IsDisposed) { if (disposing) { _vertexBuffer.Dispose(); _vertexBuffer = null; _indexBuffer.Dispose(); _indexBuffer = null; _bindings = null; } DisposalManager.Add(() => GL.DeleteVertexArrays(1, ref _id)); _id = 0; } IsDisposed = true; }
protected override void OnRenderFrame(FrameEventArgs e) { GL.Viewport(0, 0, Width, Height); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); int count = 0; foreach (ModelMesh mesh in dwarf.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.VertexArray.AddBinding(shader.VertexAttribute("vert").Slot, VertexUsage.Position); part.VertexArray.AddBinding(shader.VertexAttribute("vertTexCoord").Slot, VertexUsage.TextureCoordinate); shader.Bind(); shader.Uniform1("tex", 0); GL.ActiveTexture(TextureUnit.Texture0); if (count == 0) { texture2.Bind(); } else { texture1.Bind(); } part.VertexArray.Bind(); GL.DrawElements(part.VertexBuffer.BeginMode, part.IndexBuffer.Length, part.IndexBuffer.ElementsType, 0); count++; //Utilities.CheckGLError(); //part.VertexArray.Unbind(); //Utilities.CheckGLError(); shader.Unbind(); Utilities.CheckGLError(); } } RenderSkeleton(dwarf.Skeleton); SwapBuffers(); DisposalManager.Process(); }
protected override void OnUnload(EventArgs e) { DisposalManager.Process(); }
protected override void OnRenderFrame(FrameEventArgs e) { GL.Viewport(0, 0, Width, Height); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); int count = 0; foreach (ModelMesh mesh in dwarf.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { //part.VertexArray.AddBinding(shader.VertexAttribute("vert").Slot, VertexUsage.Position); //part.VertexArray.AddBinding(shader.VertexAttribute("vertTexCoord").Slot, VertexUsage.TextureCoordinate); //shader.Bind(); //shader.Uniform1("tex", 0); //GL.ActiveTexture(TextureUnit.Texture0); //if (count == 0) // texture2.Bind(); //else // texture1.Bind(); //part.VertexArray.Bind(); //GL.DrawElements(part.VertexBuffer.BeginMode, part.IndexBuffer.Length, part.IndexBuffer.ElementsType, new IntPtr(0)); ////GL.DrawElementsBaseVertex(part.VertexBuffer.BeginMode, (int)part.NumIndicies, part.IndexBuffer.ElementsType, new IntPtr(part.StartIndex), (int)part.StartVertex); //count++; //Utilities.CheckGLError(); //part.VertexArray.Unbind(); //Utilities.CheckGLError(); //shader.Unbind(); //Utilities.CheckGLError(); //texture2.Unbind(); //shader.Bind(); //if (count == 0) // shader.BindUniforms(new Dictionary<string, IUniformValue>() { { "tex", UniformValue.Create(Sampler.Create(texture2)) } }); //else // shader.BindUniforms(new Dictionary<string, IUniformValue>() { { "tex", UniformValue.Create(Sampler.Create(texture1)) } }); //count++; // this will eventually be handled by a camera class attached to the GraphicsDevice //shader.BindUniforms(new Dictionary<string, IUniformValue>() { { "WorldView", UniformValue.Create(Matrix4.Mult(modelviewMatrix, projectionMatrix)) } }); //part.Material.Passes[0].Apply(_graphicsDevice); //part.Material.Passes[0].Program.Bind(); //part.Material.Passes[0].Program.BindUniforms(part.Material.Passes[0].Parameters); //shader.BindUniforms(part.Material.Passes[0].Parameters); _graphicsDevice.World = world; _graphicsDevice.DrawVertexArray(part.VertexArray, part.Material); } } // draw testing points for arm //if (buffer == null) //{ // buffer = VertexBuffer.Create(VertexFormat.PositionColor, points); // buffer.Bind(); // int slot1 = skeletonShader.VertexAttributeSlot("vert"); // GL.EnableVertexAttribArray(slot1); // GL.VertexAttribPointer(slot1, 3, VertexAttribPointerType.Float, false, 7 * sizeof(float), 0); // int slot2 = skeletonShader.VertexAttributeSlot("color"); // GL.EnableVertexAttribArray(slot2); // GL.VertexAttribPointer(slot2, 4, VertexAttribPointerType.Float, false, 7 * sizeof(float), 3 * sizeof(float)); //} //buffer.Bind(); //Utilities.CheckGLError(); //skeletonShader.Bind(); //Utilities.CheckGLError(); //Utilities.CheckGLError(); //GL.DrawArrays(BeginMode.Points, 0, buffer.Count); //Utilities.CheckGLError(); //skeletonShader.Unbind(); //buffer.Unbind(); //Utilities.CheckGLError(); //RenderSkeleton(dwarf.Skeleton); SwapBuffers(); DisposalManager.Process(); }