Skip to content

Commit 32e9011

Browse files
committed
Initial import of private code repositories. Terse README.
1 parent 43c82f9 commit 32e9011

File tree

476 files changed

+126172
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

476 files changed

+126172
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.o
2+
*.obj
3+
*.pdb

CMakeLists.txt

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
cmake_minimum_required (VERSION 2.6)
2+
3+
project (vermilion9)
4+
5+
LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/lib )
6+
7+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
8+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
9+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
10+
11+
# Second, for multi-config builds (e.g. msvc)
12+
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
13+
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
14+
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/bin )
15+
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/lib )
16+
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/lib )
17+
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
18+
19+
set (CMAKE_DEBUG_POSTFIX "_d")
20+
21+
find_package(OpenGL REQUIRED)
22+
23+
if(WIN32)
24+
set(COMMON_LIBS vermilion ${OPENGL_LIBRARIES} optimized glfw3 debug glfw3_d)
25+
elseif (UNIX)
26+
set(COMMON_LIBS vermilion ${OPENGL_LIBRARIES} glfw ${GLFW_LIBRARIES} GL rt dl)
27+
else()
28+
set(COMMON_LIBS vermilion)
29+
endif()
30+
31+
set(COMMON_HEADERS include/vgl.h include/vapp.h)
32+
33+
set(COMMON_LIBS ${COMMON_LIBS} ${EXTRA_LIBS})
34+
35+
add_library(vermilion
36+
lib/gl3w.c
37+
lib/LoadShaders.cpp
38+
lib/targa.cpp
39+
lib/vdds.cpp
40+
lib/loadtexture.cpp
41+
lib/vermilion.cpp
42+
lib/vbm.cpp
43+
)
44+
45+
set(RUN_DIR ${PROJECT_SOURCE_DIR}/bin)
46+
47+
set(EXAMPLES
48+
01-keypress
49+
01-triangles
50+
03-drawcommands
51+
03-instancing
52+
03-instancing2
53+
03-instancing3
54+
03-pointsprites
55+
03-primitiverestart
56+
03-xfb
57+
04-gouraud
58+
04-gouraud-float
59+
04-shadowmap
60+
06-cubemap
61+
06-load-texture
62+
06-mipfilters
63+
06-multitexture
64+
06-statictexture
65+
06-texturewrapping
66+
06-volumetexturing
67+
08-lightmodels
68+
09-simpletess
69+
09-teapot
70+
10-draw-xfb
71+
10-fur
72+
10-viewport-array
73+
11-doublewrite
74+
11-oit
75+
11-overdrawcount
76+
12-imageprocessing
77+
12-particlesimulator
78+
12-raytracer
79+
12-simplecompute
80+
)
81+
82+
find_package(OpenMP)
83+
if (OPENMP_FOUND)
84+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
85+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
86+
endif()
87+
88+
foreach(EXAMPLE ${EXAMPLES})
89+
add_executable(${EXAMPLE} WIN32 src/${EXAMPLE}/${EXAMPLE}.cpp ${COMMON_HEADERS})
90+
set_property(TARGET ${EXAMPLE} PROPERTY DEBUG_POSTFIX _d)
91+
target_link_libraries(${EXAMPLE} ${COMMON_LIBS})
92+
if(MSVC)
93+
configure_file(${PROJECT_SOURCE_DIR}/build/templates/vs2013.vcxproj.user.in ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.vcxproj.user @ONLY)
94+
endif(MSVC)
95+
endforeach(EXAMPLE)
96+
97+
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
98+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LINUX")
99+
ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
100+
101+
include_directories( include )
102+
include_directories(lib/glfw/include)
103+
104+
add_subdirectory(lib/glfw)
105+
106+
ADD_CUSTOM_TARGET(debug ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR})
107+
ADD_CUSTOM_TARGET(release ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Release ${PROJECT_SOURCE_DIR})

README.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
1-
Example code for the OpenGL Programming Guide (Red Book)
2-
========================================================
1+
OpenGL Red Book Example Code
2+
============================
33

4-
Coming soon to a repository near you!
4+
This is the example code for the OpenGL Programming Guide (Red Book), 9th Edition.
5+
It is mostly an import of code from previous editions with minor updates
6+
to match some of the descriptions in the latest edition of the book.
7+
We will be adding more samples and updating existing ones over time.
8+
Treat this as a live repository. Pull requests and issues are welcome.
9+
Go forth and fork!
10+
11+
Building
12+
--------
13+
14+
We are using CMake as our build system. To build the samples, enter
15+
the "build" subdirectory and enter "cmake -G "{your generator here}" .."
16+
Project files or makefiles will be produced in the build subdirectory.
17+
We have tested Unix makefiles ("Unix Makefiles") and Visual Studio project files.
18+
Visual Studio 2013 ("Visual Studio 12") was used to develop most of the samples.
19+
An update to add support for 2015 will land shortly. Code should compile, but the
20+
templates for the project files are not in the repository at this time.
21+
Other compilers and IDEs should work, but we haven't tested them.
22+
23+
Running
24+
-------
25+
26+
Download the media pack from the download area in the repository and unpack it
27+
into the bin/media directory. This contains model files and textures used by the
28+
applications. Without this, most applications won't work and will quite possibly
29+
crash. Don't file bugs about that if you don't have the media files.
30+
Otherwise, the samples should compile and run out-of-the box. Of course, make sure your
31+
OpenGL drivers are up to date and that your hardware is capable of running OpenGL 4.5.
32+
That's what this book is about. Some systems don't support OpenGL 4.5 and will therefore
33+
not run some of the samples. Trying to run such samples on a machine that doesn't have
34+
OpenGL 4.5 support will fail. For example, if a platform were limited to, say OpenGL 4.1,
35+
then the samples wouldn't work on that platform. Please don't file bugs about that either.
36+
Error checking in these applications is minimal. If you don't have media files or if
37+
your OpenGL drivers are out of date, they'll probably fail spectacularly.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#version 430 core
2+
3+
/*
4+
* OpenGL Programming Guide - Double Write Example
5+
*/
6+
7+
// Buffer containing the rendered image
8+
layout (binding = 0, rgba32f) uniform image2D output_image;
9+
10+
// This is the output color
11+
layout (location = 0) out vec4 color;
12+
13+
void main(void)
14+
{
15+
color = vec4(imageLoad(output_image, ivec2(gl_FragCoord.xy)).xxxx) / 255.0;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#version 430 core
2+
3+
in vec4 position;
4+
5+
void main(void)
6+
{
7+
gl_Position = position;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#version 430 core
2+
3+
// Buffer containing a palette of colors to be used to mark primitives by ID
4+
layout (binding = 0, rgba32f) uniform imageBuffer colors;
5+
6+
// The buffer that we will write to
7+
layout (binding = 1, rgba32f) uniform image2D output_buffer;
8+
9+
out vec4 color;
10+
11+
void main(void)
12+
{
13+
// Load a color from the palette buffer based on primitive ID % 256
14+
vec4 col = imageLoad(colors, gl_PrimitiveID & 255);
15+
16+
// Store the resulting fragment at two locations. First at the fragments
17+
// window space coordinate shifted left...
18+
imageStore(output_buffer, ivec2(gl_FragCoord.xy) - ivec2(200, 0), col);
19+
20+
// ... then at the location shifted right
21+
imageStore(output_buffer, ivec2(gl_FragCoord.xy) + ivec2(200, 0), col);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#version 430 core
2+
3+
layout (location = 0) in vec4 position;
4+
layout (location = 1) in vec3 normal;
5+
layout (location = 2) in vec2 map1;
6+
7+
uniform mat4 model_matrix;
8+
uniform mat4 view_matrix;
9+
uniform mat4 projection_matrix;
10+
11+
uniform float aspect;
12+
uniform float time;
13+
14+
out gl_PerVertex
15+
{
16+
vec4 gl_Position;
17+
};
18+
19+
out vec4 surface_color;
20+
out vec3 frag_position;
21+
out vec3 frag_normal;
22+
23+
void main(void)
24+
{
25+
vec4 offset = vec4(float(gl_InstanceID & 3) * 2.0,
26+
float((gl_InstanceID >> 2) & 3) * 2.0,
27+
float((gl_InstanceID >> 4) & 3) * 2.0, 0.0) -
28+
vec4(4.0, 4.0, 4.0, 0.0);
29+
30+
surface_color = normalize(offset) * 0.5 + vec4(0.5, 0.5, 0.5, 0.4);
31+
32+
vec4 object_pos = (position + offset);
33+
vec4 world_pos = model_matrix * object_pos;
34+
frag_position = world_pos.xyz;
35+
frag_normal = mat3(model_matrix * view_matrix) * normal;
36+
37+
gl_Position = (projection_matrix * view_matrix) * world_pos;
38+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#version 400 core
3+
4+
in vec4 color;
5+
6+
out vec4 fColor;
7+
8+
void
9+
main()
10+
{
11+
fColor = color;
12+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#version 400 core
3+
4+
layout( location = 0 ) in vec4 vPosition;
5+
layout( location = 1 ) in vec4 vColor;
6+
7+
out vec4 color;
8+
9+
void
10+
main()
11+
{
12+
color = vColor;
13+
gl_Position = vPosition;
14+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
#version 400 core
3+
4+
out vec4 fColor;
5+
6+
void
7+
main()
8+
{
9+
fColor = vec4( 0.0, 0.0, 1.0, 1.0 );
10+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
#version 400 core
3+
4+
layout( location = 0 ) in vec4 vPosition;
5+
6+
void
7+
main()
8+
{
9+
gl_Position = vPosition;
10+
}
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#version 420 core
2+
3+
layout (early_fragment_tests) in;
4+
5+
layout (binding = 0, r32ui) uniform uimage2D head_pointer_image;
6+
layout (binding = 1, rgba32ui) uniform writeonly uimageBuffer list_buffer;
7+
8+
layout (binding = 0, offset = 0) uniform atomic_uint list_counter;
9+
10+
layout (location = 0) out vec4 color;
11+
12+
in vec3 frag_position;
13+
in vec3 frag_normal;
14+
in vec4 surface_color;
15+
16+
uniform vec3 light_position = vec3(40.0, 20.0, 100.0);
17+
18+
void main(void)
19+
{
20+
uint index;
21+
uint old_head;
22+
uvec4 item;
23+
vec4 frag_color;
24+
25+
index = atomicCounterIncrement(list_counter);
26+
27+
old_head = imageAtomicExchange(head_pointer_image, ivec2(gl_FragCoord.xy), uint(index));
28+
29+
vec3 L = normalize(light_position - frag_position);
30+
vec3 V = normalize(-frag_position);
31+
vec3 N = normalize(frag_normal);
32+
vec3 H = normalize(L + V);
33+
34+
float NdotL = dot(N, L);
35+
float NdotH = dot(N, H);
36+
37+
vec4 modulator = vec4(surface_color.rgb * abs(NdotL), surface_color.a);
38+
vec4 additive_component = mix(surface_color, vec4(1.0), 0.6) * vec4(pow(clamp(NdotH, 0.0, 1.0), 26.0)) * 0.7;
39+
40+
item.x = old_head;
41+
item.y = packUnorm4x8(modulator);
42+
item.z = floatBitsToUint(gl_FragCoord.z);
43+
item.w = packUnorm4x8(additive_component);
44+
45+
imageStore(list_buffer, int(index), item);
46+
47+
frag_color = modulator;
48+
49+
color = frag_color;
50+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#version 330
2+
3+
layout (location = 0) in vec4 position;
4+
layout (location = 1) in vec3 normal;
5+
layout (location = 2) in vec2 map1;
6+
7+
uniform mat4 model_matrix;
8+
uniform mat4 view_matrix;
9+
uniform mat4 projection_matrix;
10+
11+
uniform float aspect;
12+
uniform float time;
13+
14+
out gl_PerVertex
15+
{
16+
vec4 gl_Position;
17+
};
18+
19+
out vec4 surface_color;
20+
out vec3 frag_position;
21+
out vec3 frag_normal;
22+
23+
void main(void)
24+
{
25+
vec4 offset = vec4(float(gl_InstanceID & 7) * 2.0,
26+
float((gl_InstanceID >> 3) & 7) * 2.0,
27+
float((gl_InstanceID >> 6) & 7) * 2.0, 0.0) -
28+
vec4(8.0, 8.0, 8.0, 0.0);
29+
30+
surface_color = normalize(offset) * 0.5 + vec4(0.5, 0.5, 0.5, 0.4);
31+
32+
vec4 object_pos = (position + offset);
33+
vec4 world_pos = model_matrix * object_pos;
34+
frag_position = world_pos.xyz;
35+
frag_normal = mat3(model_matrix * view_matrix) * normal;
36+
37+
gl_Position = (projection_matrix * view_matrix) * world_pos;
38+
}

0 commit comments

Comments
 (0)