OpenGL installation (Windows)

Source: Internet
Author: User

OpenGL Development Environment Configuration
OpenGL has some reusable auxiliary libraries, such as glut and glew. You need to install them on your own on the Windows platform, because Microsoft only supports OpenGL 1.1 in Windows to promote its DX. You can open \ Microsoft Visual Studio x. x \ Vc \ include \ GL \ Gl. h
Or \ microsoft sdks \ windows \ v6.1 \ include \ GL \ Gl. h file. Check that the default supported OpenGL version is:
/* Version */
# Define gl_version_1_1 1
Now OpenGL has grown to 3.0, so we need to download and configure these libraries by ourselves. Here we will install the glut, Glee, and glew libraries and some OpenGL extension support.
GLUT: Provides window encapsulation. This is a cross-platform window, so we don't have to write tedious window code on our own.
Glee: it is easy to judge whether the current system supports a certain OpenGL feature. We don't have to write the tedious code that gets the function address first and then judges it.
Glew: Windows only supports OpenGL 1.1 by default. To use a later version of OpenGL, you need to install it. It can automatically identify all OpenGL advanced extension functions supported by your platform.
1. Install glut
Glu3.7: http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
Click the link above to download the latest glut. The latest version of glut is 3.7. decompress the package and unzip the glu32.dll and glut. copy the DLL to c: \ windows \ system32 and paste. copy the lib to the lib directory under the VC installation directory (for example, \ Microsoft Visual Studio 9.0 \ Vc \ Lib \) and paste the glut. copy H to the \ include \ GL \ directory under the VC installation directory (for example, \ Microsoft Visual Studio 9.0 \ Vc \ include \ GL ). In the program, we only need
# Include <Gl/Gl. h>
# Include <Gl/Glu. h>
Use
# Include <Gl/glut. h>
You can replace it. Because the glut. h header file already contains these header files and the necessary libraries are imported:
# Pragma comment (Lib, "winmm. lib")/* link with Windows multimedia lib */
# Pragma comment (Lib, "opengl32.lib")/* link with Microsoft OpenGL lib */
# Pragma comment (Lib, "glu32.lib")/* link with OpenGL utility lib */
# Pragma comment (Lib, "glu32.lib")/* link with Win32 glut lib */
2. Install glew
Download link:
Https://sourceforge.net/project/downloading.php group_id1_67586&filename=glew-1.5.1-win32.zip
Click the link above to download the latest glew (OpenGL 3.0 is supported), decompress it, and copy \ bin \ glew32.dll to c: \ windows \ system32, copy \ Lib \ glew32.lib to the lib directory under the VC installation directory (for example, \ Microsoft Visual Studio 9.0 \ Vc \ Lib \) and \ include \ glew. H and \ include \ wglew. copy H to the \ include \ GL \ directory under the VC installation directory (for example, \ Microsoft Visual Studio 9.0 \ Vc \ include \ GL ). In the program, we only need to include GL, Glu
Or before glut. H, you can include glew. H (Note: you must first include glew. h). In the code, add the following sentence:
# Pragma comment (Lib, "glew32.lib ")
Example:
# Include <Gl/glew. h>
# Include <Gl/glut. h>
# Progrma comment (Lib, "glew32.lib ")
After creating the OpenGL rendering context, call glewinit (); initialize glew.
3. install some extension support
Download the three files glext. h, glxext. h, and wglext. h. Place it in the \ include \ GL \ directory under the VC installation directory (for example, \ Microsoft Visual Studio 9.0 \ Vc \ include \ GL ). You can simply include them when using them.

Instance:
// Gl. cpp: defines the entry point for the console application.
//

# Include "stdafx. H"

# Include <Gl/glew. h>
# Pragma comment (Lib, "glew32.lib ")


# Include <Gl/glut. h>
# Pragma comment (Lib, "winmm. lib")/* link with Windows multimedia lib */
# Pragma comment (Lib, "opengl32.lib")/* link with Microsoft OpenGL lib */
# Pragma comment (Lib, "glu32.lib")/* link with OpenGL utility lib */
# Pragma comment (Lib, "glu32.lib")/* link with Win32 glut lib */


# Include <Gl/Glaux. h>
# Pragma comment (Lib, "Glaux. lib ")


Int ipointnum = 0; // Number of vertices that have been determined

Int X1 = 0, X2 = 0, Y1 = 0, y2 = 0; // determined Coordinate

Int winwidth = 400, winheight = 300; // the width and height of the window

 

Void initial (void)

{
 
Glclearcolor (1.0f, 1.0f, 1.0f, 1.0f );
 
}

 

Void changesize (int w, int H)

{
 
Winwidth = W; winheight = h;
 
Glviewport (0, 0, W, H); // specify the display area of the window.
 
Glmatrixmode (gl_projection); // sets the projection parameter.
 
Glloadidentity ();
 
Gluortho2d (0.0, winwidth, 0.0, winheight );
 
}

 

Void display (void)

{
 
Glclear (gl_color_buffer_bit );
 
Glcolor3f (1.0f, 0.0f, 0.0f );
 
If (ipointnum> = 1 ){

Glbegin (gl_lines); // draw a line segment

Glvertex2i (x1, Y1 );

Glvertex2i (X2, Y2 );

Glend ();

}
 
Gluswapbuffers (); // swap Buffer
 
}

 

Void mouseplot (glint button, glint action, glint xmouse, glint ymouse)

{
 
If (Button = maid & Action = maid ){

If (ipointnum = 0 | ipointnum = 2 ){

Ipointnum = 1;

X1 = xmouse; Y1 = winheight-ymouse;

}

Else {

Ipointnum = 2;

X2 = xmouse; y2 = winheight-ymouse;

Glupostredisplay (); // specify the redraw window

}

}
 
If (Button = maid & Action = maid ){

Ipointnum = 0;

Glupostredisplay ();

}
 
}

 

Void passivemousemove (glint xmouse, glint ymouse)

{
 
If (ipointnum = 1 ){

X2 = xmouse;

Y2 = winheight-ymouse;

Glupostredisplay ();

}
 
}

 

Int main (INT argc, char * argv [])

{
 
Gluinit (& argc, argv );
 
Fig; // uses the dual cache and RGB model
 
Gluinitwindowsize (400,300 );
 
Gluinitwindowposition (100,100 );
 
Ngcreatewindow ("rubber band technology ");
 
Gludisplayfunc (Display );
 
Glureshapefunc (changesize); // specifies the callback function of the window in the integer.
 
Glumousefunc (mouseplot); // specifies the mouse response function.
 
Glupassivemotionfunc (passivemousemove); // specifies the response function for moving the mouse
 
Initial ();
 
Glumainloop ();
 
Return 0;
 
}

Void key (unsigned char key, int X, int y)
{
Switch (key ){
Case 'p ':
If (ipointnum = 0 | ipointnum = 2 ){
Ipointnum = 1;
X1 = x; Y1 = winheight-y;
}
Else {
Ipointnum = 2;
X2 = x; y2 = winheight-y;
Glupostredisplay ();
}
Break;
Default: break;
}
}

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.