Leo Sun
Leo Sun

Reputation: 1

Opentk glcontrol in the winforms with c# visual studio 2010?

I used openTK control to draw something,but it wass always displaying a white background. WHY?

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using OpenTK;
    using OpenTK.Graphics.OpenGL;
    using OpenTK.Input;

    namespace WindowsFormsApplication10
    {
        public partial class Form1 : Form
        {
            bool loaded = false;
            public Form1()
            {
                InitializeComponent();
            }

            private void glControl1_Load(object sender, EventArgs e)
            {
                loaded = true;
                GL.ClearColor(Color.SkyBlue); // Yey! .NET Colors can be used directly!
            }
            private void glControl1_Resize(object sender, EventArgs e)
            {
                if (!loaded)
                    return;
            }
            private void glControl1_Paint(object sender, PaintEventArgs e)
            {
                if (!loaded) // Play nice
                    return;

                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                glControl1.SwapBuffers();
            }
        }
    }

Upvotes: 0

Views: 3998

Answers (2)

Maksym V.
Maksym V.

Reputation: 2937

Simply, u forgot to add call of glControl1_Paint, goto properties of that control, open events, on the top inside Appearance add a call.

Upvotes: 1

Alexey Suslov
Alexey Suslov

Reputation: 73

While using GLControl instead of GameWindow, you should call glControl1.Invalidate() every time you need to display changes.

Upvotes: 0

Related Questions