我在c ++中搞乱了OpenGL,但我想用我更熟悉的语言测试它。
我从OpenGL红皮书中得到了一个例子(据我所知,这是第一个),其中包括以下内容:
#include <whateverYouNeed.h>
main() {
InitializeAWindowPlease();
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush();
UpdateTheWindowAndCheckForEvents();
}
我正在尝试使用C#的OpenTK包装器做同样的事情,这就是我想出的:
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TEST2
{
class Program
{
static void Main(string[] args)
{
using (GameWindow gameWindow = new GameWindow())
{
gameWindow.Load += (sender, e) =>
{
gameWindow.VSync = VSyncMode.On;
gameWindow.Title = "Test";
};
gameWindow.Resize += (sender, e) =>
{
GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
};
gameWindow.UpdateFrame += (sender, e) =>
{
};
gameWindow.RenderFrame += (sender, e) =>
{
//Here's the main content of the 'converted' code
GL.ClearColor(0.0f,0.0f,0.0f,0.0f);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Color3(1.0f, 1.0f, 1.0f);
GL.Ortho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
GL.Begin(PrimitiveType.Polygon);
GL.Vertex3(0.25f, 0.25f, 0.0f);
GL.Vertex3(0.75f, 0.25f, 0.0f);
GL.Vertex3(0.75f, 0.75f, 0.0f);
GL.Vertex3(0.25f, 0.75f, 0.0f);
GL.End();
GL.Flush();
gameWindow.SwapBuffers();
};
gameWindow.Run(10);
}
}
}
}
现在我假设这样做会在黑色背景上显示一个白色的盒子,就像OpenGL的例子显然那样,但它似乎不起作用......我是什么做错了?是我的窗户处理吗?