Introduction to Computer Graphics


Mac Setup


0. Install XCode


The first action we want to perform is installing XCode. This is Apple's primary environment for creating C++ programs.

  • From a terminal run the command: "xcode-select --install"
  • You may also download XCode from the Appstore.


1. Setup


The first thing we want to do on our Mac systems, is check which version of OpenGL we have. I have tested

  • The quickest way is to check: Apple Support. Do so now
    • If glxinfo is missing, you can install: https://www.xquartz.org
    • If that still does not work, then you can just trust the Apple Support link above.
  • You should notice OpenGL 3.3 is supported across almost every system since 2007. Any Mac within the last decade will support the functions we call (How fast is to be determined!)
  • Let's also figure out our OpenGL version from the terminal however (something a bit more principled).
  • Run on a terminal: glxinfo | grep "version"
  • glxinfo The observation here is on my Mac I only have version 2.1 running. But if I look at the previous Apple link, my 2011 MacBook Air with an Intel HD Graphics 3000 should support OpenGL 3.3.
  • The trick here, is for Mac's we will have to explicitly state in our code that we want to use OpenGL 3.3.

2. Identifying your graphics card


Today most laptops have a fairly powerful graphics card on them. Some laptops even have two graphics cards in them! Try these steps to find out:

  • Click on the Apple Icon in the top left corner of your mac.
  • Then hit the displays tab.
  • You should then see the graphics cards you have available.
  • (From the terminal you can try: "system_profiler SPDisplaysDataType")

3. Files - Downloading SDL


The easiest way to get SDL is to visit the SDL website at https://www.libsdl.org/download-2.0.php (Note we are downloading version 2.0).

  • glxinfo Download the SDL 2 .dmg file and double-click to install it.
  • glxinfo Copy the SDL2.frameworks file to the path /Library/Frameworks. Hint: Command+shift+g will bring up a finder for you to jump quickly jump to.
  • glxinfo If given a prompt, authenticate SDL2.framework

(Aside) - Mac Troubleshooting

If you have trouble compiling from the command-line. You need to download Xcode and the command line development tools(You can also run "xcode-select --install" in a terminal). This means going to the app store and downloading XCode (which could take a few hours to download depending on your connection speed).

  • Mac has what are called 'frameworks' which are in additional to static libraries. A reasonable explanation of Frameworks is provided on Stack Overflow here.

4. GLAD - OpenGL Extensions


Note: I have done this setup for you in the repository.

GLAD is a tool that helps us use extensions in OpenGL. An OpenGL extension is some feature or functionality that a graphics card vendor provides. In other words, extensions are released over time, and they allow us to run a variety of commands on graphics cards to improve performance, or create neat visual effects.

Some information below.
  • A permanent link to the 3.3 profile I generated for this course is here. I have provided GLAD in the code repository already.
  • If you look at glad.h, you will see that it is essentially a giant list of function pointers.
  • (Optional just FYI: You can generate your own profile here: GLAD webservice
  • (Optional) If you are still having trouble, this link may be of use:GLAD and SDL2

5. Build - Linking SDL with source


Now that we have GLAD and SDL downloaded, we are ready to try and run our program. In this section I am going to describe how to link SDL to our executable.

  • Provide with the lab is a file called "macbuild.py". By running "python macbuild.py" on your system, your file will actually compile just fine. However, let me show a "raw" version of compiling so you understand what is going on.
  • clang++ -o lab -I ./include/ -I/Library/Frameworks/SDL2.framework./Headers ./src/lab.cpp ./src/glad.c -F/Library/Frameworks -framework SDL2
    • clang++ is the compiler being used
    • -o lab1 is a compiler flag outputting an object file named lab 1
    • -I followed by a directory tells where to look for header(.h) files.
    • ./src/lab1.cpp is an example of a C++ file we are compiling (./src/glad.c is a .c file also being compiled)
    • -F/Library/Frameworks where to find Frameworks library files
    • -framework tells to load in the SDL2 library.

6. Video Tutorial


(My Mac crashed, but it is somewhat similar to the Linux setup. Read above directions and I can help troubleshoot in class.)

(Best viewed in HD if you want to read the text).