一个简单的OpenGL程序 绘制一个多边形

OpenGL配置请参考 https://blog.csdn.net/jennybi/article/details/79736349

#include
#include
#include


void CALLBACK display(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0 ,-1.0, 1.0 , -1.0, 1.0);


glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
auxInitPosition(0, 0, 500, 500);
auxInitWindow((LPCWSTR)argv[0]);
auxMainLoop(display);
return 0;

}

注:

1 添加附加依赖库glaux.lib;glu32.lib;opengl32.lib;glut32.lib;

2 编译出现error LNK2019: 无法解析的外部符号 _sscanf,该符号在函数 _GetRegistrySysColors@8 中被引用

在附加依赖库中添加 legacy_stdio_definitions.lib;

一个简单的OpenGL程序 绘制一个多边形_第1张图片

运行结果:

一个简单的OpenGL程序 绘制一个多边形_第2张图片

你可能感兴趣的:(opengl)