一、首先确保已经通过NuGet安装了nupengl
二、解决方案平台设置为x64
因为在x86下要报错,未找到原因
三、写示例代码
#include <GL/freeglut.h>
//运行发布出来的exe时,不再显示dos窗口,但在VS中运行还是会显示。
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glutSolidSphere(0.5, 50, 6);
glFlush();
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(200, 200);
glutInitWindowPosition(0, 0);
glutCreateWindow("第一个窗口");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
四、运行