我在这个类中生成具有给定随机数的矩形。
class Rect
{
double x;
double y;
public Rect(double _x, double _y)
{
x = _x;
y = _y;
}
public void Draw()
{
Gl.glBegin(Gl.GL_QUADS);
Gl.glVertex2d(x + (-0.05d), y + (-0.05d));
Gl.glVertex2d(x + (-0.05d), y + (0.05d));
Gl.glVertex2d(x + (0.05d), y + (0.05d));
Gl.glVertex2d(x + (0.05d), y + (-0.05d));
Gl.glEnd();
}
}
我在 Paint 函数中调用它。
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
{
Gl.glClearColor(0, 1, 0, 0);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
for (int i = 0; i < 4; i++)
{
rand = new Random();
double x = 2 * rand.NextDouble() - 1;
double y = 2 * rand.NextDouble() - 1;
rect= new Rect(x,y);
rect.Draw();
}
}
一切看起来都很好,但有问题。我看不到所有的矩形。其中一些失踪了。但是,如果我在某处切换断点或放置MessageBox.Show(x+" "+y);
代码可以正常工作并向我显示我想要的矩形数量。我认为我的代码是正确的,但 OpenGL 有问题。我正在使用 Tao 框架。