Search code examples
linuxopenglglutfreeglut

How do I compile and run code on Linux from INTERACTIVE COMPUTER GRAPHICS A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL® (6th edition)?


I'm trying to compile and run the book's online code from http://www.cs.unm.edu/~angel/BOOK/INTERACTIVE_COMPUTER_GRAPHICS/SIXTH_EDITION/CODE/, but they only seem to have Mac and Windows versions; how do I run this on Linux? I've spent hours trying to get the dependencies and things right just to build the simple examples in chapter 2!


Solution

  • I'm Tony from the future! If you continue on the path you're on, you'll end up spending several more hours before figuring this out - the good news is that I've already done it, and have compiled the following steps to help you out!

    1. sudo apt-get install freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev
    2. From http://www.cs.unm.edu/~angel/BOOK/INTERACTIVE_COMPUTER_GRAPHICS/SIXTH_EDITION/CODE/, download the following files:

      • CHAPTER02/WINDOWS_VERSIONS/ [I just put these files in CHAPTER02/]
      • Common/InitShader.cpp
      • Everything in include/ (although CheckError.h was unnecessary)
      • (So, your base directory should now have the following folders: CHAPTER02, Common, and include.)
    3. cd CHAPTER02

    4. g++ ../Common/InitShader.cpp example1.cpp -I../include -lglut -lGL -lGLU -lc -lm -lGLEW -o example1.out
    5. Make some changes to resolve errors:

      • add #include <stdio.h> to include/mat.h
      • If you get "X Error of failed request: GLXBadFBConfig", comment out these two lines in example1.cpp:

      //glutInitContextVersion( 3, 2 ); //glutInitContextProfile( GLUT_CORE_PROFILE );

      • If you get "error: GLSL 1.50 is not supported." change the first lines of fshader21.glsl and vshader21.glsl to say "#version 130" instead of 150
    6. ./example1.out
    7. Rejoice at finally seeing the Sierpinski Gasket!