Anonymous
Почему программа, написанная на C# с использованием OpenTK, отображает только пустое серое окно?
Сообщение
Anonymous » 08 янв 2025, 18:13
Я пишу программу на C# для рендеринга трех трехмерных объектов: сферы, призмы и шестиугольной пирамиды, используя OpenGL с OpenTK.
Проблема в том, что она этого не делает. t отображать любые ошибки или исключения; он просто отображает пустое окно с серым фоном (указанный мной цвет).
Вот полный код:
Код: Выделить всё
public class Game : GameWindow
{
public Game() : base(GameWindowSettings.Default, NativeWindowSettings.Default)
{
this.CenterWindow(new Vector2i(800, 600));
}
protected override void OnLoad()
{
GL.ClearColor(new Color4(0.1f, 0.1f, 0.1f, 1.0f));
GL.Enable(EnableCap.DepthTest);
base.OnLoad();
}
protected override void OnResize(ResizeEventArgs e)
{
GL.Viewport(0, 0, e.Width, e.Height);
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)Size.X / Size.Y, 0.1f, 100.0f);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref projection);
base.OnResize(e);
}
protected override void OnUpdateFrame(FrameEventArgs args)
{
base.OnUpdateFrame(args);
}
protected override void OnRenderFrame(FrameEventArgs args)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 modelview = Matrix4.LookAt(new Vector3(5, 5, 5), Vector3.Zero, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);
GL.Color3(1.0, 0.0, 0.0);
this.DrawSphere(1.0, 20, 20);
GL.Color3(0.0, 1.0, 0.0);
GL.PushMatrix();
GL.Translate(3.0, 0.0, 0.0);
this.DrawTriangularPrism();
GL.PopMatrix();
GL.Color3(0.0, 0.0, 1.0);
GL.PushMatrix();
GL.Translate(-3.0, 0.0, 0.0);
this.DrawHexagonalPyramid();
GL.PopMatrix();
GL.Flush();
this.Context.SwapBuffers();
base.OnRenderFrame(args);
}
private void DrawSphere(double radius, int lats, int longs)
{
for (int i = 0; i
Подробнее здесь: [url]https://stackoverflow.com/questions/79339701/why-does-the-program-written-in-c-sharp-using-opentk-display-only-an-empty-gray[/url]
1736349187
Anonymous
Я пишу программу на C# для рендеринга трех трехмерных объектов: сферы, призмы и шестиугольной пирамиды, используя OpenGL с OpenTK. Проблема в том, что она этого не делает. t отображать любые ошибки или исключения; он просто отображает пустое окно с серым фоном (указанный мной цвет). Вот полный код: [code]public class Game : GameWindow { public Game() : base(GameWindowSettings.Default, NativeWindowSettings.Default) { this.CenterWindow(new Vector2i(800, 600)); } protected override void OnLoad() { GL.ClearColor(new Color4(0.1f, 0.1f, 0.1f, 1.0f)); GL.Enable(EnableCap.DepthTest); base.OnLoad(); } protected override void OnResize(ResizeEventArgs e) { GL.Viewport(0, 0, e.Width, e.Height); Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)Size.X / Size.Y, 0.1f, 100.0f); GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref projection); base.OnResize(e); } protected override void OnUpdateFrame(FrameEventArgs args) { base.OnUpdateFrame(args); } protected override void OnRenderFrame(FrameEventArgs args) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Matrix4 modelview = Matrix4.LookAt(new Vector3(5, 5, 5), Vector3.Zero, Vector3.UnitY); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref modelview); GL.Color3(1.0, 0.0, 0.0); this.DrawSphere(1.0, 20, 20); GL.Color3(0.0, 1.0, 0.0); GL.PushMatrix(); GL.Translate(3.0, 0.0, 0.0); this.DrawTriangularPrism(); GL.PopMatrix(); GL.Color3(0.0, 0.0, 1.0); GL.PushMatrix(); GL.Translate(-3.0, 0.0, 0.0); this.DrawHexagonalPyramid(); GL.PopMatrix(); GL.Flush(); this.Context.SwapBuffers(); base.OnRenderFrame(args); } private void DrawSphere(double radius, int lats, int longs) { for (int i = 0; i Подробнее здесь: [url]https://stackoverflow.com/questions/79339701/why-does-the-program-written-in-c-sharp-using-opentk-display-only-an-empty-gray[/url]