AdrianPi's picture

Tutorial outdated?

Project:The Open Toolkit library
Version:0.9.9-3
Component:Documentation
Category:bug report
Priority:normal
Assigned:Unassigned
Status:confirmed
Description

I've found no need for the loaded member variable and tests in this tutorial: http://www.opentk.net/doc/chapter/2/glcontrol

If things are done as explained in the tutorial, the loaded event for the control is never triggered and the control behaves like a transparent window.

I've simply done like this and it worked like a charm:

public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            this.ClientSize = new Size(640, 480);
        }
 
        private void glControl1_Resize(object sender, EventArgs e)
        {
            int w = glControl1.Width;
            int h = glControl1.Height;
            GL.Viewport(0, 0, w, h); // Use all of the glControl painting area
        }
 
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            GL.ClearColor(Color.Navy);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();            
            GL.Begin(BeginMode.Triangles);
            GL.Color3(Color.Red);
            GL.Vertex2(0, 0);
            GL.Color3(Color.Green);
            GL.Vertex2(1, 0);
            GL.Color3(Color.Blue);
            GL.Vertex2(0, 1);
            GL.End();
 
            glControl1.SwapBuffers();
 
        }

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
karlschiffmann's picture

#1

I just want to resize the glControl to the size of the containing client area... but I am not getting glControl1_Resize() or the glControl1_Paint() events happening from the code above (nor from the original Chapter 2 tutorial code either). I have hooked in these events to the control via the Form designer. Any ideas for me?

Besides that, the glControl never starts filling the client area either. Any ideas for me?

the Fiddler's picture

#2

Can you please post the contents of the Designer.cs file (or, even better, attach your project so I can reproduce the issue)?

The simplest way to fill the client area is to set the Dock parameter of the glControl to DockStyle.Fill.

karlschiffmann's picture

#3

Thank you for the quick response! Actually, the DockStyle.Fill did not do it for me... what did was I had not had the control "Anchored" on all sides. Now the control fills its container and gets the Resize event. Great.

But I am still not getting the Load event to fire... I just posted the code in the "Not firing Load event for GLControl" thread. (Sorry, I pasted it in before I saw the Upload file button...)

the Fiddler's picture

#4

Thanks, I'll check this and see what the problem is.

AdrianPi's picture

#5

For me, the Dock property set to Fill worked perfectly. It was what I was doing.

the Fiddler's picture

#6

Status:open» confirmed

Load and Resize events should fire correctly starting with SVN rev. 2371 (#1071: Not firing Load event for GLControl.).

The tutorial should be updated to reflect the latest version of the GLControl.