Tailor-made for Visual Studio Freeglut

Source: Internet
Author: User

Programmers who use Microsoft's Visual Studio to develop applications under Windows are common. Configuring Freeglut under Visual Studio is mostly done by downloading the binaries that have already been compiled for a specific version of Visual Studio online. However, there are many versions of Visual Studio, so these directly downloaded files are not necessarily suitable for our own use of Visual Studio. As a platform-wide OpenGL development tool, Freeglut has fully taken into account the configuration installation requirements under various platforms, but it does not directly provide the binary form that can be used, instead, it only provides the source code, the programmer according to their respective platform for the corresponding compilation, You can get the right version for yourself. But this process is relatively cumbersome, resulting in many programmers do not know where to start.

This article details how to compile and configure Freeglut for free visual Studio Community 2013, and finally develop and run one of the simplest OpenGL applications.

Download and install the free visual Studio Community 2013

Download the Vs_ommunity.exe here. It is best to use IE to open the above address, other browsers may be able to access the Web page, but not open. This is an online installer with a size of only 1.18M. You can also access this page to choose to download a DVD9 ISO image file of size 6.89G. Both forms of the file, I have tried, ISO image file can be installed on the 32-bit Win7 above, but on 64-bit Win7, it seems to be unable to install, if you encounter this problem, you can choose the online installation program.

Download and install ... This is a lengthy process, especially for online installations. I started the online installation before work, after work, ha, automatic installation is complete.

You can also install the Simplified Chinese Language pack if you want.

Download Freeglut

Download Freeglut to the Freeglut website and unzip it to a folder, such as C:\freeglut. There are two important folders under the directory, one is include, the header file of C, and the other is SRC, which contains the source code we are going to compile.

Compiling Freeglut

Go to cmake.org to download a cmake that can be installed directly on Windows and double-click the file to install it.

After installation, run CMake and follow the settings.

Where is the source code to specify the directory of the Freeglut we unzipped, which has a SRC subdirectory. The Where to build the binaries is used to specify the directory in which the results are stored freeglut compiled. Here, I built a freeglut_32 subdirectory under a temp directory because I wanted to compile a 32-bit freeglut on my 64-bit operating system. Further explanations are given below for reasons.

Click the Configure button. A window will pop up as shown.

Select Visual Studio 12 2013 in the drop-down box specify the generator for this project. The visual Studio Community 2013 We downloaded above has a version number of 12 and the release time should be 2013. The drop-down box also has an option for the closer visual Studio Win64, which compiles to a 64-bit freeglut. As mentioned earlier, I want a 32-bit instead of 64-bit, so this option is not selected.

Click the Finish button. CMake will compile the first pass based on the selection. Then, as shown, temporarily stop compiling so that we can make further choices.

The Freeglut_gles is compiled for the embedded system, not the desktop application we intend to develop, so we do not choose. All of them are selected.

Then, click Configure again, the red background disappears, indicating that the next compilation can be done. Then click the Generate button, CMake instantaneous display generating done, indicating that the compilation is complete. You can turn off the CMake app at this time.

At this point, under C:\UserData\Sarkuya\temp\freeglut_32, many files will be generated, one of which is the Freeglut.sln file, which is the solution file for Visual Studio. Double-click the file, and Visual Studio runs and loads this scenario. There are a total of 27 projects under this scenario. Press the F7 key in Visual Studio to compile the entire scenario.

After compiling the scheme, not only did we have the files we needed, but we also had some OpenGL applications that could run directly.

We can select specific items in Visual Studio, such as the SMOOTH_OPENGL3 project, right-click, select Set as Startup Project, set it as the startup item, press F5 to run the project, and a fascinating colorful triangle can appear.

This triangle also tells us that Freeglut has been compiled and ready to prepare. Close the Smooth_opengl3 app, as well as visual Studio. After watching other people's films, we also have to start self-directed.

Make a 32-bit Freeglut release package

Create a new folder named Freeglut-3.0.0-msvc-compiled, which will be the root directory for the release package. Below we make this release package by hand.

We downloaded and unzipped the C:\UserData\Sarkuya\Tools\Programming\FreeGlut\ freeglut-3.0.0 folder, copy the subfolders include into the freeglut-3.0.0-msvc-compiled folder.

Create a new Lib subfolder under the Freeglut-3.0.0-msvc-compiled folder,
Place all three files under the C:\UserData\Sarkuya\temp\freeglut_32\lib\Debug folder: Freeglut_staticd.lib, Freeglutd.exp and Freeglutd.lib, all copied to the new Lib subfolder.

Create a new Bin subfolder under the Freeglut-3.0.0-msvc-compiled folder, in the C:\UserData\Sarkuya\temp\freeglut_32\bin\Debug folder, Locate the Freeglutd.dll file and copy it to the new Bin subfolder.

At this point, the freeglut-3.0.0-msvc-compiled folder is structured as follows:

  --> 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 is finished. If you need to, you can package it as a compressed file and put it on the web for others to download and use.

To configure the Freeglut release package to a Visual Studio environment

The header file directory for Visual Studio's C + + app is C:\Program files (x86) \microsoft Visual Studio 12.0\vc\include. Copy the four header files in the release package GL directory to the following GL subdirectory (if you do not have a GL subdirectory under the Include directory for the VC, you will need to create it manually).

The library file directory for Visual Studio's C/s + + app is C:\Program files (x86) \microsoft Visual Studio 12.0\vc\lib. Copy the three files under the Lib directory of the release package to it.

Copy the Freeglutd.dll file from the release package bin directory to the C:\Windows\SysWOW64 directory. If your operating system is 32-bit, you need to copy it to the C:\Windows\System32 directory.

64-bit operating systems will automatically look for Freeglutd.dll in the C:\Windows\SysWOW64 directory when linking, while 32-bit operating systems are automatically found in the C:\Windows\System32 directory. So, while my operating system is 64-bit, because I am developing an OpenGL application that is only 32 bits (which is why this article makes 32-bit Freeglut release packages), you should also copy this 32-bit freeglutd.dll to C:\Windows\ The SysWOW64 directory.

Development of Freeglut-based OpenGL applications

Now, we're going to develop a simple OpenGL application to verify that our 32-bit Freeglut release package works.

Start Visual Studio, create a new Visual C + + project for Win32 Console application, and enter the following in the Main.cpp file:

#include <GL/freeglut.h> void display() {
        glVertex2f(-0.5, -0.5);
        glVertex2f(-0.5, 0.5);
        glVertex2f( 0.5, 0.5);
        glVertex2f( 0.5, -0.5);
} int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutCreateWindow("Freeglut Hello World");

When you press the F5 key in Visual Studio, the program runs, and then it appears:

(I'm ashamed that my OpenGL skill only allows this quadrilateral to appear, that's all!) But if it strikes you to learn more about OpenGL's confidence, look at my avatar in this blog. This is the result of a positive 12 polygon that I made with OpenGL about three years ago and put it right behind. )

Don't believe it, we don't need to do more setup in Visual Studio to get this program running. For example, you do not need to set up the include directory because we have copied the corresponding header file to the default include directory in Visual Studio, and you do not need to set the library dependency because Freeglut is already in its freeglut_ The Glu32.lib, Opengl32.lib, Gdi32.lib, Winmm.lib, required for OpenGL applications are automatically hung up in Std.h, User32.lib the five libraries, and you don't need to copy the Freeglutd.dll to the app directory because we've copied it to the system's default path.

Yes, the hot-blooded OpenGL app was supposed to be so simple!

Tailor-made for Visual Studio Freeglut

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.