190 likes | 338 Vues
This presentation provides an overview of how to draw basic primitive shapes using OpenTK, an OpenGL wrapper for .NET. It demonstrates various methods for rendering lines, polygons, and triangles, which are some of the most common graphical primitives. Examples include drawing lines, closed polygons, triangle strips, and more. This guide describes how to set color, clear the screen, and force rendering for visual output. While there are multiple approaches to generating these primitives, the methods shown here are among the most prevalent in OpenTK applications.
E N D
Foreward This presentation shows how some primitive shapes may be drawn using openTK (openGL) This is not the only approach to draw these primitives, but may be the most common
DrawLine() private void DrawLine() { // Clear screen to background color. GL.Clear(ClearBufferMask.ColorBufferBit); // Set foreground (or drawing) color. GL.Color3(Color.White); GL.Begin(BeginMode.Lines); GL.Vertex3(20.0, 20.0, 0.0); GL.Vertex3(80.0, 20.0, 0.0); GL.Vertex3(80.0, 80.0, 0.0); GL.Vertex3(20.0, 80.0, 0.0); GL.End(); // Flush created objects to the screen, i.e., force rendering. glControl1.SwapBuffers(); }
Polygon private void DrawPolygon() { // Clear screen to background color. GL.Clear(ClearBufferMask.ColorBufferBit); // Set foreground (or drawing) color. GL.Color3(Color.White); GL.Begin(BeginMode.Polygon); GL.Vertex3(20.0, 20.0, 0.0); GL.Vertex3(80.0, 20.0, 0.0); GL.Vertex3(80.0, 80.0, 0.0); GL.Vertex3(20.0, 80.0, 0.0); GL.End(); // force rendering. glControl1.SwapBuffers(); }
Triangles private void DrawLine() { // Clear screen to background color. GL.Clear(ClearBufferMask.ColorBufferBit); // Set foreground (or drawing) color. GL.Color3(Color.White); GL.Begin(BeginMode.Triangles); GL.Vertex3(10.0, 90.0, 0.0); GL.Vertex3(10.0, 10.0, 0.0); GL.Vertex3(35.0, 75.0, 0.0); GL.Vertex3(30.0, 20.0, 0.0); GL.Vertex3(90.0, 90.0, 0.0); GL.Vertex3(80.0, 40.0, 0.0); GL.End(); // force rendering. glControl1.SwapBuffers(); }
LineStrip private void DrawLineStrip() { // Clear screen to background color. GL.Clear(ClearBufferMask.ColorBufferBit); // Set foreground (or drawing) color. GL.Color3(Color.White); GL.Begin(BeginMode.LineStrip); GL.Vertex3(20.0, 20.0, 0.0); GL.Vertex3(80.0, 20.0, 0.0); GL.Vertex3(80.0, 80.0, 0.0); GL.Vertex3(20.0, 80.0, 0.0); GL.End(); // force rendering. glControl1.SwapBuffers(); }
TriangleFan private void DrawTRFan() { // Clear screen to background color. GL.Clear(ClearBufferMask.ColorBufferBit); // Set foreground (or drawing) color. GL.Color3(Color.White); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); // Draw a polygon with specified vertices. GL.Begin(BeginMode.TriangleFan); GL.Vertex3(10.0, 10.0, 0.0); GL.Vertex3(15.0, 90.0, 0.0); GL.Vertex3(55.0, 75.0, 0.0); GL.Vertex3(80.0, 30.0, 0.0); GL.Vertex3(90.0, 10.0, 0.0); GL.End(); // Flush created objects to the screen, i.e., force rendering. glControl1.SwapBuffers(); }
QuadStrip private void DrawQDStrip() { // Clear screen to background color. GL.Clear(ClearBufferMask.ColorBufferBit); // Set foreground (or drawing) color. GL.Color3(Color.White); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); // Draw a polygon with specified vertices. GL.Begin(BeginMode.QuadStrip); // glBegin(GL_LINE_STRIP); // glBegin(GL_LINE_LOOP); GL.Vertex3(10.0, 90.0, 0.0); GL.Vertex3(10.0, 10.0, 0.0); GL.Vertex3(30.0, 80.0, 0.0); GL.Vertex3(40.0, 15.0, 0.0); GL.Vertex3(60.0, 75.0, 0.0); GL.Vertex3(60.0, 25.0, 0.0); GL.Vertex3(90.0, 90.0, 0.0); GL.Vertex3(80.0, 20.0, 0.0); GL.End(); // Flush created objects to the screen, i.e., force rendering. glControl1.SwapBuffers(); }