0

In a practice from CodeProject, I used C#; In my window form I select an GLControl from toolbox and put the code below in Resize and load event of this control, but when I run the project the form is blank.

Where is the mistake?

    int w = glControl1.Width;
    int h = glControl1.Height;
    glControl1.MakeCurrent();
    Color4 _newColor = new Color4(1f, 0f, 1f, 1f);
    GL.ClearColor(_newColor);
    glControl1.Invalidate();
    GL.MatrixMode(MatrixMode.Projection);
    GL.LoadIdentity();
    GL.Ortho(-w / 2, w / 2, -h / 2, h / 2, -1, 1);
    GL.Viewport(0, 0, w, h);
    GL.End();
    glControl1.SwapBuffers();
Sumurai8
  • 20,333
  • 11
  • 66
  • 100

2 Answers2

0

I'm not used to the C# openGL api. But I think that you've only set the clear colour. You need to tell openGL to clear the GL_COLOR_BUFFER_BIT. I believe that would be something like:

Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
James Snook
  • 4,063
  • 2
  • 18
  • 30
  • I thought so but I test GL.clear with two parameter so: GL.Clear(ClearBufferMask.ColorBufferBit | learBufferMask.DepthBufferBit); and the output was not changed! – user3159964 Feb 15 '14 at 08:55
0
  1. Click anywhere on the GLControl in the Designer
  2. Make sure glControl1 is listed in the Properties window
  3. Click the "Events" button to list all events of glControl1
  4. Double-click the empty cell right of the Load event to create and hook an event handler for the Load event. Just repeat these steps for your Resize, Paint function. And there is no need GL.End();
user987339
  • 10,519
  • 8
  • 40
  • 45
Ali
  • 13
  • 1
  • 4