VC + + 6.0 OPENGGL configuration and Glut configuration

Source: Internet
Author: User

Transferred from: http://blog.sina.com.cn/s/blog_5f0cf7bd0100c9oa.html

OpenGL official website (US site)

http://www.opengl.org

Below I willWindows under theOpenGL programming for a brief introduction.

First step: Select a compilation environment

Right nowThe mainstream compilation environment for Windows systems hasVisual Studio,Broland C + + Builder,Dev-c++ and so on, they are all supportedOpenGL's. But here we chooseVC + + 6.0 as a learningOpenGL's environment.

Step Two: InstallGLUT Tool Kit

Glut notOpenGL is necessary, but it will give us a certain convenience of learning, recommended installation.

In the Windows environmentGLUT: (size approx.150k)
Http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

If you cannot download from the above address, please use the following connection:
Http://upload.programfan.com/upfile/200607311626279.zip

Installation in Windows environmentSteps to GLUT:
1. Unpack the downloaded package, and you will get5 files
2, take my installation directory as an example:
(1) "D:\Program Files\Microsoft The Visual Studio\vc98\include\gl folder. Get the extract.Glut.h put it in this.In the GL folder. NoThe GL folder can be built on its own, which is common.
(2) "D:\Program Files\Microsoft The Visual Studio\vc98\lib folder. Get the extract.Glut.lib andGlut32.lib is placed in the folder where the static function library is located,Lib folder.
(3) Get the extractedGlut.dll andGlut32.dll to the operating system directory.In the System32 folder. (The typical location is:C:\Windows\System32) This is very important for dynamic link library settings!

The third step is to create the project with the following steps:

(1) Create aWin32 Console Application. (In the example I created, the project is namedSIMPLEGL)
(2) LinksOpenGL libraries: InIn Visual C + +, first clickProject, and then clickSettings, find it again.Link click, and finally inObject/library Modules the front PlusOpengl32.lib Glut32.lib Glaux.lib glu32.lib.
(3) ClickIn Project settingsA/C + + label,Preprocessor definitions in the_console instead__windows. Last ClickOk.

Now, the preparation is basically complete, do not underestimate this step, if you are not set up in the process of compiling and running will always be wrong.

ForVS2005 can be set as follows:
1, theGlut.h Copy ToVC installation path under thePlatformsdk\include\gl folder
2, theGlut32.lib Copy ToVC installation path under thePlatformsdk\lib folder
3, theGlut32.dll Copy ToWindows\System32 folder
4, in  vc  to create a console application, in the options to clear "Using Precompiled Headers" (to avoid portability)
5,  vc   Open Project -> Properties dialog box with the following settings:
          Select the Configuration drop-down box to all configurations
          OPEN linker --input "entry
         added in "Additional Dependencies":
        opengl32.lib
         glu32.lib
         Glut32.lib

Fourth Step, create the simplest opengl program

#include <GL/glut.h>

void Mydisplay (void)
{
Glclear (Gl_color_buffer_bit);
GLRECTF ( -0.5f, -0.5f, 0.5f, 0.5f);
Glflush ();
}

int main (int argc, char *argv[])
{
Glutinit (&ARGC, argv);
Glutinitdisplaymode (Glut_rgb | Glut_single);
Glutinitwindowposition (100, 100);
Glutinitwindowsize (400, 400);
Glutcreatewindow ("First OpenGL program ");
Glutdisplayfunc (&mydisplay);
Glutmainloop ();
return 0;
}
The function of the program is to draw a white rectangle in the center of a black window. Each line statement is described below.

First, you need to include the header file#include <gl/glut.h>Glut's header file.
WasOpenGL programs generally also include<GL/gl.h> and<gl/glu.h>These two files have been automatically included in the glut header file and do not have to be included again.

and seeThe main function.
int main (int argc, char *argv[]), this is a command-line argumentThe main function, you should have seen it? Comrades who have not seen please turn over the book, and so on to understand and then look down.
AttentionEach statement in the main function, except for the lastReturn, all the rest isGlut begins. Such aThe functions that begin with GLUT areThe functions provided by the GLUT Toolkit are described below for several functions that are used.
1.Glutinit, yes.Glut is initialized, this function must be in the otherGlut is called once before use. Its format is more rigid, generally copy this sentenceGlutinit (&AMP;ARGC, argv) can do it.
2.Glutinitdisplaymode, set the display mode, whereGlut_rgb represents the use ofRGB color, corresponding to theGlut_index (indicates the use of indexed colors).Glut_single indicates that a single buffer is used, and the correspondingGlut_double (using double buffering). For more information, pleaseGoogle. Of course, later tutorials will also have some explanation.
3.Glutinitwindowposition, this simple, sets the position of the window in the screen.
4.Glutinitwindowsize, this is also simple, set the size of the window.
5.Glutcreatewindow, creates a window based on the information previously set. The parameter is used as the caption of the window. Note: When the window is created, it is not immediately displayed to the screen. Need to callGlutmainloop to see the window.
6.Glutdisplayfunc, set a function that will be called when a drawing is required. (This statement is not accurate enough, but the exact statement may not be very good for beginners to understand, for the time being said).
7.Glutmainloop, make a message loop. (This may not be easy for beginners to understand, but it's enough to know that the function can show the window and wait for the window to close before it returns.) )

InIn the Glutdisplayfunc function, we set the "when drawing is required, callmydisplay functions. So mydisplay function is used to draw. Observe the three function calls in  mydisplay, and find that they all start with gl. This function, which begins with GL, is the standard function of opengl, and the functions used are described below.
1, glclear, clear. gl_color_buffer_bit means clear color, The Glclear function can also erase other things, but this is not an introduction.
2, glrectf, draw a rectangle. The four parameters represent the horizontal and vertical coordinates of two points located on the diagonal.
3, glflush, guaranteeing the front opengl command executes immediately (instead of letting them wait in the buffer). Its effect is similar to fflush (stdout).

OpenGL source program, run on prompt, "computer lost Glut32.dll file"

Workaround: http://www.cnblogs.com/x_wukong/p/4194355.html

VC + + 6.0 OPENGGL configuration and Glut configuration

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.