The button should have a width of 17 pixel and a height of 17 pixel.
My project has a reference to the OpenTK-assembly. The main windows-form hosts a glControl where I can draw on it.
To initialize the control, I run the following commands after the control’s loaded (I will only draw 2d objects):
GL.ClearColor(Color.White)
GL.Disable(EnableCap.DepthTest)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
After the commands above and after each resize I setup the viewport :
GL.MatrixMode(MatrixMode.Projection)
GL.LoadIdentity()
GL.Ortho(0, Me.glControl1.Width, Me.glControl1.Height, 0, 0, 128)
GL.Viewport(0, 0, Me.glControl1.Width, Me.glControl1.Height)
When the paint-event is raised, I draw my button with the following commands :
GL.Clear(ClearBufferMask.ColorBufferBit)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
Dim rect AS RectangleF = New RectangleF(2, 2, 17, 17)
’ ############0
’ #000000000000
’ #000000000000
’ #000000000000
’ 0000000000000
GL.Color3(SystemColors.ControlLight)
GL.Begin(BeginMode.LineStrip)
GL.Vertex2(rect.Right - 1, rect.Top + 1)
’ when I here add 1 pixel to the X-position, the corner will not be painted
GL.Vertex2(rect.Left, rect.Top + 1)
GL.Vertex2(rect.Left + 1, rect.Bottom - 1)
GL.End()
' 0000000000000
' 0##########00
' 0#00000000000
' 0#00000000000
' 0000000000000
GL.Color3(SystemColors.ControlLightLight)
GL.Begin(BeginMode.LineStrip)
GL.Vertex2(rect.Right - 2, rect.Top + 2)
' when I here add 2 pixels to the X-position, the corner will not be painted
GL.Vertex2(rect.Left + 1, rect.Top + 2)
GL.Vertex2(rect.Left + 2, rect.Bottom - 1)
GL.End()
' 000000000000#
' 000000000000#
' 000000000000#
' 000000000000#
' #############
GL.Color3(SystemColors.ControlDarkDark)
GL.Begin(BeginMode.LineStrip)
GL.Vertex2(rect.Left, rect.Bottom)
' when I here subtract 1 pixel from the X-position, the corner will not be painted
GL.Vertex2(rect.Right, rect.Bottom)
GL.Vertex2(rect.Right - 1, rect.Top)
GL.End()
' 0000000000000
' 000000000000#0
' 000000000000#0
' 0###########0
' 0000000000000
GL.Color3(SystemColors.ControlDark)
GL.Begin(BeginMode.LineStrip)
GL.Vertex2(rect.Left + 1, rect.Bottom - 1)
' when I here subtract 2 pixels from the X-position, the corner will not be painted
GL.Vertex2(rect.Right - 1, rect.Bottom - 1)
GL.Vertex2(rect.Right - 2, rect.Top + 1)
GL.End()
' 0000000000000
' 0000000000000
' 00#########00
' 0000000000000
' 0000000000000
GL.Color3(SystemColors.Control)
GL.Begin(BeginMode.Quads)
GL.Vertex2(rect.Left + 2, rect.Top + 2)
GL.Vertex2(rect.Right - 2, rect.Top + 2)
GL.Vertex2(rect.Right - 2, rect.Bottom - 2)
GL.Vertex2(rect.Left + 2, rect.Bottom - 2)
GL.End()
Me.glControl1.SwapBuffers()
This code works on my development-machine and draws the button correctly.
The second thing I don’t understand: I have to subtract or add 1 pixel for each corner to draw it. But why?