amikaml's picture

Doesn't work

Hi all,
I am using Visual Studio 2008 in WinXP + OpenGL 3.1 support driver for Geforce 9500 GT.
I tried the simple example from the tutorial but it doens't work (the window is not painted). What I have to do more? Thanks.
The code (C#, Windows forms)

using OpenTK.Graphics;
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;

namespace glnet
{
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);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-20, 20, -20, 20, -1, 1);
GL.Viewport(0, 0, 297, 270);
}

private void glControl1_Resize(object sender, EventArgs e)
{
if (!loaded)
return;
}

private void glControl1_Paint(object sender, PaintEventArgs e)
{
if (!loaded)
return;

double ang;
double x, y;

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

GL.Color3(Color.Yellow);

GL.Begin(BeginMode.Polygon);
for (ang = 0; ang < 2 * Math.PI; ang += (2 * Math.PI / 4))
{
x = 10 * Math.Cos(ang);
y = 10 * Math.Sin(ang);
GL.Vertex2(x, y);
}
GL.End();

glControl1.SwapBuffers();
}
}
}


Comments

Comment viewing options

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

1 - try remove glControl1.SwapBuffers(); after GL.Clear
2 - add Timer to Form, enable it, and add glControl1.Invalidate(); to Timer_Tick event

amikaml's picture

Thanks, but it didn't help.
Maybe it is possible to use OpenTK with VS2005 only?

the Fiddler's picture

OpenTK works fine with VS2008 and 2010.

You are hitting bug #1071: Not firing Load event for GLControl.. The workaround is to add the GL.Viewport call to the Resize event.