Customized Freeglut and studiofreeglut for Visual Studio
It is common for programmers who use Microsoft Visual Studio to develop applications in Windows. The configuration of Freeglut in Visual Studio is mostly done by directly downloading binary files compiled for a specific version of Visual Studio on the Internet. However, there are many versions of Visual Studio, so these directly downloaded files are not necessarily suitable for our own Visual Studio. Freeglut, as a cross-platform OpenGL development tool, has fully considered the configuration and installation requirements for various platforms, but it does not directly provide binary forms that can be used for use. On the contrary, only the source code is provided. After the programmers compile the source code based on their respective platforms, they can get the appropriate version. However, this process is relatively cumbersome, resulting in many programmers do not know where to start.
This article describes in detail how to compile and configure freeglut for free Visual Studio Community 2013, and finally develop and run a simplest OpenGL application.
Download and install free Visual Studio Community 2013
Download vs_ommunity.exe. It is best to use IE to open the above address. other browsers may be able to access the webpage, but do not open it. This is an online installation program with a size of only 1.18M. You can also visit this page to download the DVD9 ISO image file with the size of 6.89G. I have tried these two types of files. The ISO image file can be mounted on a 32-bit Windows 7, but it seems that it cannot be installed on a 64-bit Windows 7, if you encounter this problem, you can select an online installation program.
Download and install ...... This is a long process, especially online installation. I started online installation before I went to work. After work, I had to install it automatically.
If necessary, you can also install the Simplified Chinese Language Pack.
Download Freeglut
Download Freeglut from Freeglut and decompress it to a folder, such as C: \ freeglut. The directory contains two important folders: include, the header file of C, and src, which contains the source code to be compiled.
Compile Freeglut
Download a CMake file that can be directly installed on Windows at cmake.org, and double-click the file to install it.
After installation, run CMake and set it accordingly.
Where is the source code used to specify the directory of the decompressed Freeglut, which has a subdirectory of src. Where to build the binaries is used to specify the directory for storing results after Freeglut compilation. Here, I created a freeglut_32 subdirectory under a temp directory, because I want to compile a 32-bit Freeglut in my 64-bit operating system. The reason is further explained below.
Click Configure. A window shown in is displayed.
In the Specify the generator for this project drop-down box, select Visual Studio 12 2013. The Visual Studio Community 2013 downloaded above has a version of 12 and a release date of 2013. The drop-down box also has a similar Visual Studio 12 2013 Win64 option, which can be compiled into a 64-bit Freeglut. As mentioned above, I want a 32-bit instance instead of a 64-bit instance, so I do not select this option.
Click Finish. CMake will perform the first compilation based on the selection. Then, as shown in, temporarily stop compilation for further selection.
FREEGLUT_GLES is compiled for embedded systems. It is not required for the desktop application to be developed. Select both.
Then, click Configure again, and the red background disappears, indicating that the next compilation can be performed. Click Generate. CMake displays Generating done instantly, indicating that the compilation is complete. You can disable the CMake application.
Under C: \ UserData \ Sarkuya \ temp \ freeglut_32, many files are generated, one of which is the freeglut. sln file, which is the Solution file of Visual Studio. Double-click this file to run and load this solution in Visual Studio. There are 27 projects in this solution. Press the F7 key in Visual Studio to compile the entire solution.
After the compilation scheme, not only the files we need are generated, but also some OpenGL applications that can be run directly.
You can select a specific Project in Visual Studio, such as the smooth_opengl3 Project, right-click it, select Set as StartUp Project, Set it as the StartUp Project, and press F5 to run the Project, you can see a colorful triangle.
This triangle also tells us that Freeglut has been compiled and is ready for release. Disable the smooth_opengl3 application and Visual Studio. After watching movies played by others, we have to start self-editing.
Create a 32-bit Freeglut release package
Create a folder named freeglut-3.0.0-msvc-compiled that becomes the root directory of the release package. Next we will create this release package manually.
We downloaded and decompressed the C: \ UserData \ Sarkuya \ Tools \ Programming \ FreeGlut \ freeglut-3.0.0 folder above and copied the subfolders include to the freeglut-3.0.0-msvc-compiled folder.
Create a new lib subfolders under the freeglut-3.0.0-msvc-compiled folder,
Set all three files in the C: \ UserData \ Sarkuya \ temp \ freeglut_32 \ lib \ Debug Folder: freeglut_staticd.lib and freeglutd. exp and freeglutd. lib, all copied to the new lib subfolder.
Create a new bin sub-folder under the freeglut-3.0.0-msvc-compiled folder, find freeglutd in the C: \ UserData \ Sarkuya \ temp \ freeglut_32 \ bin \ Debug folder. dll file, copy it to the new bin sub-folder.
At this point, the folder structure of the freeglut-3.0.0-msvc-compiled is as follows:
freeglut-3.0.0-msvc-compiled --> bin --> freeglutd.dll --> include --> GL --> freeglut.h --> freeglut_ext.h --> freeglut_std.h --> glut.h --> lib --> freeglut_staticd.lib --> freeglutd.exp --> freeglutd.lib
Our 32-bit release package has been created. If necessary, you can package it into a compressed file and put it on the network for others to download and use.
Configure the Freeglut release package to the Visual Studio Environment
The header file directory of the C/C ++ Application of Visual Studio is C: \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ VC \ include. Copy the four header files under the GL directory of the release package to the GL subdirectory below (if there is no GL subdirectory under the include directory of VC, You need to manually create it ).
The library file directory of the C/C ++ Application of Visual Studio is C: \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ VC \ lib. Copy the three files in the lib directory of the release package to the directory.
Copy the freeglutd. dll file under the bin directory of the release package to the C: \ Windows \ SysWOW64 directory. If your operating system is 32-bit, copy it to the C: \ Windows \ System32 directory.
The 64-bit operating system will automatically find freeglutd in the C: \ Windows \ SysWOW64 directory when linking. the 32-bit operating system is automatically located in the C: \ Windows \ System32 directory. Therefore, although my operating system is 64-bit, since the OpenGL application I want to develop is only 32-bit (this is the reason why I made a 32-bit Freeglut release package ), the 32-bit freeglutd should also be added. copy the dll to the C: \ Windows \ SysWOW64 directory.
Developing Freeglut-based OpenGL applications
Now, we need to develop a simple OpenGL application to verify whether our 32-bit Freeglut release package can play a role.
Start Visual Studio, create a Visual C ++ project for Win32 Console Application, and enter the following content in the main. cpp file:
#include <GL/freeglut.h>void display() { glClear(GL_COLOR_BUFFER_BIT); 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) { glutInit(&argc, argv); glutCreateWindow("Freeglut Hello World"); glutDisplayFunc(display); glutMainLoop();}
Press F5 in Visual Studio. After the program runs, the following error occurs:
(Sorry, my OpenGL skill can only show this quadrilateral. That's all! However, if this is the case, you will be able to learn more about OpenGL and check my profile picture in this blog. This is a positive 12-shaped surface that I created using OpenGL more than three years ago. It is rendered after being corrected .)
Don't believe it. We don't need to make more settings in Visual Studio to let the program run. For example, you do not need to set the include directory, because we have copied the corresponding header file to the default include directory of Visual Studio. You do not need to set the library dependency, freeglut has automatically mounted the glu32.lib, opengl32.lib, gdi32.lib, and winmm required by OpenGL in its freeglut_std.h. lib, user32.lib, and freeglutd. dll is copied to the application directory because it has been copied to the default path of the system.
Yes, the exciting OpenGL application should have been so simple!