Lazy Foo' Productions

SDL Forums external link SDL Tutorials Articles OpenGL Tutorials OpenGL Forums external link
Follow BlueSky Follow Facebook Follow Twitter Follow Threads
Donate
News FAQs Contact Bugs

Hello OpenGL

Hello OpenGL screenshot

Last Updated: Sep 8th, 2012

OpenGL is a pure graphics rendering API. It'll render anything you tell it to, but it has no commands to process files or handle windowing. Fortunately, there are support libraries like freeGLUT that can create OpenGL windows.

freeGLUT is a completely open source alternative to the OpenGL Utility Toolkit (GLUT) library. While it's not the most versatile OpenGL windowing API, it's great for doing quick OpenGL demos. In order to use it, you need to install it.
We're using freeGLUT as a dynamically linked library. A dynamically linked library has 3 parts:
  • The header files (Library.h)
  • The library files (Library.lib for windows or libLibrary.a for *nix)
  • The binary files (Library.dll for windows or Library.so for *nix)
Your compiler needs to be able to find the header files when compiling so it knows what glutMainLoop() and the other freeGLUT functions and variables are. You can either configure your compiler to search in an additional directory where the freeGLUT header files are located, or put the header files in with the rest of header files that your compiler comes with. If the compiler complains that it can't find freeglut.h, it means the header files aren't in a place that the compiler looks for header files.

After your compiler compiles all your source files it has to link them together. In order to program to link properly, it needs to know the addresses of all your functions including the ones for freeGLUT. For a dynamically linked library, these addresses are in the library file. The library file has the Import Address Table so your program can import the functions at runtime. Like with header files, You can either configure your compiler to search in an additional directory where the freeGLUT library files are located, or put the library files in with the rest of library files that your compiler comes with. You also have to tell the linker to link against the library file. If the linker complains that it can't find -lfreeglut or freeglut.lib, it means the library files aren't in a place that the linker looks for library files. If the linker complains about an undefined reference, it probably means it was never told to link the library.

After your program is compiled and linked, you need to be able to link against the library when you run it. In order to run a dynamically linked application, you need to be able to import the library binaries at runtime. Your operating system needs to be able to find the library binary when you run your program. You can either put the library binaries in the same directory as your executable, or a directory that your operating system keeps library binary files.

After you set up freeGLUT, we'll cover how to render your first polygon using OpenGL.
Select Your Operating System
Setting up freeGLUT on Windows
Setting up freeGLUT on Windows
Setting up freeGLUT on Linux
Setting up freeGLUT on Linux
Setting up freeGLUT in Mac OS X Lion
Setting up freeGLUT in Mac OS X Lion