VS2010
GLUT Download Address:
http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
Glut. H – & gt; C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0 A/Include/gl
glut.dll,glut32.dll —> C:/Windows/ SYSWOW64 (Windows 7 64-bit operating system)
– & gt; C:/Windows/System32 (Windows 7 32-bit operating system)
glut.lib,glut32.lib —> C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib
!!!!! No!!!!! With # define macros GLUT_DISABLE_ATEXIT_HACK
So a lot of people Glut. h didn’t know where to put it, and they created a new folder, and a lot of people Glut. h said,
To search the GL folder, place Glut. h in the GL folder that contains the two files Glut. h and Glut. h.
Direct copy of the following routine compilation can be passed
Routine as follows
#include < gl/glut.h>
Void myDisplay (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glFlush ();
} int main (int arg c, char * argv [])
{
glutInit (& amp; argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition (100, 100);
glutInitWindowSize (400, 400);
GlutCreateWindow (” First OpenGL program “);
glutDisplayFunc (& amp; myDisplay);
glutMainLoop ();
return 0;
}
VS2008
The first step is to choose a compilation environment
now the mainstream of Windows compiled environment have Visual Studio, Broland c + + Builder, Dev – c + +, etc., they are all support OpenGL.
I chose Visual Studio 2008 and VC6++ as the environments to learn OpenGL.
Second, install the GLUT toolkit
Glutters
Glutters
Glutters
Glutters
Glutters
Glutters
Glutters
Glutters
Windows GLUT download address :(size about 150K)
http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
cannot be downloaded from the above address, please use the links below:
http://upload.programfan.com/upfile/200607311626279.zip
install GLUT for Windows:
2, Search for “gl.h” in “My Computer” and find the folder in which it is located
If it is VC++6, then Glut.h should be copied in “D:/Program Files/
MicrosoftVisualStudio/VC98/Include/GL folder “). If it’s VisualStudio2008, copy Glut.h to
X :/Program Files/Microsoft/Visual Studio 9.0/VC/include/GL X is the disk symbol that you use to install VS. If you install VC++, there is a GL file in it. Visual Studio 2008 needs to go to it yourself
Create a new one)
3, let the glut of decompression. Lib and glut32 lib on static libraries in the folder (that is, with the include side by side under the lib folder).
4, let the glut of decompression. DLL and glut32 DLL in the operating system directory under the system32 folder. (Typical location: C:/Windows/System32)
Step 3: Set up an OpenGL project
VisualStudio2008 or VC++6:
choose File – & gt; New-> The Project, and then
Select Win32 Console Application, (not Win32 Application). Select a name and press OK. Click Application Settings on the left side of the resulting dialog box, locate the Empty Project, check it, and select Finish. Then add a code file to the project, called “opengl.c”, and note that you end the file with.c.
is done, just like any other project.
include <
#include < GL/glut.h>
#pragma comment(lib, “opengl32.lib”)
#pragma comment(lib, “glu32.lib”)
#pragma comment(lib, “glut32.lib”)
rst OpenGL program
A simple OpenGL program is as follows:
(Note that if you need to compile and run, GLUT needs to be installed correctly, as described above.)
# include & lt; GL/glut.h>
void myDisplay (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glFlush ();
}
int main(int argc, char *argv[])
{
glutInit (& amp; Arg c, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition (100, 100);
glutInitWindowSize (400, 400);
GlutCreateWindow (” First OpenGL program “);
glutDisplayFunc (& amp; myDisplay);
glutMainLoop ();
return 0;
}
This program draws a white rectangle in the center of a black window. Each of the statements is explained below.
First, you need to include the header file #include
; GL/glut.h> So this is the header file for GLUT.
GL/gl.h> And & lt; GL/glu.h> , but both files are automatically included in the GLUT header file and do not need to be included again.
then look at the main function.
int main(int argc, char *argv[])
int main(int argc, char *argv[]) Comrades who have not seen it, please read the book more, and then look down when you understand.
Notice that all statements in main begin with GLUT, except for the return at the end.
The functions that begin with GLUT are all functions provided by the GLUT toolkit, and the functions used are described below.
1, glutInit (GLUT) — This function must be called once before another GLUT is used. Glutinit (& Arg C, Arg V.
2, glutInitDisplayMode, set the display mode, including GLUT_RGB said using RGB color, and the matching and GLUT_INDEX (using the index color). GLUT_single means to use a single buffer, as does GLUT_DOUBLE (to use a double buffer). For more information, please Google yourself. Of course, there will be some explanations in future tutorials.
>
>
>
>
>
>
>
>
>
>
>
>
5, GlutCreateWindow, create the window based on the information set above. Parameters will be used as the title of the window. Note: The window is not immediately displayed on the screen after it is created. You need to call glutMainLoop to see the window.
6, glutDisplayFunc, set up a function, when the need for drawing, this function will be invoked. (This statement is not accurate, but the accurate statement may not be easy for beginners to understand, so say for the time being).
(This may not be obvious to beginners, but for now it is enough to know that this function displays a window and waits for the window to close before returning.)
in glutDisplayFunc function, we set up “when need drawing, please call myDisplay function”. So myDisplay function is going to be used to draw the graph. When you look at the three function calls in MyDisplay, you see that they all start with GL.
Functions that start with GL are standard OpenGL functions, and the ones we use are described below.
GL_Color_BUFFER_BIT clears the color, and glClear clears other things, but I won’t cover them here.
2, Glrectf, draw a rectangle. The four parameters represent the horizontal and vertical coordinates of the two points located on the diagonal.
3, Glflush, which ensures that previous OpenGL commands are executed immediately (rather than having them wait in the buffer). It works similarly to fflush(stdout).