OpenGL Development Environment configuration in VC ++ 6.0

Source: Internet
Author: User

 


OpenGL official website (English)
Http://www.opengl.org

Next I will give a brief introduction to OpenGL programming in windows.

Step 1: select a compiling environment

Currently, mainstream windows compiling environments include Visual Studio, broland C ++ builder, Dev-C ++, and so on. They all support OpenGL. But here we choose VC ++ 6.0 as the learning OpenGL environment.

Step 2: Install the glut Toolkit

Glut is not required by OpenGL, but it will bring some convenience to our learning. We recommend that you install it.

Glut in Windows: (the size is about 150 K)
Http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

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

To install glut in Windows:
1. Unpack the downloaded package and obtain 5 files.
2. Take my installation directory as an example:
(1) "D:/program files/Microsoft Visual Studio/vc98/include/GL folder ". Put the extracted glut. h In this gl folder. You can create one by yourself without the GL folder.
(2) "D:/program files/Microsoft Visual Studio/vc98/lib folder ". Put the extracted glut. lib and glu32.lib in the folder where the static function library is located, that is, the Lib folder.
(3) Place the extracted glut. dll and glu32.dll In the System32 folder under the operating system directory. (Typical location: C:/Windows/system32) This is an important dynamic link library setting!

Step 3: Create a project as follows:

(1) create a Win32 console application. (For example, the project name is simplegl)
(2) link OpenGL libraries: click Project in Visual C ++, click Settings, find link, and add opengl32.lib glu32.lib Glaux at the beginning of Object/library modules. lib glu32.lib. (The special note here is that it is glu32.lib instead of GLUT. Lib)
(3) Click the C/C ++ label in Project Settings and change _ console in Preprocessor definitions to _ windows. Click OK.

Now, the preparation work is almost complete. Do not underestimate this step. If you do not set it, errors will always occur during compilation and running.

You can set vs2005 as follows:
1. Copy glut. H to the platformsdk/include/GL folder under the VC installation path.
2. Copy glu32.lib to the platformsdk/lib folder in the VC installation path.
3. Copy glu32.dll to the Windows/system32 folder.
4. Create a console application in VC and clear "use precompiled header" in options to avoid affecting portability)
5. Open the project> Properties dialog box in VC and set it as follows:
Select "All configurations" from the "configuration" drop-down box"
Open the "linker -- input" item
Add:
Opengl32.lib
Glu32.lib
Glu32.lib

Step 4: 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 [])
{
Gluinit (& argc, argv );
Fig );
Gluinitwindowposition (100,100 );
Gluinitwindowsize (400,400 );
Valley createwindow ("first OpenGL program ");
Gludisplayfunc (& mydisplay );
Glumainloop ();
Return 0;
}

The function of this program is to draw a White Rectangle in the center of a black window. Each row of statements is described below.

First, you need to include the header file # include <Gl/glut. h>, which is the header file of glut.
Originally, OpenGL programs generally contain <Gl/Gl. h> and <Gl/Glu. h>, but the glut header file automatically contains these two files and does not need to be included again.

Then look at the main function.
Int main (INT argc, char * argv []). This is a main function with command line parameters. Have you ever seen it? If you have never seen any other comrades, please read more books and wait until you understand them.
Note that all the statements in the main function, except the last return, start with glut. The functions starting with glut are all functions provided by the glut toolkit. The following describes several functions used.
1. gluinit: Initialize the glut. This function must be called once before other gluts are used. The format is relatively rigid. You can copy this keyword according to the format of gluinit (& argc, argv.
2. Set the display mode of the glutinitdisplaymode. In the display mode, the ng_rgb color indicates that the RGB color is used, and the corresponding value is the ng_index (indicating that the index color is used ). Glu_single indicates that a single buffer is used, and the corresponding value is glu_double (dual buffering is used ). For more information, Google. Of course, there will be some explanations in future tutorials.
3. Set the position of the window on the screen.
4. It is also simple to set the window size.
5. Create a window based on the information set above. The parameter is used as the title of the window. Note: The window is not displayed on the screen immediately after it is created. You need to call the glumainloop function to view the window.
6. Set a function to map a graph. The function is called. (This statement is not accurate enough, but it may be difficult for beginners to understand it. Let's talk about it for the time being ).
7. A message loop is implemented using the glumainloop. (This may not be quite understandable for beginners. Now you only need to know that this function can display a window and will return it only after the window is closed .)

In the gludisplayfunc function, we set "Call the mydisplay function when drawing is required ". The mydisplay function is used for drawing. Observe the three function calls in mydisplay and find that they all start with GL. These functions starting with GL are all OpenGL standard functions, which are described below.
1. glclear: Clear. Gl_color_buffer_bit indicates to clear the color. The glclear function can also clear other things, but it is not described here.
2. glrectf: Draw a rectangle. The four parameters represent the horizontal and vertical coordinates of the two points on the diagonal line.
3. glflush: ensure that the previous OpenGL commands are executed immediately (instead of waiting them in the buffer ). Its role is similar to that of fflush (stdout.

 

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.