Introduction to OpenGL
OpenGL is currently used to develop portable, interactive 2D and 3D graphical applications, is also the most widely used computer graphics standard. OpenGL is a set of computer graphics processing systems developed by SGI. It is a software interface of graphics hardware, and GL represents a graphics library (Graphics Library). OpenGL has portability, any OpenGL application does not require consideration of the platform and operating system in which its running environment is located, which produces the same visual effect in any environment that follows OpenGL standards.
OpenGL is not a programming language, but an API (Application Programming Interface, Application Programming Interface). When we say a program is OpenGL or it is an OpenGL program, it means that it is written in some programming languages such as C or C , which calls one or more OpenGL library functions. As an API, OpenGL follows the C language call convention.
OpenGL mainly includes three libraries, which are core libraries, utility libraries, and programmed auxiliary libraries. The core library contains OpenGL's most basic command function. The core library provides more than 100 functions, which are prefixed in "GL" to establish a variety of geometric models, perform coordinate transformation, generating illumination, texture mapping, generating atomization, etc. Two-dimensional and 3D graphics operations. A practical library is a function library than the core library, which provides more than forty functions, which are prefixed in "Glu". Since OpenGL is a graphic standard, it is independent of any window system or operating system, and there is no function to provide window management and message event response in OpenGL, and there is no function of reading events in the mouse and keyboard, so the programming auxiliary library is provided. Some basic window management functions, event handlers, and simple event functions. Such functions are prefixed as "AUX". It is worth mentioning that the current AUX programmed auxiliary library has been largely replaced by the GLUT library. The following introduction takes the GLUT library as an example.
GLUT represents OpenGL Utility Toolkit, is a toolkit that is not related to window system. It is a more functional alternative to the AUX library to hide the complexity of the API of different window system. The prefix of the subroutine of GLUT uses "glut".
First, the following is the process of installing the use of the precompiled translation library with Windows and Visualc .
(1) Copy GULT32.DLL to the Windows System System32
(2) Copy GULT32.LIB to the LIB directory of VC
(3) Copy GULT.H to the VC's include / GL
Second, a simple OpenGL program
#include
#include
// Draw a subroutine
Void Display (void) {
GlclearColor
1.0f
,
1.0F
,
1.0f
,
1.0f
); // Set the window to white when setting the clear window
GLCLEAR (GL_COLOR_BUFFER_BIT); // Execute Window Cleaning
GLFLUSH (); // Refresh the command queue and buffer in OpenGL, so that all commands that have not been executed
}
Void main (int Argc, char ** argv) {
Glutinit (& Argc, Argv); // Initializing the GLUT library
GlutinitDisplayMode (glut_single | glut_rgb); // Display mode
GLUTCREATEWINDOW ("Hello OpenGL!"); // Create a window, the parameter is the title GLUTDISPLAYFUNC (DISPLAY); / / Draw the current window
GLUTMAINLOOP (); // is usually used for the end of the program, indicating that the running program is started. Show all created windows
}