0% found this document useful (0 votes)
77 views

What Is OpenGL

OpenGL is a software interface for 3D graphics hardware. It consists of 150+ commands to specify 3D objects and operations without hardware dependencies. It provides a basic set of geometric primitives but not high-level models. Header files like gl.h and glu.h are needed. Windows are initialized using GLUT functions and the display callback redraws the scene.

Uploaded by

Padmashree Naik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

What Is OpenGL

OpenGL is a software interface for 3D graphics hardware. It consists of 150+ commands to specify 3D objects and operations without hardware dependencies. It provides a basic set of geometric primitives but not high-level models. Header files like gl.h and glu.h are needed. Windows are initialized using GLUT functions and the display callback redraws the scene.

Uploaded by

Padmashree Naik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

What Is OpenGL?

OpenGL is a software interface to graphics hardware. This interface consists of about 150 distinct commands that you use to specify the
objects and operations needed to produce interactive three-dimensional applications.

OpenGL is designed as a streamlined, hardware-independent interface to be implemented on many different hardware platforms. To achieve
these qualities, no commands for performing windowing tasks or obtaining user input are included in OpenGL; instead, you must work
through whatever windowing system controls the particular hardware you're using. Similarly, OpenGL doesn't provide high-level commands
for describing models of three-dimensional objects. Such commands might allow you to specify relatively complicated shapes such as
automobiles, parts of the body, airplanes, or molecules. With OpenGL, you must build up your desired model from a small set of geometric
primitives - points, lines, and polygons.

OpenGL Command Syntax

As you might have observed from the simple program in the previous section, OpenGL commands use the prefix gl and initial capital letters
for each word making up the command name (recall glClearColor(), for example). Similarly, OpenGL defined constants begin with GL_,
use all capital letters, and use underscores to separate words (like GL_COLOR_BUFFER_BIT).

Some OpenGL commands accept as many as 8 different data types for their arguments. The letters used as suffixes to specify these data
types for ISO C implementations of OpenGL

Suffix Data Type Typical Corresponding C-Language Type OpenGL Type Definition

B 8-bit integer signed char GLbyte

S 16-bit integer Short GLshort

I 32-bit integer int or long GLint, GLsizei

F 32-bit floating-point Float GLfloat, GLclampf

D 64-bit floating-point Double GLdouble, GLclampd

ub 8-bit unsigned integer unsigned char GLubyte, GLboolean

us 16-bit unsigned integer unsigned short GLushort

ui 32-bit unsigned integer unsigned int or unsigned long GLuint, GLenum, GLbitfield

Include Files

For all OpenGL applications, you want to include the gl.h header file in every file. Almost all OpenGL applications use GLU, the
aforementioned OpenGL Utility Library, which requires inclusion of the glu.h header file. So almost every OpenGL source file begins with

#include <GL/gl.h>
#include <GL/glu.h>

If you are directly accessing a window interface library to support OpenGL, such as GLX, AGL, PGL, or WGL, you must include additional
header files. For example, if you are calling GLX, you may need to add these lines to your code

#include <X11/Xlib.h>
#include <GL/glx.h>

If you are using GLUT for managing your window manager tasks, you should include

#include <GL/glut.h>

Note that glut.h includes gl.h, glu.h, and glx.h automatically, so including all three files is redundant. GLUT for Microsoft Windows
includes the appropriate header file to access WGL.

Window Management
Five routines perform tasks necessary to initialize a window.

• glutInit(int *argc, char **argv) initializes GLUT and processes any command line arguments (for X, this would be options like
-display and -geometry). glutInit() should be called before any other GLUT routine.
• glutInitDisplayMode(unsigned int mode) specifies whether to use an RGBA or color-index color model. You can also specify
whether you want a single- or double-buffered window. (If you're working in color-index mode, you'll want to load certain colors
into the color map; use glutSetColor() to do this.) Finally, you can use this routine to indicate that you want the window to have
an associated depth, stencil, and/or accumulation buffer. For example, if you want a window with double buffering, the RGBA
color model, and a depth buffer, you might call glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH).
• glutInitWindowPosition(int x, int y) specifies the screen location for the upper-left corner of your window.
• glutInitWindowSize(int width, int size) specifies the size, in pixels, of your window.
• int glutCreateWindow(char *string) creates a window with an OpenGL context. It returns a unique identifier for the new
window. Be warned: Until glutMainLoop() is called (see next section), the window is not yet displayed.

The Display Callback

glutDisplayFunc(void (*func)(void)) is the first and most important event callback function you will see. Whenever GLUT determines the
contents of the window need to be redisplayed, the callback function registered by glutDisplayFunc() is executed. Therefore, you should
put all the routines you need to redraw the scene in the display callback function.

If your program changes the contents of the window, sometimes you will have to call glutPostRedisplay(void), which gives
glutMainLoop() a nudge to call the registered display callback at its next opportunity.

Running the Program

The very last thing you must do is call glutMainLoop(void). All windows that have been created are now shown, and rendering to those
windows is now effective. Event processing begins, and the registered display callback is triggered. Once this loop is entered, it is never
exited!

OpenGL Architecture

Preliminaries

• Headers Files

• #include <GL/gl.h>

• #include <GL/glu.h>

• #include <GL/glut.h>
• Libraries

• Enumerated Types

– OpenGL defines numerous types for compatibility

– GLfloat, GLint, GLenum, etc.

Modeling Transformations

• Move object

glTranslate{fd}( x, y, z )

• Rotate object around arbitrary axis

glRotate{fd}( angle, x, y, z )

– angle is in degrees

• Dilate (stretch or shrink) or mirror object

glScale{fd}( x, y, z )

glScissor( x, y, w, h )

• any fragments outside of box are clipped

• useful for updating a small section of a viewport

• affects glClear() operations

You might also like