Freeglut Windows programming on NetBeans

Source: Internet
Author: User
Tags netbeans

There are many inconveniences in using Freeglut to develop OpenGL applications under Windows:

    • OpenGL in Windows Cygwin is implemented in two ways. One is the WIN32API approach, but this approach does not support Freeglut. Another way to support Freeglut, but only for the X Windows System.
    • Freeglut official version can not be used directly, the need for a relatively complex compilation before the use.
    • MinGW down there is a direct implementation of the way. But not directly applicable to Cygwin.
    • NetBeans has a JOGL plugin, but it is only available in the Java language, but it loses the efficiency of C + +.

Using Cygwin instead of MinGW, and in favor of NetBeans rather than visual Studio, the author has studied and found a way to develop OpenGL applications using Freeglut in Cygwin-based NetBeans.

Installing OpenGL and WIN32API components for Cygwin

After installing OpenGL and WIN32API components through Cygwin, gl.h, glaux.h, Glew.h, Glu.h will appear under the %cygwinroot%\usr\include\win32api\gl path, Wglew.h and so on several files, of course, not yet freeglut.h header file.

Download and configure Freeglut

Transmission Zero maintains the MSVC and MinGW two versions of Freeglut. The MSVC version is designed specifically for Microsoft Visual Studio, and we download its MinGW version.

To avoid a mix of freeglut and Cygwin components that we download ourselves, you can create a new directory, such as C:\freeglut. Then, copy the Include and Lib two folders from the Freeglut-mingw.zip compressed file into the directory. There is a 32-bit and 64-bit Freeglut.dll file under the Bin folder. Copy it to the appropriate location, depending on whether the operating system is 32-bit or 64-bit. For 32-bit Windows, copy the Bin\freeglut.dll to C:\windows\system32. For 64-bit Windows, copy the Bin\x64\freeglut.dll to C:\Windows\SysWOW64.

Then, make sure that C:\windows\system32 or C:\Windows\SysWOW64 already appear in the system's environment variables.

Configuring Freeglut in NetBeans

To create a new C + + application in NetBeans, enter the following code in MAIN.CPP:

/ * * File:main.cpp * Author:sarkuya * * Created on April 13, 2015, PM 23:13 */#include <GL/freeglut.h>voidDisplay () {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 ();}intMainintargcChar* * argv) {glutinit (&AMP;ARGC, argv); Glutcreatewindow ("Freeglut Demo");    Glutdisplayfunc (display); Glutmainloop ();}

In the two OpenGL implementations of Cygwin, we will use the WIN32API approach.

Click on the NetBeans Menu Tool---options, select C + + in the popup window, code help->c++ the compiler's inclusion directory, based on the last four lines set:

In the last four rows, C:\cygwin64\usr\include\w32api and C:\cygwin64\include\w32api must first appear before C:\cygwin64\usr\include, so that It ensures that we prioritize the implementation of WIN32API. The penultimate line adds the Freeglut's include directory that we manually set up, and NetBeans automatically looks for the file in this directory when we include "Gl/freeglut.h" in the code.

The advantage of setting Freeglut's inclusion directory in the NetBeans environment rather than the specific project properties is that you can write the GLUT statement directly in the code by creating a new OpenGL application in NetBeans.

Right-click the item in NetBeans, click Properties, and set the link properties in the popup window:

, the other library directories are selected%freeglutroot%\lib\x64, which tells the directory where the Netbeans,freeglut library resides. There are four options that need to be set in the other options for compiling a row. The first three are OpenGL-related, which means you need to use Freeglut, GLU32, opengl32 Three libraries for the link. The fourth option, "-wl,–subsystem,windows", is a unique option under Windows, which means that the app will run in a window rather than a command-line way.

The above configuration produces the following command line that g++ uses when linking:

g++-o dist/Debug/Cygwin_4.x-Windows/opengltest build/Debug/Cygwin_4.x-Windows/main.-L../../../..-lfreeglut-lglu32-lopengl32-Wl,--subsystem,windows

The two-phase combination allows for easier understanding of NetBeans configuration principles.

Run the App

Running this application, the Classic OpenGL application window will appear:

Conclusion

Although this is already an outdated programming method for shading language, the purpose of this article is to emphasize OpenGL application development in a specific environment. Understanding this principle can help us learn more about OpenGL programming in a convenient way.

Freeglut Windows programming on NetBeans

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.