private void LinkShadowMapResources(GraphicsContext ctx) { LinkResource(_ShadowMapQuad = new VertexArrays()); ArrayBuffer <Vertex2f> positionArray = new ArrayBuffer <Vertex2f>(BufferUsage.StaticDraw); positionArray.Create(new Vertex2f[] { new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 0.0f), new Vertex2f(1.0f, 1.0f), new Vertex2f(0.0f, 1.0f), new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 1.0f), }); positionArray.Create(ctx); _ShadowMapQuad.SetArray(positionArray, VertexArraySemantic.Position); _ShadowMapQuad.SetArray(positionArray, VertexArraySemantic.TexCoord); _ShadowMapQuad.SetElementArray(PrimitiveType.Triangles); _ShadowMapQuad.Create(ctx); LinkResource(_ShadowMapDebugProgram = ctx.CreateProgram("OpenGL.Specialized+Depth")); }
private void CreateResources(GraphicsContext ctx) { // Program library _Context.MergeShadersLibrary("HelloObjects.Shaders._ShadersLibrary.xml"); // Mass buffer _MassBuffer = new ArrayBufferInterleaved <Mass>(BufferUsage.StaticDraw); _Context.LinkResource(_MassBuffer); // _MassBuffer.Immutable = false; _MassBuffer.Create(_Size); // Map arrays _MassArrays = new VertexArrays(); _Context.LinkResource(_MassArrays); _MassArrays.SetArray(_MassBuffer, 0, VertexArraySemantic.Position); _MassArrays.SetElementArray(PrimitiveType.Points, 0, 1024); _MassArrays.Create(_Context); // Programs _ComputeEnergy = _Context.CreateProgram("HelloObjects.MassForceCompute"); _ComputePosition = _Context.CreateProgram("HelloObjects.MassPositionCompute"); _DrawMass = _Context.CreateProgram("OpenGL.Standard"); // Initiailize mass buffer Random random = new Random(); _MassBuffer.Map(_Context, BufferAccessMask.MapWriteBit); for (uint i = 0; i < _MassBuffer.ItemsCount; i++) { Mass mass; mass.Position = new Vertex4f((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 1.0f) * 256.0f; mass.Velocity = new Vertex4f((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 1.0f) * 0.000f; mass.Force = new Vertex4f(0.0f, 0.0f, 0.0f, (float)Math.Abs(random.NextDouble() * 100000.0)); _MassBuffer.SetElement(mass, i); } _MassBuffer.Unmap(_Context); }
public void ExampleSetVertexArraysIndexedElements(GraphicsContext ctx, ShaderProgram shaderProgram) { VertexArrays vao = new VertexArrays(); // ... create and setup buffers ... ElementBuffer <int> indexBuffer = new ElementBuffer <int>(BufferUsage.StaticDraw); indexBuffer.Create(new int[] { 0, 1, 2, 3, 2, 1 }); // Draw the first 6 deferenced vertices as GL_TRIANGLES int idx1 = vao.SetElementArray(PrimitiveType.Triangles, indexBuffer); // Draw the first two deferenced vertices as GL_LINES int idx2 = vao.SetElementArray(PrimitiveType.Lines, indexBuffer, 0, 2); // Create/update all resources linked to this instance vao.Create(ctx); // Draw all elements vao.Draw(ctx, shaderProgram); // Draw only the triangles vao.Draw(ctx, shaderProgram, idx1); }
public void ExampleSetVertexArraysElements(GraphicsContext ctx, ShaderProgram shaderProgram) { VertexArrays vao = new VertexArrays(); // ... create and setup buffers ... // Draw the first 4 vertices as GL_LINES int idx1 = vao.SetElementArray(PrimitiveType.Lines, 0, 4); // Draw all other vertices using GL_TRIANGLES int idx2 = vao.SetElementArray(PrimitiveType.Triangles, 4, vao.ArrayLength); // Draw all vertices using GL_POINTS int idx3 = vao.SetElementArray(PrimitiveType.Points); // Create/update all resources linked to this instance vao.Create(ctx); // Draw all elements vao.Draw(ctx, shaderProgram); // Draw only the triangles vao.Draw(ctx, shaderProgram, idx2); // Draw using IElement interface (idx1 and idx3) vao.Draw(ctx, shaderProgram, vao.GetElementArray(idx1), vao.GetElementArray(idx3)); }
private void VisionControl_ContextCreated(object sender, OpenGL.GlControlEventArgs e) { // Create GL context abstraction _GraphicsContext = new GraphicsContext(e.DeviceContext, e.RenderContext); // Create texture _FramebufferTexture = new Texture2d(1024, 1024, PixelLayout.RGB24); _FramebufferTexture.SamplerParams.MagFilter = TextureMagFilter.Linear; _FramebufferTexture.SamplerParams.MinFilter = TextureMinFilter.Linear; _FramebufferTexture.Create(_GraphicsContext); // Create framebuffer _Framebuffer = new Framebuffer(); _Framebuffer.AttachColor(0, _FramebufferTexture); _Framebuffer.Create(_GraphicsContext); // Create shader (standard) _ProgramStd = _GraphicsContext.CreateProgram("OpenGL.Standard"); _ProgramStd.Create(_GraphicsContext); // Create program (standard + texture) _ProgramStdTex = _GraphicsContext.CreateProgram("OpenGL.Standard+Texture"); _ProgramStdTex.Create(_GraphicsContext); // Create vertex arrays (square) ArrayBuffer <Vertex2f> quadBuffer = new ArrayBuffer <Vertex2f>(BufferUsage.StaticDraw); quadBuffer.Create(new Vertex2f[] { new Vertex2f(-0.5f, +0.5f), new Vertex2f(-0.5f, -0.5f), new Vertex2f(+0.5f, +0.5f), new Vertex2f(+0.5f, -0.5f), }); _ArraysQuad = new VertexArrays(); _ArraysQuad.SetArray(quadBuffer, VertexArraySemantic.Position); _ArraysQuad.SetElementArray(PrimitiveType.TriangleStrip); _ArraysQuad.Create(_GraphicsContext); // Create vertex arrays (square) ArrayBuffer <Vertex2f> postquadBuffer = new ArrayBuffer <Vertex2f>(BufferUsage.StaticDraw); postquadBuffer.Create(new Vertex2f[] { new Vertex2f(0.0f, 1.0f), new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 1.0f), new Vertex2f(1.0f, 0.0f), }); _ArraysPostQuad = new VertexArrays(); _ArraysPostQuad.SetArray(postquadBuffer, VertexArraySemantic.Position); _ArraysPostQuad.SetArray(postquadBuffer, VertexArraySemantic.TexCoord); _ArraysPostQuad.SetElementArray(PrimitiveType.TriangleStrip); _ArraysPostQuad.Create(_GraphicsContext); // Create vertex arrays (optical markers) _BufferOpticalMarkers = new ArrayBuffer <Vertex2f>(BufferUsage.DynamicDraw); _BufferOpticalMarkers.Create(10000 * 2); _ArraysOpticalMarkers = new VertexArrays(); _ArraysOpticalMarkers.SetArray(_BufferOpticalMarkers, VertexArraySemantic.Position); _ArraysOpticalMarkers.SetElementArray(PrimitiveType.Lines); _ArraysOpticalMarkers.Create(_GraphicsContext); }