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)
{
glControl2.MakeCurrent();
PaintEventArgs p = null;
glControl2_Paint(sender,p);
GL.End();}

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)
        {
              glControl2.MakeCurrent();

              GL.End();
              glControl2.SwapBuffers();
              GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
              Draw_clock();
              GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
              GL.End();
              glControl2.SwapBuffers();
              drawsecond();
              glControl2.SwapBuffers();

        }

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.Color3(Color.Red);
            GL.Begin(BeginMode.Quads);

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

            GL.End();
        }

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.
thanks

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s