Updated on March 18
Updated on Nov 2 2015
What is OpenGL? ( Open Graphics
OpenGL is a software interface to graphics
hardware. It is the most common graphics API originated by SGI
(Silicon Graphics). Essentially it allows you to "draw in 3-D". It
can be used for 2-D but there are other packages out there that do
that as well (such as Allegro, SDL). It is a graphics library used
in many applications. OpenGL is an API
for rendering graphics - usually 3D.
The interface consists of hundreds of distinct commands in the core OpenGL (GL) and more in the OpenGL Utilitiy Library (GLU). These commands are used to specify objects and operations needed to create interactive 3-D applications. OpenGL is designed to be hardware-independent.
What OpenGL is NOT - timing, fileI/O, animations, image file format processing, GUI, etc. Since OpenGL does not provide routines for interfacing with windowing systems or input devices that's where GLUT comes in. GLUT provides windowing operations, opening windows and input processing.
OpenGL has changed over the years. Latest versions from 3.0 on, are now more powerful with the technology of gpu. Original pipeline (version 1.0 July 1994) was fixed-function. With version 2.0, added programmable shaders. Changes in 3.0 changed the pipeline to match the hardware capabilities. Pipeline changed in 3.1 (March 2009) - data became GPU-resident. 3.2 introduced geometry shaders and context profiles. OpenGL 4.1 (July, 2010) included tessellation-control and evaluation shaders. Latest version is 4.5.
GLSL becomes very important.
Derivatives of OpenGL:
- OpenGL ES 2.0 - cell phones, hand-held devices, based on GL 3.1 and shader based
For example, you won't find options to set your gl version in Houdini now that it has adapted GL3.0 core. This is specified in the specs: "You must have a GL3 compliant graphics card in order to run Houdini. For Windows and Linux, you'll need a GL3 graphics card with a GL3.3 driver. "
Pipeline in simple terms is vertex processing/rasterizer (user not control)/fragment processing.
What is GLUT? ( OpenGL Utility Toolkit ) and what is Freeglut
GLUT is not OpenGL, it is a library that can be used to create an OpenGL window.
We will also be using GLUT (or freeglut - see aside below) which stands for the OpenGL Utility Toolkit. It is a window system independent toolkit for writing OpenGL programs. Wait, what? GLUT makes it easier to learn and explore OpenGL by providing a library of utilities which primarily perform system-level I/O with the host OS (operating system) such as window definition, window control, monitoring keyboard and mouse input and drawing a number of primitve shapes. GLUT was written by Mark J. Kilgard while he was at Silicon Graphics Inc (now at NVIDIA) and was ported to Microsoft Windows (WGL) by Nate Robins.
GLUT is a library that provides a platform-independent interface to window management, menus, i/o devices.
A good site to learn more about GLUT is here.
Freeglut site is here.
In addition, there are step by step example files in the MATERIALS folder. These work on both linux and windows. GLUT has been thoroughly tested. (As of F15, glut has been replaced with freeglut on Windows only)
There is another alternative to GLUT (which is now unsupported) called Freeglut. It is very similar and I have tested it on my personal Windows machine. If you wish to pursue GLSL (the graphics library shading language) you are advised to use freeglut along with glew or the OpenGL Unofficial SDK, however this is beyond the scope of the class material. (I have tested freeglut, glew and glsl so let me know if you are interested).
If you would like to use freeglut at home on Windows I have instruction for visual studio with freeglut and using mingw with freeglut. In addition, I have instructions for linux with freeglut as well which I have tested on CentOS.
If you are interested there are similar excellent resources which can be found. Similar to the description given above for glut, freeglut can be found here.
The main reason for this advice is that many of the example files for glsl are based on freeglut and glew or alternatively use the OpenGL Unofficial SDK which includes freeglut. Martin Payne's site provides binaries for MSVC and MinGW. For information on installing this along with glew see http://www.cs.uregina.ca/Links/class-info/315/WWW/Lab1/GLUT/windows.html.
Note that this also contains a link for Angel.zip - a set of utility files that are also dependent on freeglut and are used in many glsl examples. There is an excellent starter example at Morten Nobel-Jorgensen's Blog.
Alternatives to glew are listed here including the unofficial OpenGL SDK which includes FreeGlut.
Yet another topic related is SFML (Simple and Fast Multimedia Library) to provide an API interface as well. There was a discussion posted here giving a very brief overview. There is also a list here under context and window toolkits.
TIP: do not use variable names far or near when using freeglut. They are valid in glut.
Here is a link to what has caused this: http://sourceforge.net/p/freeglut/bugs/205/
Using OpenGL/GLUT or Freeglut?On Windows:
If you would like to use OpenGL/Freeglut with Visual Studio click here
[Recommended to use freeglut rather than glut: If you would like to use OpenGL/GLUT at home with Visual Studio 2010 a step-by-step guide to achieve this is here. (Also documented for Eclipse and command line on Windows here).]
In Eclipse or command line: click here.
Note, if you develop code on Windows and bring it to linux, there may be some changes required. Example files exist in the dropbox for both windows and linux. The major changes to the example files that were converted from Windows to RedHat 6 Linux so far under the Tips and troubleshooting Section near the bottom of the page.
If you are on linux, here is an excellent website that you can also refer to.
Using Python and OpenGL/GLUT on Windows:
Have not personally tested this yet but will soon ...
The above is for C++ but you can also use OpenGL/glut with python! You will need to download pyOpenGL. You can download the same version of glut and place the files as you did above. However, do not use the official release of pyOpenGL - this does not work on Windows - you will need to use the unofficial version described below. Otherwise you will get an error as described here. I tried the official release version on two different machines, went through all the top google suggestions and still had:
File "C:\Python27\lib\site-packages\OpenGL\GLUT\special.py", line 324, in glutInit
_base_glutInit( ctypes.byref(count), holder )
TypeError: 'NoneType' object is not callable
Using this site here, scroll down to the version (or search for PyOpenGL). I used PyOpenGL-3.0.2.win-amd64-py2.7.exe and it worked great! (I'm using python 2.7).
Examples and resources:Documentation by Mark J. Kilgard on GLUT exists here.
There are many resources on the internet, for example here.
One of my favorite introductory tutorials is located here.
Here is a very simple example to test your choice of IDE/compiler. I have placed a selection of examples in the MATERIALS folder that cover the topics we will touch on. This is intended to correspond to the select OpenGL topics that will be covered and is by no means any attempt at being a comprehensive list.
There are numerous books available. A few options are listed below.
"OpenGL Programming Guide - The Official Guide to Learning OpenGL" Sixth Edition, by Dave Shreiner, Mason Woo, Jackie Neider and Tom Davis is an excellent reference. There exist a Seventh Edition (available at Safari books online through the SCAD library) and soon to be published Eighth Edition (Dec 19, 2011)
A more computer graphics approach is taken is "Computer Graphics with Open GL" by Hearn and Baker. This goes into the underlying algorithms and methods commonly used in creating graphics displays.
"Beginning OpenGL Game Programming, Second Edition" by Luke Benstead is available at Safari books online through the SCAD library.
In addition, there is an excellent video from Siggraph 2013 and 2014 "An Introduction to OpenGL Programming" on the SIGGRAPH University youtube channel. The presenters are Edward Angel from the University of New Mexico and Dave Shreiner of ARM, Inc. (They are using freeglut).
Their power point slides are also available here.
Computer Graphics Tools:Games and VSFX use Computer Graphics Tools in many ways. These tools are hardware and software. Hardware tools include output devices: video monitors, printers; input devices: mouse/trackball, pen/drawing tablet, keyboard; graphics cards. Software tools include OS, editor, compiler, debugger, graphics library (OpenGL).
Computer Graphics Libraries:
consist of Functions/commands to draw line, circle, cube, etc.
Now have device-independent libraries: APIs: OpenGL, DirectX, java3D. ie. Working OpenGL programs can be used on Windows, or Linux.
Please Note:OpenGL is a vast topic involving many of the underlying concept of Computer Graphics - we will take a cursory look at OpenGL and use it as a tool to implement a visual interface with the final assignment that you will develop in this class (or optionally, HDK).
For an overview of some of the OpenGL and glut/freeglut code we will be using click here.
Also note, glutMouseFunc - the x and y of the result are in window relative coordinates. So your windows upper left corner is 0,0 but in openGL the bottom left is the origin, so you will likely have to remap depending on how you set up your ortho view.