参考:https://blog.csdn.net/qq_41598072/article/details/81543428
https://blog.csdn.net/linian71/article/details/68485494
目录
一、freeglut介绍
先介绍下Glut库。GLUT最初由MarkKilgard编写,从OpenGL Redbook(红宝书)第二版起就用来作为示例程序的支持环境,直到第八版为止(注:第九版开始改为GLFW)。从那时起,GLUT因为其简单、可用性广、可移植性强,被广泛应用于各种OpenGL实际应用中。Glut最新版本为3.7版,大致在1998年8月停止维护和更新。
Freeglut是Glut库(OpenGL Utility Toolkit,OpenGL实用工具包)的免费开源替代品。它是由Pawel W. Olszta在1999年12月创建,最新版本为2015年3月的3.0版本。
二、freeglut下载及编译
1、下载
freeglut下载地址 http://freeglut.sourceforge.net/index.php#download
2、用CMake编译生成freeglut.sln
打开CMake,没有的去这里下载并安装https://cmake.org/download/
选好目录,点Configure选好需要的编译器,完成后点Generate
设置CMAKE_INSTALL_PREEFIX为你的install目录,我设置为F:/third/freeglut/install
3、编译freeglut.sln
在输出文件中找到freeglut.sln,用vs08打开,选好Debug还是Release。编译ALL_BUILD。
在debug和release模式下都生成解决方案一下,然后再release模式下生成install项
三、freeglut使用
#include <windows.h>
#include <GL/freeglut.h>
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0, 0);
static float sc = 1.0;
glRectf(-0.5f*sc, -0.5f*sc, 0.5f*sc, 0.5f*sc);
sc = sc *1.01;
glFlush();
}
void timerProc(int id)
{
myDisplay();
glutTimerFunc(33, timerProc, 1);//需要在函数中再调用一次,才能保证循环
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("第一个OpenGL程序");
glutDisplayFunc(&myDisplay);
glutTimerFunc(33, timerProc, 1);
glutMainLoop();
return 0;
}
显示的是一个不断变化的正方形,使用glutTimerFunc来对窗口进行不断的刷新。