OpenTK a simple 2d clock design in windows form C# (basic OpenTK-3)

please see first part and second part before start it.

Now we have to create a timer event for that, so first add a timer select interval at 1000 for 1 s enable it and add this event at timer tick

;private void timer1_Tick(object sender, EventArgs e)
PaintEventArgs p = null;

now paint method will be call after one second u have to draw line for second there, so paint event will be like

  private void glControl2_Paint(object sender, PaintEventArgs e)

              GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
              GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


here for draw second we need a static variable for chage the coordinate of seconds line vertex position we take

 static int i = 0;

now drawsecond() function

 void  drawsecond()

            GL.Vertex2(5, 0);
            GL.Vertex2(-5, 5);
            double degInRad = i * 3.1416 / 180;
            GL.Vertex2(Math.Cos(degInRad) * 80, Math.Sin(degInRad) * 80);
            GL.Vertex2(Math.Cos(degInRad) * 85, Math.Sin(degInRad) * 85);

            i = i - 6;
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


here static variable subtracted for rotating in clockwise and subtracted by 6 because 360/6 equal to 60 which we need to round the circle.

so seconds line is rotating now

now in 4th part we will see how we can use rotate, translate and scale operation and then we will make it to take real time.

About kishor datta gupta

Graduate Research Assistant at University of Memphis Software Engineer at Silicon Orchard LTD. Former Research Assistant at Lamar University Former Software Engineer at Samsung R&D Institute Bangladesh Studies Ph.D. Computer Science at University of Memphis Studied Masters of Science in Computer Sciences at Lamar University Studied BSC in CSE at Khulna University of Engineering and Technology Studied HSC (completed) at Chittagang college 04-06 Studied High school at ST. Placid's High School'04 Studied Junior Secondary School at Saint Mary's School Lives in Memphis, Tennessee
This entry was posted in C#, OpenTK, Winform app and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s