• Stars
    star
    295
  • Rank 135,700 (Top 3 %)
  • Language
    C
  • License
    MIT License
  • Created almost 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OpenGL 4 Shading Language Cookbook - Third Edition, published by Packt

Example code from the OpenGL 4 Shading Language Cookbook, 3rd Edition

The example code from the OpenGL 4 Shading Language Cookbook, 3rd Edition, by David Wolff and published by Packt Publishing.

Requirements

To compile these examples, you'll need the following:

  • The GLM Mathematics Library version 0.9.6 or later. Note that versions prior to 0.9.6 may not work properly because of a switch from degrees to radians. GLM 0.9.5 will work, but you'll need to add #define GLM_FORCE_RADIANS prior to including the glm header files.
  • GLFW version 3.0 or later.

Compiling the examples

The example code builds with CMake. Note that the examples for Chapter 10 will not function on MacOS due to lack of support for compute shaders on that platform.

  1. Install GLFW by following the instructions on their web site.
  2. Install the latest version of GLM. Note that for CMake to find GLM correctly, you need to run the install "build" (e.g. make install) or install GLM from your favorite package manager. Otherwise, the CMake config files will not be created/available.
  3. Download this example code from github, or clone using git.
  4. Run cmake. If cmake has difficulties finding the GLFW or GLM installations, set the variable CMAKE_PREFIX_PATH to help cmake find them.
    It can be tricky to get CMake to find the GLM libraries, unfortunately. See below for tips.
  5. Compile by running make.

Any problems, create an issue on github.

Tips for getting CMake to find GLM

When searching for GLM, CMake looks for the files glmConfig.cmake and glmConfigVersion.cmake.

If you install GLM using a package manager such as Homebrew on macOS, or a Linux package manager the cmake files should already be included.

Otherwise, if you're using the GLM source distribution, you'll have to run GLM through CMake to get it to generate the glmConfig.cmake and glmConfigVersion.cmake files. It is frustrating, I wish that the GLM maintainers didn't require this.

  1. Download GLM and extract it to some location: GLM_SRC
  2. cd $GLM_SRC
  3. mkdir build
  4. cd build
  5. cmake -D GLM_TEST_ENABLE=OFF -D CMAKE_INSTALL_PREFIX=MY_GLM_LOCATION ..
  6. cmake --build . --target install

Replace GLM_SRC above with the place where you extracted the GLM zip file, and replace MY_GLM_LOCATION with the location where you want to install GLM. This should generate the needed cmake files and install all of GLM to MY_GLM_LOCATION.

Tips for compiling for Windows with Visual Studio

  • Use the Visual Studio target in CMake: -G "Visual Studio...", open the Visual Studio solution. You should see one project per chapter.
  • Each chapter requires a command line argument to choose a recipe. When running in VS, be sure to set the 'Command Argument' under 'Properties' for the appropriate recipe.

OpenGL Function Loading

An OpenGL header file and a function loader for a 4.3 core profile are included with this project. They were generated using GLAD. This loader should also work on MacOS under a 4.1 core profile, but of course not all functions will load.

The code has been tested with OpenGL 4.3 on Windows/Linux and OpenGL 4.1 on MacOS.

OpenGL 4 Shading Language Cookbook - Third Edition

This is the code repository for OpenGL 4 Shading Language Cookbook - Third Edition, published by Packt.

Build high-quality, real-time 3D graphics with OpenGL 4.6, GLSL 4.6 and C++17

What is this book about?

OpenGL 4 Shading Language Cookbook, Third Edition provides easy-to-follow recipes that first walk you through the theory and background behind each technique, and then proceed to showcase and explain the GLSL and OpenGL code needed to implement them.

This book covers the following exciting features:

  • Compile, debug, and communicate with shader programs
  • Use compute shaders for physics, animation, and general computing
  • Learn about features such as shader storage buffer objects and image load/store
  • Utilize noise in shaders and learn how to use shaders in animations
  • Use textures for various effects including cube maps for reflection or refraction

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow *window = glfwCreateWindow(800, 600, "Title", nullptr, nullptr);

Following is what you need for this book: If you are a graphics programmer looking to learn the GLSL shading language, this book is for you. A basic understanding of 3D graphics and programming experience with C++ are required.

With the following software and hardware list you can run all code files present in the book (Chapter 1-11).

Software and Hardware List

Chapter Software required OS required
All GLM Mathematics Library Windows, Mac OS X, and Linux (Any)
GLFW Windows, Mac OS X, and Linux (Any)
CMake Windows, Mac OS X, and Linux (Any)
Visual Studio 2017 Windows, Mac OS X, and Linux (Any)

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

Errata

  • Page 238 (line 24): GLenumdrawBuffers[] = {GL_NONE, GL_COLOR_ATTACHMENT0, should be GLenum drawBuffers[] = {GL_NONE, GL_COLOR_ATTACHMENT0.
  • Page 375 (last line): This recipe was inspired by a blog post by Wojciech Toman (no longer publicly available), has been removed please ignore the line
  • Page 371 (Code snippet 1 ,second last line): vec3 rustColor = mix( MaterialColor.rgb, vec3(0.01), noise.a );, should be vec3 rustColor = mix( MaterialColor.rgb, vec3(0.01), noise );
  • Page 328 (line 24): **When GL_NEAREST is the interpolation mode (as it is in our case) the result will be 1.0, or 0.0. **should beWhen GL_COMPARE_REF_TO_TEXTURE is the texture comparison mode (as it is in our case) the result will be either 1.0 or 0.0
  • Page 327 (tip second line): because we need a 2D position and a depth , should be because we need a 2D texture coordinate and a reference depth value for the comparison
  • Page 279 ( line 10): For example, to find ha, we use the interior angle at vertex C (β) , should be For example, to find ha, we use the interior angle at vertex B (β)
  • Page 264 ( line 2): indicates the index within the GL_ATOMIC_COUTER_BUFFER binding point (refer, should be indicates the index within the GL_ATOMIC_COUNTER_BUFFER binding point (refer
  • Page 255 ( line 4): a variety of techniques for doing this; one of the most common technique is to keep a list of should be a variety of techniques for doing this; one of the most common techniques is to keep a list of
  • Page 320 ( information tip): range for the depth values (say between 0 and 100) via should be range for the depth values (say between 0 and 1) via

Related products

Get to Know the Author

David Wolff is a professor in the computer science department at Pacific Lutheran University (PLU). He received a PhD in Physics and an MS in computer science from Oregon State University. He has been teaching computer graphics to undergraduates at PLU for over 17 years, using OpenGL.

Other books by the author

Suggestions and Feedback

Click here if you have any feedback or suggestions.

More Repositories

1

Deep-Reinforcement-Learning-Hands-On

Hands-on Deep Reinforcement Learning, published by Packt
Python
2,750
star
2

The-Kaggle-Book

Code Repository for The Kaggle Book, Published by Packt Publishing
Jupyter Notebook
2,056
star
3

Advanced-Deep-Learning-with-Keras

Advanced Deep Learning with Keras, published by Packt
Python
1,700
star
4

Hands-On-Machine-Learning-for-Algorithmic-Trading

Hands-On Machine Learning for Algorithmic Trading, published by Packt
Jupyter Notebook
1,280
star
5

Node.js-Design-Patterns-Third-Edition

Node.js Design Patterns Third Edition, published by Packt
JavaScript
1,162
star
6

Machine-Learning-for-Algorithmic-Trading-Second-Edition_Original

Machine Learning for Algorithmic Trading, Second Edition - published by Packt
Jupyter Notebook
1,083
star
7

Deep-Learning-with-Keras

Code repository for Deep Learning with Keras published by Packt
Jupyter Notebook
1,047
star
8

Deep-Reinforcement-Learning-Hands-On-Second-Edition

Deep-Reinforcement-Learning-Hands-On-Second-Edition, published by Packt
Jupyter Notebook
1,028
star
9

Learning-JavaScript-Data-Structures-and-Algorithms-Third-Edition

Learning JavaScript Data Structures and Algorithms (Third Edition), published by Packt
JavaScript
1,007
star
10

40-Algorithms-Every-Programmer-Should-Know

40 Algorithms Every Programmer Should Know, published by Packt
Python
910
star
11

Learn-CUDA-Programming

Learn CUDA Programming, published by Packt
Cuda
849
star
12

3D-Graphics-Rendering-Cookbook

3D Graphics Rendering Cookbook, published by Packt.
C++
847
star
13

Vulkan-Cookbook

Code repository for Vulkan Cookbook by Packt
C++
784
star
14

Linux-Kernel-Programming

Linux Kernel Programming, published by Packt
Makefile
759
star
15

Learn-Algorithmic-Trading

Learn Algorithmic Trading, Published by Packt
Python
730
star
16

Django-4-by-example

Django 4 by example (4th Edition) published by Packt
Python
718
star
17

Django-3-by-Example

Django 3 by Example (3rd Edition) published by Packt
Python
710
star
18

Node.js_Design_Patterns_Second_Edition_Code

Code repository for Node.js Design Patterns Second Edition, published by Packt
JavaScript
706
star
19

Python-for-Finance-Cookbook

Python for Finance Cookbook, published by Packt
Jupyter Notebook
665
star
20

Pandas-Cookbook

Pandas Cookbook, published by Packt
Jupyter Notebook
623
star
21

Hands-on-Exploratory-Data-Analysis-with-Python

Hands-on Exploratory Data Analysis with Python, published by Packt
Jupyter Notebook
619
star
22

Java-Coding-Problems

Java Coding Problems, published by Packt
Java
615
star
23

Hands-On-Domain-Driven-Design-with-.NET-Core

Hands-On Domain-Driven Design with .NET Core, published by Packt
C#
602
star
24

Modern-Computer-Vision-with-PyTorch

Modern Computer Vision with PyTorch, published by Packt
Jupyter Notebook
585
star
25

Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA

Hands-On GPU Accelerated Computer Vision with OpenCV and CUDA, published by Packt
C++
584
star
26

Django-2-by-Example

Django 2 by Example (2nd Edition) published by Packt
Python
567
star
27

Learning-OpenCV-4-Computer-Vision-with-Python-Third-Edition

Learning OpenCV 4 Computer Vision with Python 3 – Third Edition, published by Packt
Python
562
star
28

Learn-Data-Structures-and-Algorithms-with-Golang

Learn Data Structures and Algorithms with Golang, published by Packt
Go
557
star
29

Causal-Inference-and-Discovery-in-Python

Causal Inference and Discovery in Python by Packt Publishing
Jupyter Notebook
555
star
30

TensorFlow-Machine-Learning-Cookbook

Code repository for TensorFlow Machine Learning Cookbook by Packt
Python
552
star
31

Transformers-for-Natural-Language-Processing

Transformers for Natural Language Processing, published by Packt
Jupyter Notebook
539
star
32

Data-Engineering-with-Python

Data Engineering with Python, published by Packt
Python
537
star
33

Mastering-OpenCV-4-Third-Edition

Mastering OpenCV 4, Third Edition, published by Packt publishing
Assembly
520
star
34

Cpp17-STL-Cookbook

Code files by Packt
C++
514
star
35

Clean-Code-in-Python

Clean Code in Python, published by Packt
Python
513
star
36

Hands-On-Graph-Neural-Networks-Using-Python

Hands-On Graph Neural Networks Using Python, published by Packt
Jupyter Notebook
500
star
37

Getting-Started-with-TensorFlow

Getting Started with TensorFlow, published by Packt
Python
491
star
38

Hands-On-Data-Structures-and-Algorithms-with-Rust

Hands-On Data Structures and Algorithms with Rust, published by Packt
Rust
486
star
39

Linux-Device-Drivers-Development

Linux Device Drivers Development, published by Packt
C
482
star
40

Python-Machine-Learning-Second-Edition

Python Machine Learning - Second Edition, published by Packt
Jupyter Notebook
477
star
41

Mastering-Graphics-Programming-with-Vulkan

C++
469
star
42

Learn-LLVM-12

Learn LLVM 12, published by Packt
C++
465
star
43

Mastering-Embedded-Linux-Programming-Third-Edition

Mastering Embedded Linux Programming Third Edition, published by Packt
C
460
star
44

Python-3-Object-Oriented-Programming-Third-Edition

Python 3 Object-Oriented Programming – Third Edition, published by Packt
Python
453
star
45

Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud

Hands-On Microservices with Spring Boot and Spring Cloud, published by Packt
Java
452
star
46

Software-Architecture-with-Cpp

Software Architecture with C++, published by Packt
C++
447
star
47

Full-Stack-React-Projects-Second-Edition

Full-Stack React Projects - Second Edition, published by Packt
JavaScript
445
star
48

Python-Feature-Engineering-Cookbook

Python Feature Engineering Cookbook, published by Packt
Jupyter Notebook
442
star
49

Deep-Learning-with-PyTorch

Deep Learning with PyTorch, published by Packt
Jupyter Notebook
437
star
50

Interpretable-Machine-Learning-with-Python

Interpretable Machine Learning with Python, published by Packt
Jupyter Notebook
423
star
51

Python-Machine-Learning-Cookbook

Code files for Python-Machine-Learning-Cookbook
Python
416
star
52

Modern-CMake-for-Cpp

Modern CMake for C++, published by Packt
Dockerfile
411
star
53

Artificial-Intelligence-with-Python

Code repository for Artificial Intelligence with Python, published by Packt
Python
408
star
54

Hands-On-Software-Engineering-with-Golang

Hands-On Software Engineering with Golang, published by Packt
Go
406
star
55

Mastering-Python-for-Finance-Second-Edition

Mastering Python for Finance – Second Edition, published by Packt
Jupyter Notebook
394
star
56

Go-Design-Patterns

This is the code repository for the book, Go Design Patterns, published by Packt
Go
394
star
57

Mastering-Python-Design-Patterns-Second-Edition

Mastering-Python-Design-Patterns-Second-Edition, published by Packt
Python
389
star
58

Mastering-Go-Second-Edition

Mastering Go Second Edition, published by Packt
Go
384
star
59

Hands-On-Machine-Learning-with-CPP

Hands-On Machine Learning with C++, published by Packt
C++
377
star
60

Learn-OpenCV-4-By-Building-Projects-Second-Edition

Learn OpenCV 4 By Building Projects, Second Edition, published by Packt
C++
367
star
61

Hands-On-Computer-Vision-with-TensorFlow-2

Hands-On Computer Vision with TensorFlow 2, published by Packt
Jupyter Notebook
366
star
62

Mastering-OpenCV-4-with-Python

Mastering OpenCV 4 with Python, published by Packt
Python
362
star
63

Hands-On-Microservices-with-Rust

Hands-On Microservices with Rust 2018, published by Packt
Rust
354
star
64

Hands-On-Design-Patterns-with-CPP

Hands-On Design Patterns with C++, published by Packt
C
353
star
65

Python-Machine-Learning-Blueprints

Code repository for Python Machine Learning Blueprints, published by Packt
Jupyter Notebook
349
star
66

Practical-Time-Series-Analysis

Practical Time-Series Analysis, published by Packt
Jupyter Notebook
345
star
67

Machine-Learning-for-Algorithmic-Trading-Bots-with-Python

Jupyter Notebook
337
star
68

Machine-Learning-for-Finance

Machine Learning for Finance, published by Packt
Jupyter Notebook
336
star
69

Effective-Python-Penetration-Testing

Effective Python Penetration Testing by Packt Publishing
Python
334
star
70

Python-Algorithmic-Trading-Cookbook

Python Algorithmic Trading Cookbook, published by Packt
Jupyter Notebook
325
star
71

Hands-On-Intelligent-Agents-with-OpenAI-Gym

Code for Hands On Intelligent Agents with OpenAI Gym book to get started and learn to build deep reinforcement learning agents using PyTorch
Python
322
star
72

Python-Artificial-Intelligence-Projects-for-Beginners

Python Artificial Intelligence Projects for Beginners, published by Packt
Jupyter Notebook
321
star
73

Hands-On-Reactive-Programming-in-Spring-5

Hands-On Reactive Programming in Spring 5, published by Packt
Java
320
star
74

Micro-State-Management-with-React-Hooks

Micro State Management with React Hooks, published by Packt
TypeScript
317
star
75

The-Azure-Cloud-Native-Architecture-Mapbook

The Azure Cloud Native Architecture Mapbook, published by Packt
C#
315
star
76

Godot-Game-Engine-Projects

Godot Game Engine Projects, published by Packt
GDScript
315
star
77

Modern-Time-Series-Forecasting-with-Python

Modern Time Series Forecasting with Python, published by Packt
Jupyter Notebook
315
star
78

Python-GUI-Programming-Cookbook-Second-Edition

Python GUI Programming Cookbook, Second Edition, published by Packt
Python
312
star
79

Computer-Vision-with-OpenCV-3-and-Qt5

Computer Vision with OpenCV 3 and Qt5, published by Packt
C++
305
star
80

Learning-PySpark

Code repository for Learning PySpark by Packt
Jupyter Notebook
303
star
81

Deep-Learning-with-TensorFlow-2-and-Keras

Deep Learning with TensorFlow 2 and Keras, published by Packt
Jupyter Notebook
302
star
82

PyTorch-Computer-Vision-Cookbook

PyTorch Computer Vision Cookbook, Published by Packt
Jupyter Notebook
302
star
83

Mastering-Machine-Learning-for-Penetration-Testing

Mastering Machine Learning for Penetration Testing, published by Packt
Python
298
star
84

Learning-Vuejs-2

This is the code repository for Learning Vue.js 2, published by Packt.
JavaScript
296
star
85

Building-Data-Science-Applications-with-FastAPI

Building Data Science Applications with FastAPI, Published by Packt
Python
295
star
86

Mastering-Transformers

Mastering Transformers, published by Packt
Jupyter Notebook
289
star
87

Neural-Network-Projects-with-Python

Neural Network Projects with Python, Published by Packt
Python
289
star
88

Bioinformatics-with-Python-Cookbook-Second-Edition

Bioinformatics with Python Cookbook Second Edition, published by Packt
OpenEdge ABL
287
star
89

Hands-on-Python-for-Finance

Hands-on Python for Finance published by Packt.
Jupyter Notebook
284
star
90

Full-Stack-React-TypeScript-and-Node

Full-Stack React, TypeScript, and Node, published by Packt
TypeScript
282
star
91

CPP-Data-Structures-and-Algorithms

C++ Data Structures and Algorithms, published by Packt
C++
279
star
92

The-Modern-Cpp-Challenge

The Modern C++ Challenge, published by Packt
C
276
star
93

The-Complete-Coding-Interview-Guide-in-Java

The Complete Coding Interview Guide in Java, published by Packt
Java
272
star
94

Pandas-Cookbook-Second-Edition

Pandas Cookbook Second Edition, published by Packt
Jupyter Notebook
271
star
95

Full-Stack-React-Projects

Full-Stack React Projects, published by Packt
JavaScript
271
star
96

Machine-Learning-for-Cybersecurity-Cookbook

Machine Learning for Cybersecurity Cookbook, published by Packt
Jupyter Notebook
270
star
97

Natural-Language-Processing-with-TensorFlow

Natural Language Processing with TensorFlow, published by Packt
Jupyter Notebook
269
star
98

50-Projects-In-50-Days---HTML-CSS-JavaScript

50 Projects In 50 Days - HTML, CSS & JavaScript, by Packt Publishing
CSS
269
star
99

Hands-On-Image-Processing-with-Python

Jupyter Notebook
264
star
100

Mastering-Distributed-Tracing

"Mastering Distributed Tracing" by Yuri Shkuro, published by Packt
Java
264
star