Notes Installing OpenGL environments for MinGW under Windows (GLUT)

Source: Internet
Author: User
Tags strcmp

OpenGL is only a standard, its implementation is generally brought in the operating system, just make sure that the graphics card driver is new enough to use. If you need to use OpenGL directly in your program, there are a lot of very nasty preparations to do. To skip these jobs, you can use a utility library, the new point has glew, because open source so the installation is relatively convenient (big deal to throw in together compile), but the various tutorials and books are common in the closed source of glut (very old library embarrassed), installation is relatively troublesome, especially under Windows, Toss a little half a day to take care of, so here record.

1. Download GLUT

Address: https://user.xmission.com/~nate/glut.html, download glut-3.7.6-bin.zip (has not been updated in more than 10 years, so this is the version of 2333)

2. Placing the header and library files

Unzip the downloaded zip, which is the relevant header files and library files. Because Glut.dll is 32-bit, the 64-bit system is decentralized in the c:\windows\syswow64,32-bit system under C:\WINDOWS\SYSTEM32. In addition, the system can be placed directly in the C:\Windows.

Glut.h put it in mingw/include/gl,glut32.lib and put it in mingw/lib.

For example, a 64-bit system MinGW installed in the D:/MINGW, after the release is probably the case:

C:\Windows\SysWOW64    └─glut.dlld:\mingw    ├─include    │   └─gl    │      └─glut.h    └─lib        └─ Glut32.lib

General operating system will bring Glu32.dll, MinGW in the installation will bring some header files in Include/gl,lib also have OpenGL and Glu library files, see no need to be strange.

If you are familiar with your own tools and prefer to specify library files and header file locations when compiling connections, this step can be skipped and placed where you feel fit, as long as you declare the path in the project/makefile.

3. Configuration parameters

Compile parameter plus -DGLUT_DISABLE_ATEXIT_HACK (can also be in code #define GLUT_DISABLE_ATEXIT_HACK ), link parameter plus-lopengl32 -lglu32 -lglut32

The MinGW itself is 32 bits, so no special settings are required. If the mingw-w64 is used, the parameters must be added-m32

4. Use the header file in the code

The following two header files need to be referenced before using the GLUT function

#include <windows.h><GL/glut.h>

The order cannot be reversed. General tutorials or sample code if not for the Win32 platform will not have #include <windows.h> , a lot of things are not found in the definition, so run to check.

Example

A simple Makefile, if you use the IDE with MinGW, just remember to configure the parameters of Step 3 in it (typically in the options such as project or build).

Ldflags=-lopengl32-lglu32-lglut32cflags=-g-ddebug-dglut_disable_atexit_hackall:    g++ main.cpp-c-o main.o $ ( CFLAGS)     g++ MAIN.O $ (ldflags)-O Main.execlean:    rm main.o Main.exe

Program main.cpp , from OpenGL Code Samples, plus windows.h:

#include <stdio.h>#include<stdlib.h>#include<string.h>#include<windows.h>#include<GL/glut.h>Glenum DoubleBuffer; Glint Thing1, thing2;Static voidInit (void) {Glclearcolor (0.0,0.0,0.0,0.0); Glclearaccum (0.0,0.0,0.0,0.0); Thing1= Glgenlists (1);    Glnewlist (Thing1, gl_compile); glcolor3f (1.0,0.0,0.0); GLRECTF (-1.0, -1.0,1.0,0.0);    Glendlist (); Thing2= Glgenlists (1);    Glnewlist (Thing2, gl_compile); glcolor3f (0.0,1.0,0.0); GLRECTF (0.0, -1.0,1.0,1.0); Glendlist ();}Static voidReshape (intWidthintheight) {Glviewport (0,0, width, height);    Glmatrixmode (gl_projection);    Glloadidentity ();    Glmatrixmode (Gl_modelview); Glloadidentity ();}Static voidKey (unsignedCharKeyintXinty) {    Switch(key) { Case '1': Glpolygonmode (Gl_front_and_back, Gl_fill);    Glutpostredisplay ();  Break;  Case '2': Glpolygonmode (Gl_front_and_back, gl_line);    Glutpostredisplay ();  Break;  Case  -: Exit (0); }}Static voidDraw (void) {Glpushmatrix (); Glscalef (0.8,0.8,1.0);    Glclear (Gl_color_buffer_bit);    Glcalllist (THING1); Glaccum (Gl_load,0.5);    Glclear (Gl_color_buffer_bit);    Glcalllist (THING2); Glaccum (Gl_accum,0.5); Glaccum (Gl_return,1.0);    Glpopmatrix (); if(DoubleBuffer) {glutswapbuffers (); } Else{Glflush (); }}Static voidArgs (intargcChar**argv)    {Glint I; DoubleBuffer=Gl_false;  for(i =1; i < argc; i++) {    if(strcmp (Argv[i),"-SB") ==0) {DoubleBuffer=Gl_false; } Else if(strcmp (Argv[i),"-db") ==0) {DoubleBuffer=gl_true; }    }}intMainintargcChar**argv)    {Glenum type; Glutinit (&argc, argv);    Args (argc, argv); Type= Glut_rgb |Glut_accum; Type|= (DoubleBuffer)?Glut_double:glut_single;    Glutinitdisplaymode (type); Glutinitwindowsize ( -, -); Glutcreatewindow ("Accum Test");    Init ();    Glutreshapefunc (reshape);    Glutkeyboardfunc (Key);    Glutdisplayfunc (Draw); Glutmainloop ();}
Run results

Notes Installing OpenGL environments for MinGW under Windows (GLUT)

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.