Windows 10 configuration of openGL freeglut, Glew and other libraries, using openGL

  • Author Environment Visual Studio 2019

Install freeGlut

Most of the tutorials on the web are about project configuration, which means you have to reconfigure every time you build a new project, so let’s do it in one step

  • First download the FreeGlut source and unzip it
  • Link: pan.baidu.com/s/1uMN5ALln… Extraction code: UWNG

Note that when configured in this way, there is no need to reconfigure when creating a new project. Also, the following tutorials are for 64-bit systems only.

  • Find the compiler directory for Visual Studio, using my default installation path of VS2019 as an example. The compiler directory is (other versions of VS or non-default installation path can be used similarly).

     C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314
    Copy the code
  • Copy the GL folder from the freeglut source file to the include folder in the compiler directory:

  • Copy the static data link library of FreeGlut to the VS library directory. Copy lib\x64\freeglut. Lib \x64\freeglut.

  • Copy the freeglut dynamic link library DLL file freeglut. DLL to the system directory: Copy bin\x64\ FreeGlut. DLL * to C:\Windows\System32** Copy bin\ Freeglut. DLL to C:\Windows\SysWOW64**

  • After the configuration is complete, start VS, create an empty project, and use it without additional configuration.


  • Create a new project and enter the following code tests. If correct, the configuration is successful

    #include <GL/glut.h> void Print() { glClear(GL_COLOR_BUFFER_BIT); GlRectf (0.5-0.5 f to 0.5 f, f, 0.5 f); glFlush(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(0, 100); glutInitWindowSize(800, 600); glutCreateWindow("Hello World!" ); glutDisplayFunc(Print); glutMainLoop(); return 0; }Copy the code

Install GLEw

  • Download the glew source code
  • Link: pan.baidu.com/s/1uMN5ALln… Extraction code: UWNG
  • willSource path \ glew-2.1.0.bin \Release\x64\glew32.dllCopied to thec:/windows/system32
  • Copy glew32.lib, glew32s.lib from glew-2.1.0-win32 glew-2.1.0-lib Release x64 to glew32s.libC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\libCopy the above two files to be on the safe sideC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\lib\x64
  • willGlew - 2.1.0 - win32 \ glew - 2.1.0 \ include \ GLCopy all the following files toC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\GL

Glut and Glew are then called in this format

#include <GL/glew.h> #include <GL/glut.h> #pragma comment (lib, "glew32.lib") void Print() { glClear(GL_COLOR_BUFFER_BIT); GlRectf (0.5-0.5 f to 0.5 f, f, 0.5 f); glFlush(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(0, 100); glutInitWindowSize(800, 600); glutCreateWindow("Hello World!" ); glutDisplayFunc(Print); glutMainLoop(); return 0; }Copy the code

If this project can also run smoothly, then the overall configuration has been completed, thank you for reading —— Jianhong Zhang, North University of China

  • By the way, pay attention to configuration at compile time

Add a fun little project and do a final environmental test

 #include <iostream>
 #include <fstream>
 #include <vector>
 #include <GL/glew.h>
 #include <GL/glut.h>
 #pragma comment (lib, "glew32.lib")
 using namespace std;
 ​
 class MapPoint
 {
 public:
     double longitude;
     double latitude;
 };
 class Polygona
 {
 public:
     vector<MapPoint> points;  //多边形的顶点序列 
 };
 vector<Polygona*> polys;   //多边形集合
 ​
 vector <Polygona*> ReadMapData(char* filename)
 {
     int PointCount;
     vector <Polygona*> polygonas;
     ifstream fs(filename);    //从指定路径中读取double类型的数据
     while (fs.eof() != true)
     {
         Polygona* poly = new Polygona;
         fs >> PointCount;
         cout << PointCount << endl;
         for (int i = 0; i < PointCount; i++)
         {
             MapPoint p;
             fs >> p.longitude >> p.latitude;
             poly->points.push_back(p);    //在尾部加入一个数据
         }
         polygonas.push_back(poly);
 ​
     }
     return polygonas;
 }
 void display(void)
 {
     glClear(GL_COLOR_BUFFER_BIT);    //用蓝色色绘制各省边界
     glColor3f(0.0, 0.0, 1.0);
     glPolygonMode(GL_BACK, GL_LINE);
     for (int i = 0; i < polys.size(); i++)
     {
         vector<MapPoint> points = polys[i]->points;
         glBegin(GL_LINE_LOOP);
         for (int j = 0; j < points.size(); j++)
         {
             glVertex3f(points[j].longitude, points[j].latitude, 0.0);
         }
         glEnd();
     }
     glFlush();
 }
 void init(void)
 {
     //设置背景颜色
     glClearColor(1.0, 1.0, 1.0, 0.0);
     //初始化观察值
     glMatrixMode(GL_PROJECTION);    //将矩阵模式设为投影
     glLoadIdentity();                 //对矩阵进行单位化
     glOrtho(110.0, 118.0, 30.0, 38.0, -1.0, 1.0);   //构造平行投影矩阵
 }
 int main(int argc, char** argv)
 {
     // 数据文件目录
     char* filename = (char*)"D:/2633716446/FileRecv/河南地图经纬度数据.txt";
     polys = ReadMapData(filename);
     glutInit(&argc, argv);
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
     //单缓存和RGB
     glutInitWindowSize(500, 500);
     glutInitWindowPosition(100, 100);
     glutCreateWindow("地图绘制");
     init();
     glutDisplayFunc(display);     //显示回调函数
     glutMainLoop();
     return 0;
 }
 ​
Copy the code