Does anyone use the "OpenGL Super Bible 6th" book?

Hello, everyone.

I’m now setting up an environment to study the book “OpenGL Super Bible 6th”.

However, the sample code provided in the book doesn’t build normally. I’m using a Macbook pro (OS: Catalina).

The GLFW of the sample code is 2.7.6, so after changing to 3.3.1, “cmake” and “make” were executed, but a build error occurred.

Also I tried to “make cocoa-install” with GLFW 2.7.6 but got the error “symbol (s) … architecture x86_64”.

I really don’t know how to run the sample code on my computer. If anyone knows how, please let me know.

Post the specific errors you’re getting, and perhaps someone with a Mac can help you out.

If you have a Linux or Windows box, you may want to try using that instead. Apple doesn’t seem interested in supporting OpenGL anymore (…though devs are finding ways around that).

Hi, Dark_Photon.

Thanks your advice.

The error that occurred was:

  1. I had to compile and build for glfw-2.7.6. So, I did run command that “make cocoa-install” in glfw-2.7.6 top directory. But command occured error. Error like this “symbol(s) not found for architecture x86_64”.

  2. I want to change library glfw2 to glfw3. So I did changed CMakefiles some code and I saw same error with this first method.

  3. I used “Homebrew”. Current version Homebrew was not supported “install glew2”. I have no idea how to install “glew2” on my computer.

I really don’t know how to run the sample code on my computer. But your advice very useful.

I read the article on OpenGL, OpenCL support and I think it’s right to use the Metal API. I think it would be more appropriate to use OpenGL on Windows to understand the graphics principle.

But if you see someone who knows how to fix it, please give me some advice on how to use it. I will also consider how to use OpenGL on the MacOS and how to run the sample code from this book.

PS: Sorry, but the reply post doesn’t contain a link. I keep getting an error when I try to insert a sample code file download link. The sample code can be found on Google by searching for “opengl super bible”. You can find it in the “Previous editions” menu on that site.

Thanks a lot :smiley:

Ok. So if I understand correctly, you’re trying to build the OpenGL Superbible examples back from the 6th edition, not the ones for the latest 7th edition. And your problem isn’t really with the Superbible example code itself, but rather just building the GLFW dependency. And building this on Macbook. Is this correct?

Re building GLFW on MacBook, here’s a related link, which you may already have found:

See info on this page on installing GLFW 3.

Here on Linux, I just fetched the OpenGL Superbible 7th edition examples using the information here:

which pulls from this git repro: sb7code (GitHub)

Then I built them like this:

unzip sb7code-master.zip
cd sb7code-master

In CMakeLists.txt, changed the "glfw3" in the following line to "glfw":
set(COMMON_LIBS sb7 glfw3 X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL rt dl)

cd build
cmake ..
make -j8

cd ../bin/media
unzip superbible7-media.zip
cd ..
# Now you're ready to run binaries in this directory

Seems to work fine. But it does presume you have GLFW 3.x installed.

The reason for my one-line mod to CMakeLists.txt was that my local GLFW 3 library is named libglfw.so, not libglfw3.so.

No problem. New users can’t post links (URLs). However, once you have a few more posts on the forums, then you’ll be able to post them.

Thanks your advice.

I reinstalled “GLFW3” which I installed via “Homebrew” via the link you gave me. I also noticed that “GLFW3” related files were created in “/usr/local/lib” and “/usr/local/include”.

I modified “CMakeLists.txt” as you told me. And I executed the command, but I’m getting an error as shown below.

I’ll try to find a solution to this problem first. And I’m not found “libglfw.so” and “libglfw3.so”. I don’t know where location this file.

Thanks a lot :smiley:

See this page:

Sounds like you need to 1) make sure pkg-config is installed, and if so, 2) tell CMake where to find it.

To install: brew install pkgconfig. Then just rerun the cmake .. step.

If it still doesn’t find it, determine where your pkg-config executable is, and either add it to your $PATH or give it to CMake by adding this line to your CMakeLists.txt with the correct path:

set(PKG_CONFIG_EXECUTABLE "/usr/bin/pkg-config")

Based on what you just previously said here, it sounds like it should be located in /usr/local/lib.

Was OpenGL deleted from macOS?

I see that it is not. It is good. I thought that it was deleted. I use OpenGL 3 and it is enough that this version works on macOS.

I use WebGL 1.0 and TypeScritp. You can host your application one time and it will be works on Desktop and Mobiles and everywhere where is a browser. Read this book: WebGL Programming Guide and use glMatrix. This is my example on Playground that I wrote in WebGL 1.0, TypeScript and glMatrix. It draws a triangle: Plunker - Triangle. glMatrix, WebGL, TypeScript

Triangle_WebGLTypeScript

Thanks your comment.

I did study last year for WebGL. But I want to learn OpenGL. So I bought a some reference book call the “OpenGL Super Bible 6th”.

Now I try hard find some solution for normal tutorial code run (“OpenGL Super Bible 6th or 7th” sample code).

Thanks a lot your opinion :smiley:

WebGL and OpenGL has same things. I like this online book about OpenGL fragment shaders: https://thebookofshaders.com/ Maybe you will like it too.

Amazing! You gave me a really useful suggestion.

I will reference site. This time I know that OpenGL and WebGL deal with the same thing.

Thanks a lot :smiley:

1 Like

I proceeded with your advice. But I saw new error at sample code build.

I needed to know the location of “pkg-config” I used command find / -name "pkg-config" in my terminal. Finally, I found it.

“pkg-config” location is /usr/local/Cellar/pkg-config/0.29.2/bin/pkg-config.

Also I did this before building the project sample code.

  1. I fixed some source code in “CMakeLists.txt”.
    1-1. Add LINK_DIRECTORIES( /usr/X11/lib )
    1-2. Add set(PKG_CONFIG_EXECUTABLE "/usr/local/Cellar/pkg-config/0.29.2/bin/pkg-config"

  2. Install “GLFW” by Homebrew

  3. Download current version “GLFW” file in GLFW official site.

  4. I used to cmake . and make in 3 step folder.

  5. Copy libglfw3.a and paste sb7code-master/lib.

  6. Replaced old version glfw-3.0.4 and current version glfw-3.3.1 in sb7code-master/extern.

  7. I did change some code in sb7code-master/include/GL/glext.h (Start code line number is 6164). Like this:

     #ifndef GL_ARB_shader_objects
     /* GL types for program/shader text and shader object handles */
     typedef char GLcharARB;
     #if defined(__APPLE__)
         typedef void *GLhandleARB;
     #else
         typedef unsigned int GLhandleARB;
     #endif
     #endif 
    

So I processed with your advice. But an error occurred.

Like this:

I don’ know what is library -lrt. I did install X11(XQuartz) from Apple.

What am I missing now?

Thanks a lot :smiley:

It looks like you’re getting really close!

On Linux, librt.so is the POSIX Realtime Extensions library. It contains routines for 1) asynchronous I/O, 2) message queues, 3) shared memory access, and 4) per-process timers. Routines such as these:

It doesn’t look like any of the code in the Superbible 7 Examples code references the routines in this library directly. And it could be that none of your libraries on that platform depend on this librt library.

So I would try just removing it from the link line used by the examples and see if that resolved your problem.

Doing a quick grep, it appears that the “-lrt” is only provided in this file:

./sb7code-master/extern/glfw-3.0.4/CMakeLists.txt:        set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -lrt")

So try removing the -lrt on this line, and then re-config and rebuild using the process I listed above (including re-running cmake ..).

I processed as below:

  1. Add set(PKG_CONFIG_EXECUTABLE "/usr/local/Cellar/pkg-config/0.29.2/bin/pkg-config").
  2. Replaced code ... glfw3 ... => ... glfw ... in sb7code-master/CMakeLists.txt.
  3. Replaced original file sb7code-master/include/GL/glext.h and updated file glext.h in sb7code-master/include/GL.
  4. Delete set(GLFW_PKG_LIBS "{GLFW_PKG_LIBS} -lrt") code from sb7code-master/extern/glfw-3.0.4/CMakeLists.txt.

So I try build in my computer. But an error occurred.

Like this:

I saw new contents when I search how to build on macOS.

“OpenGL Super Bible 7th” is using OpenGL 4.5. My computer spec is below.

  • Macbook pro (Retina, 15-inch, Mid 2015)
  • Using two graphics chips (Intel Iris Pro 5200, AMD Radeon R9 M370X)
  • Using OS Catalina

I found some information how much support OpenGL and CL version in Apple official site. My computer supported GL 4.1 and CL 1.2.

Mac computers that use OpenCL and OpenGL graphics

Can I really build sample code on my computer?

Also, I changed some contents of “CMakeLists.txt” by referring to the following site. But I still get an error.

Fix linking error on ubuntu #13

Thanks a lot :smiley:

In this post, you indicated that you’d already successfully built (or obtained) a GLFW library, and had placed it in the sb7code-master/lib directory:

5. Copy libglfw3.a and paste sb7code-master/lib.

It sounds like that you just need to point the Superbible Examples build to where you put it, and link it with the name you’ve given it (glfw3 in the case of the above).

In sb7code-master/CMakeLists.txt, I think it already tells it to look in the sb7code-master/lib directory for libraries, so just place the glfw library in this directory (if it’s not already in a system directory):

LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/lib )
...
if(WIN32)
  set(COMMON_LIBS sb7 optimized glfw3 debug glfw3_d ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES})
elseif (UNIX)
  find_package(PkgConfig REQUIRED)
  pkg_check_modules(GLFW REQUIRED glfw3)
  set(COMMON_LIBS sb7 glfw3 X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL rt dl)
else()
  set(COMMON_LIBS sb7)
endif()

I had understand what you said. I processed according to your advice. Additionally I added some source code to sb7code-master/CMakeLists.txt (I finished copying the build task related files).

+ LINK_DIRECTORIES( /usr/X11/lib)
+ set(PKG_CONFIG_EXECUTABLE "/usr/local/Cellar/pkg-config/0.29.2/bin/pkg-config")

+ IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+     set(COMMON_LIBS sb7 glfw3 X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL dl)
+     find_library(IOKIT IOKit)
+     find_library(COCOA Cocoa)
+     find_library(CORE_FDT CoreFoundation)
+     find_library(CORE_VIDEO CoreVideo)
+ ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

+ IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+     set(CMAKE_CXX_FLAGS "${CMAKE_CSS_FLAGS} -std=c++11")
+ ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

Below include “glfw-master” getting from this repository.

+ include_directories(extern/glfw-master/include)

After this process and I ran cmake .., make -j8 in sb7code-master/build. Fortunately, some seem to have been compiled. I ran a compiled example as shown below.

However, an error occurs about 30% of the compile process. Cause omp.h file not found. I think omp.h related “OpenMP”. So installed libomp, llvm using “Homebrew”.

Should I write the path for “OpenMP” in “CMakeLists.txt” again?

I don’t know much about “CMakeLists” so I don’t know how to write it. Most of the reasons I’ve been able to proceed here are due to your advice. Thank you so much :smiley:

According to this:

brew probably told you what options needed to be provided to CMake to get it to compile with OpenMP support. In the above link, it’s:

-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib

Here on Linux, CMake just detected the proper method for compiling and linking in OpenMP support automatically.

After that, here’s how the CMake-generated Makefile compiled and linked the ompparticles demo (for instance):

[ 48%] Building CXX object CMakeFiles/ompparticles.dir/src/ompparticles/ompparticles.cpp.o
/usr/bin/c++   -I/data/CD-PREP/ARCHIVE/GRAPHICS/BOOKS/OpenGL_Superbible/t/sb7code-master/include -I/data/CD-PREP/ARCHIVE/GRAPHICS/BOOKS/OpenGL_Superbible/t/sb7code-master/extern/glfw-3.0.4/include  -fopenmp -D_LINUX -std=c++0x   -o CMakeFiles/ompparticles.dir/src/ompparticles/ompparticles.cpp.o -c /data/CD-PREP/ARCHIVE/GRAPHICS/BOOKS/OpenGL_Superbible/t/sb7code-master/src/ompparticles/ompparticles.cpp
[ 48%] Linking CXX executable ../bin/ompparticles
/usr/bin/cmake -E cmake_link_script CMakeFiles/ompparticles.dir/link.txt --verbose=1
/usr/bin/c++   -fopenmp -D_LINUX -std=c++0x  -rdynamic CMakeFiles/ompparticles.dir/src/ompparticles/ompparticles.cpp.o  -o ../bin/ompparticles  -L/data/CD-PREP/ARCHIVE/GRAPHICS/BOOKS/OpenGL_Superbible/t/sb7code-master/lib -Wl,-rpath,/data/CD-PREP/ARCHIVE/GRAPHICS/BOOKS/OpenGL_Superbible/t/sb7code-master/lib lib/libsb7.a -lglfw -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lGL -lrt -ldl 

I referenced many information in stackoverflow.

Added some source code in CMakeLists.txt for OpenMP.

set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/9.0.0_1/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/9.0.0_1/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/9.0.0_1/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/9.0.0_1/include")

OPTION(USE_OpenMP "Use OpenMP to enable <omp.h>" ON)

if (APPLE AND USE_OpenMP)
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
		set(OpenMP_C "${CMAKE_C_COMPILER}")
		set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
		set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
		set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
		set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
		set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES})
	endif()
	if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
		set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
		set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
		set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5")
		set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
		set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
		set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
	endif()
endif()

if(USE_OpenMP)
	find_package(OpenMP REQUIRED)
endif(USE_OpenMP)

if(OPENMP_FOUND)
	include_directories("${OPENMP_INCLUDES}")
	link_directories("${OPENMP_LIBRARIES}")
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
	# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif(OPENMP_FOUND)

And some source code wrapping to comment. Below this:

# find_package(OpenMP)
# if (OPENMP_FOUND)
#    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
#    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
#    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# endif()

# IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
#	set(CMAKE_CXX_FLAGS "${CMAKE_CSS_FLAGS} -std=c++11")
# ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

Finally, I saw 100% build succeeded for sb7code-master. I ran two commands in "sb7code-master/build".

cmake ..
make (or make -j8)

But I don’t know when I have not see anything at run sample program (eg. singletri.exec). I have see only green background.

What am I missing now?

Your advice so very useful to me. Thanks a lot :smiley:

Great!

Well, some of the examples assume that you have unzip’ed the media files in the bin/media/ directory. But not singletri.

Here’s what I get when I run singletri, whether or not the media ZIP has been unzip’ed in bin/media/:

And here’s when I see when I run alienrain, but only after unzip’ing the media ZIP in bin/media:

Unzipping the media:

cd sb7code-master/bin/media/
unzip ../../../../superbible7-media.zip
cd ..