TUTORIAL 1 - OpenGL Fundamentals

1  2  3  4  5  6  7  8  9  10  11  12  13

Introduction

If you want to use advanced graphics output, you have to decide, whether you prefer OpenGL or DirectX. Each of them has its specific advantages and disadvantages. While OpenGL exists on all major platforms (Linux, Windows, Macintosh,…) DirectX is limited to Windows, but on the other hand DirectX supports multimedia, which OpenGL is just starting to support (the so called OpenML). Due to the platform independence of OpenGL, I will use OpenGL to show how advanced graphics can be implemented.

OpenGL is a software interface that allows you to access the graphics hardware without taking care of the hardware details or which graphics adapter is in the system. To become more independent of the platform and programming language, OpenGL provides it's own data types. In the following list you can find a summary of the most important data types and their equivalent in standard C:


OpenGL Data Type Internal Representation Defined as C Type C Literal Suffix

GLbyte 8-bit integer Signed char b
GLshort 16-bit integer Short s
GLint, GLsizei 32-bit integer Long I
GLfloat, GLclampf 32-bit floating point Float f
GLdouble, GLclampd 64-bit floating point Double d
GLubyte, GLboolean 8-bit unsigned integer Unsigned char ub
GLushort 16-bit unsigned integer Unsigned short us
GLuint, GLenum, GLbitfield 32-bit unsigned integer Unsigned long ui

Another advantage of OpenGL is the logical structure of its commands. Lets take the glcolor3f command as an example (this command is used to set the color of vertices).

The first two letters are the library prefix. "gl" means, that the command is part of the gl library, which is used most (nevertheless there are also other libraries like the glut, which are very usefull). "color" is the actual command, "3" gives the number of arguments and "f" tells us, that the arguments are of type "float". If you select a color, all drawing routines will use this color until you select another color with the glcolor3f command (i.e. OpenGL works as a state machine). In the following we will discuss a basic OpenGL application, that shows how to use the most important commands. Of course this discussion can't teach you everything about OpenGL, but hopefully it can give you a starting point.

previous    next