OpenGL learning notes (1) -- basic usage of OpenGL in Windows

Source: Internet
Author: User

For more information, see http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html.

1. Check whether the graphics card of the Local Machine supports OpenGL. The confirmation method is as follows:

Search for the following two files in the system directory (c: \ windows \ system32 by default for WINXP:

Opengl32.dll and glu32.dll, if any, indicate that your video card has implemented the OpenGL interface.

2. Download the source code package of the glut tool.

OpenGL:

Http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

Http://upload.programfan.com/upfile/200607311626279.zip

3. Installation Method

To install glut in windows, follow these steps:

(1) Unpack the downloaded package and obtain 5 files. They are:

GLUT. dll
GLUT. h
GLUT. Lib
Glu32.dll
Glu32.lib

(2) check whether the local machine has a GL. h file. Specific Method: Search "Gl. H" in "My Computer" and find its folder.

The machine directory I found is: C: \ Program Files \ microsoft sdks \ windows \ v6.0a \ include \ GL.

(3) copy the glut. h file to a suitable directory.

For VC ++ 6, copy glut. H to the vc98/include/GL directory under the vs installation directory.

My machine directory is: D: \ Microsoft Visual Studio \ vc98 \ include

For vs2008, copy glut. H to the VC/include/GL directory under the vs installation directory,

If no GL sub-directory exists, you can create one by yourself.

The directory on my machine is:

D: \ Microsoft Visual Studio 9.0 \ Vc \ include \ GL

(4) Put the extracted glut. lib and glu32.lib In the Lib subdirectory with VC.

My machine directory is:

D: \ Microsoft Visual Studio \ vc98 \ Lib (vc6)

D: \ Microsoft Visual Studio 9.0 \ Vc \ Lib (vs2008)

(5) Put the extracted glut. dll and glu32.dll In the System32 folder under the operating system directory. (Typical location: C:/Windows/system32)

4. Create the first OpenGL program

(1) Create an empty console Program

Whether visualstudio2008 or VC ++ 6:
Select File-> New-> project, and then select Win32 console application. The project name can be helloopengl.
Then press OK. Click application settings on the left of the displayed dialog box, locate the empty project, and click Finish.

(2) write code
Add a code file to the helloopengl project named "MAIP. cpp ",

The content is as follows:

#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);    glutCreateWindow("opengl");    glutDisplayFunc(&myDisplay);    glutMainLoop();    return 0;}

Press F7 to compile the window, and then run it to see the effect: A window appears on the screen, with a white rectangle in the center of the window. As shown in:

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.