WHAT IS OPENGL? OpenGl is an API similar to direct3D. However, OpenGL (Open Graphics Library) is not supported by Microsoft and is a cross-language, cross-platform API used for writing applications that produce 2d or 3D graphics. Over 300 functions are implemented in this API which can help you draw complex 3D scenes from primitive data such as polygons and triangles. Mesa 3D is an open source library API which is also compatible with the OpenGl protocol. OpenGl aims at two key goals: - To present to the programmer a uniform API that hides the complexities of interfacing with different 3D accelerators.
- To hide the different capabilities of hardware platforms.
OpenGL converts primitives into pixels that are depicted on your screen. Primitives can be polygons, triangles or lines. The transformation is accomplished by a graphics pipeline.
OPENGL BASICS As mentioned, OpenGL is a library for rendering computer graphics. Generally, there are two operations that you do with OpenGL: • draw something • change the state of how OpenGL draws OpenGL has two types of things that it can render: geometric primitives and image primitives. Geometric primitives are points, lines and polygons. Image primitives are bitmaps and graphics images (i.e. the pixels that you might extract from a JPEG image after you’ve read it into your program). Additionally, OpenGL links image and geometric primitives together using texture mapping, which is an advanced topic. The other common operation that you do with OpenGL is setting state. “Setting state” is the process of initializing the internal data that OpenGL uses to render your primitives. It can be as simple as setting up the size of points and colour that you want a vertex to be, to initializing multiple mipmap levels for texture mapping. A typical OpenGL procedure is the following: 1) Choose the type of window that you need for your application and initialize it. 2) Initialize any OpenGL state that you don’t need to change every frame of your program. This might include things like the background color, light positions and texture maps. 3) Register the callback functions that you’ll need. Callbacks are routines you write that GLUT (OpenGl implementation) calls when a certain sequence of events occurs, like the Window needing to be refreshed or the user moving the mouse. The most important callback function is the one to render your scene. 4) Enter the main event processing loop. This is where your application receives events, and schedules when callback functions are called. CALLBACKS GLUT uses a callback mechanism to do its event processing. Callbacks simplify event processing for the application developer. As compared to more traditional event driven programming, where the author must receive and process each event, and call whatever actions are necessary, callbacks simplify the process by defining what actions are supported, and automatically handling the user events. All the author must do is fill in what should happen when. GLUT supports many different callback actions, including: • glutDisplayFunc() - called when pixels in the window need to be refreshed. • glutReshapeFunc() - called when the window changes size • glutKeyboardFunc() - called when a key is struck on the keyboard • glutMouseFunc() - called when the user presses a mouse button on the mouse • glutMotionFunc() - called when the user moves the mouse while a mouse button is pressed • glutPassiveMouseFunc() - called when the mouse is moved regardless of mouse button state • glutIdleFunc() - a callback function called when nothing else is going on. Very useful for animations.
Trackback(0)
 |