Opentk 显示黑屏而不是三角形
Opentk showing black screen instead of triangle
我创建了一个简单的应用程序来显示三角形,但它只显示黑色 window。
class Program
{
static void Main(string[] args)
{
GameWindow window = new GameWindow(800,600);
game game = new game(window);
window.Run(1.0/60.0);
}
}
class game
{
GameWindow window = new GameWindow();
public game(GameWindow window)
{
this.window = window;
window.Load += Window_Load;
window.UpdateFrame += Window_UpdateFrame;
window.RenderFrame += Window_RenderFrame;
}
private void Window_RenderFrame(object sender, FrameEventArgs e)
{
GL.ClearColor(Color.CornflowerBlue);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Viewport(0, 0, 800, 600);
GL.Begin(PrimitiveType.Triangles);
GL.Color3(Color.OrangeRed);
GL.Vertex2(0, 0);
GL.Vertex2(1, 0);
GL.Vertex2(0, 1);
GL.End();
window.SwapBuffers();
}
private void Window_UpdateFrame(object sender, FrameEventArgs e)
{
}
private void Window_Load(object sender, EventArgs e)
{
}
}
您不小心创建了 2 个 GameWindow
对象。只需创建一个 GameWindow
:
class Program
{
static void Main(string[] args)
{
GameWindow window = new GameWindow(800, 600);
game game = new game(window);
window.Run(1.0 / 60.0);
}
}
class game
{
GameWindow window; // <--- remove: = new GameWindow();
public game(GameWindow window)
{
this.window = window;
window.Load += Window_Load;
window.UpdateFrame += Window_UpdateFrame;
window.RenderFrame += Window_RenderFrame;
}
// [...]
我创建了一个简单的应用程序来显示三角形,但它只显示黑色 window。
class Program
{
static void Main(string[] args)
{
GameWindow window = new GameWindow(800,600);
game game = new game(window);
window.Run(1.0/60.0);
}
}
class game
{
GameWindow window = new GameWindow();
public game(GameWindow window)
{
this.window = window;
window.Load += Window_Load;
window.UpdateFrame += Window_UpdateFrame;
window.RenderFrame += Window_RenderFrame;
}
private void Window_RenderFrame(object sender, FrameEventArgs e)
{
GL.ClearColor(Color.CornflowerBlue);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Viewport(0, 0, 800, 600);
GL.Begin(PrimitiveType.Triangles);
GL.Color3(Color.OrangeRed);
GL.Vertex2(0, 0);
GL.Vertex2(1, 0);
GL.Vertex2(0, 1);
GL.End();
window.SwapBuffers();
}
private void Window_UpdateFrame(object sender, FrameEventArgs e)
{
}
private void Window_Load(object sender, EventArgs e)
{
}
}
您不小心创建了 2 个 GameWindow
对象。只需创建一个 GameWindow
:
class Program
{
static void Main(string[] args)
{
GameWindow window = new GameWindow(800, 600);
game game = new game(window);
window.Run(1.0 / 60.0);
}
}
class game
{
GameWindow window; // <--- remove: = new GameWindow();
public game(GameWindow window)
{
this.window = window;
window.Load += Window_Load;
window.UpdateFrame += Window_UpdateFrame;
window.RenderFrame += Window_RenderFrame;
}
// [...]