You are on page 1of 8

An Introduction to OpenGL

Submitted in Graphics Programming Lab (2D and 3D Programming at a glance)

Contents : 1. Basis of OpenGl

3. OpenGl v 4.1 4. OpenGl Registry

___________________________Page 2

2. Purpose of OpenGl ___________________________Page 2 & 3 ____________________________Page 3 & 4 ____________________________Page 4 & 5

5. Enumerant and Function Registry ________________Page 5 & 6 6 . Example ____________________________Page 7

7. Associated utility libraries ______________________Page 8 8. Higher level functionality _______________________Page 8

Submitted By:Name - Ved Prakash Singh Roll No. - 08100EN034 Class - B.Tech.,Part-3, CSE. IT_BHU, Varanasi.

Date 30th July, 2010.


OpenGl as Beginning :

OpenGL (Open Graphics Library) is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL was developed by Silicon Graphics Inc. (SGI) and is widely used in CAD, virtual reality, scientific visualization, information visualization, and flight simulation. It is also used in video games, where it competes with Direct3D on Microsoft Windows platforms (see OpenGL vs. Direct3D). OpenGL is managed by a non-profit technology consortium, the Khronos Group.

OpenGL serves two main purposes :

1. Hide complexities of interfacing with different 3D accelerators by presenting a single, uniform interface 2. Hide differing capabilities of hardware platforms by requiring support of full OpenGL feature set for all implementations (using software emulation if necessary).

OpenGL has historically been influential on the development of 3D accelerators, promoting a base level of functionality that is now common in consumer-level hardware :

Rasterised points, lines and polygons as basic primitives. A transform and lighting pipeline Z-buffering Texture mapping Alpha blending

OpenGL is a low-level, procedural API, requiring the programmer to dictate the exact steps required to render a scene. This contrasts with descriptive (aka scene graph or retained mode) APIs, where a programmer only needs to describe a scene and can let the library manage the details of rendering it. OpenGL's low-level design requires programmers to have a good knowledge of the graphics pipeline, but also gives a certain amount of freedom to implement novel rendering algorithms.

High Performance Graphics by OpenGl v 4.1 :

OpenGL 4.1 at a glance :OpenGL 4.1 improves OpenCL interoperability for accelerating computationally intensive visual applications and continues support for both the Core and Compatibility profiles first introduced with OpenGL 3.2, enabling developers to use a streamlined API or retain backwards compatibility for existing OpenGL code, depending on their market needs.

New features of OpenGL 4.1 include :

Full compatibility with OpenGL ES 2.0 APIs for easier porting between mobile and desktop platforms The ability to query and load a binary for shader program objects to save recompilation time The capability to bind programs individually to programmable stages for programming flexibility 64-bit floating-point component vertex shader inputs for higher geometric precision Multiple viewports for a rendering surface for increased rendering flexibility

New ARB extensions introduced with OpenGL 4.1 include :

Linking OpenGL sync objects to OpenCL event objects for enhanced OpenCL interoperability The ability to set stencil values in a fragment shader for enhanced rendering flexibility Features to improve robustness, for example when running WebGL applications Callback mechanisms to receive enhanced errors and warning messages.

API & GLSL specifications of version 4.1 :

OpenGL 4.1 Core Profile Specification OpenGL 4.1 Compatibility Profile Specification OpenGL Shading Language 4.10.6 Specification

New ARB extensions of version 4.1 :

GL_ARB_cl_event GL_ARB_debug_output GL_ARB_robustness GL_ARB_shader_stencil_export GLX_ARB_create_context_robustness WGL_ARB_create_context_robustness

OpenGL Registry

The OpenGL Registry contains specifications, header files, and related documentation for OpenGL and related APIs including GLU, GLX, and WGL. In addition to the core API specifications, many extensions to these APIs have been defined by vendors, groups of vendors, and the ARB. The Registry also contains specifications and header files for all registered extensions, written as modifications to the appropriate core API specifications.

The Registry also includes naming conventions, guidelines for creating new extensions and writing suitable extension specifications, and other documentation related to these APIs.

Adding to the Registry and Requesting Enumerant Allocations

If we want to add an extension specification to the Registry, correct an existing specification, request allocation of enumerants and other controlled resources in the OpenGL / GLX / WGL namespaces, or otherwise change the Registry, please create a Bugzilla account on the public Bugzilla, and submit your request there against Product "OpenGL", Component "Registry". You can use this Bugzilla link, which fills in many fields for us.

Enumerant and Function Registry

The Registry includes databases defining the APIs and reserved enumerant ranges for OpenGL, GLX, and WGL. There are several of these ".spec" files for each API, described below :

OpenGL .spec files o enum.spec - canonical description of the reserved OpenGL enumerants and the ranges allocated for different purposes. New allocations are made here and when extensions using values in allocated ranges are registered, the enumerants in those extensions are added as well. o enumext.spec - derived variant of enum.spec containing the enumerant values grouped by the extension or API core revision they correspond to. o gl.spec - canonical description of the functions defined by core OpenGL and extensions. When extensions are registered, the functions they define are added here. o - typemap used to convert the abstract typenames in gl.spec into underlying GL types. o enumext.spec, gl.spec, and are used to generate glext.h

GLX .spec files o glxenum.spec - canonical description of the reserved GLX enumerants, like enum.spec. o glxenumext.spec - derived variant of glxenum.spec containing the enumerant values grouped by the GLX extension or API core revision they correspond to. This only includes GLX core versions 1.3 and later. o glx.spec - canonical description of the functions defined by core GLX up to version 1.3. o glxext.spec - canonical description of the functions defined by GLX extensions and core versions 1.3 and later. o - typemap used to convert the abstract typenames in glx*.spec into underlying GLX types. o glxenumext.spec, glxext.spec, and are used to generate glxext.h.

WGL .spec files o wglenum.spec - canonical description of the reserved WGL enumerants, like enum.spec. o wglenumext.spec - derived variant of wglenum.spec containing the enumerant values grouped by the WGL extension they correspond to. This only includes WGL core versions 1.3 and later (Microsoft has never revised the WGL core API). o wgl.spec - canonical description of the functions defined by WGL. o wglext.spec - canonical description of the functions defined by WGL extensions. o - typemap used to convert the abstract typenames in wgl*.spec into underlying WGL and Win32 types. o wglenumext.spec, wglext.spec, and are used to generate wglext.h.

Example:This example will draw a green square on the screen. OpenGL has several ways to accomplish this task, but this is the easiest to understand. However, the reader should be aware that most of the APIs used in the code below have been deprecated in and after the OpenGL 3.0 specification.

This statement clears the color buffer, so that the screen will start blank.
glMatrixMode( GL_PROJECTION ); /* Subsequent matrix commands will affect the projection matrix */ glLoadIdentity(); /* Initialise the projection matrix to identity */ glFrustum( -1, 1, -1, 1, 1, 1000 ); /* Apply a perspective-projection matrix */ These statements initialize the projection matrix, setting a 3d frustum matrix that represents the viewable area. This matrix transforms objects from camera-relative space to OpenGL's projection space.

glMatrixMode( GL_MODELVIEW ); /* Subsequent matrix commands will affect the modelview matrix */ glLoadIdentity(); /* Initialise the modelview to identity */ glTranslatef( 0, 0, -3 ); /* Translate the modelview 3 units along the Z axis */ These statements initialize the modelview matrix. This defines a transform from model-relative coordinates to camera The combination of the modelview matrix and the projection transforms objects from model-relative space to projection space. glBegin( GL_POLYGON ); /* Begin issuing a polygon */ glColor3f( 0, 1, 0 ); /* Set the current color to green */ glVertex3f( -1, -1, 0 ); /* Issue a vertex */ glVertex3f( -1, 1, 0 ); /* Issue a vertex */ glVertex3f( 1, 1, 0 ); /* Issue a vertex */ glVertex3f( 1, -1, 0 ); /* Issue a vertex */ glEnd(); /* Finish issuing the polygon */ matrix space. matrix screen

These commands draw a green square in the XY plane.

Associated utility libraries

Several libraries are built on top of or beside OpenGL to provide features not available in OpenGL itself. Libraries such as GLU can be found with most OpenGL implementations, and others such as GLUT and SDL have grown over time and provide rudimentary cross platform windowing and mouse functionality, and if unavailable can easily be downloaded and added to a development environment. Simple graphical user interface functionality can be found in libraries like GLUI or FLTK. Still other libraries like GLAux (OpenGL Auxiliary Library) are deprecated and have been superseded by functionality commonly available in more popular libraries, but code using them still exists, particularly in simple tutorials. Other libraries have been created to provide OpenGL application developers a simple means of managing OpenGL extensions and versioning. Examples of these libraries include GLEW (the OpenGL Extension Wrangler Library) and GLEE (the OpenGL Easy Extension Library). In addition to the aforementioned simple libraries, other higher level object oriented scene graph retained mode libraries exist such as PLIB, OpenSG, OpenSceneGraph, and OpenGL Performer. These are available as cross platform free/open source or proprietary programming interfaces written on top of OpenGL and systems libraries to enable the creation of real-time visual simulation applications. Other solutions support parallel OpenGL programs for Virtual Reality, scalability or graphics clusters usage, either transparently like Chromium or through a programming interface like Equalizer. Mesa 3D is a free/open source implementation of OpenGL. It supports pure software rendering as well as providing hardware acceleration for several 3D graphics cards under Linux.

Higher level functionality

OpenGL was designed to be graphic output-only: it provides only rendering functions. The core API has no concept of windowing systems, audio, printing to the screen, keyboard/mouse or other input devices. While this seems restrictive at first, it allows the code that does the rendering to be completely independent of the operating system it is running on, allowing cross-platform development. However, some integration with the native windowing system is required to allow clean interaction with the host system. This is performed through the following add-on APIs:

GLX X11 (including network transparency) WGL Microsoft Windows CGL Mac OS X. Better integration with Mac OS X's application frameworks is provided by APIs layered on top of CGL: AGL for Carbon and NSOpenGL for Cocoa.

Additionally, GLUT, SDL and the GLFW libraries provide functionality for basic windowing using OpenGL, in a portable manner.Some open source cross-platform toolkits, such as GTK+, Qt and WxWidgets, include widgets to embed OpenGL contents.