Skip to content

Commit 56bf795

Browse files
committed
Initial Load
1 parent d3b8022 commit 56bf795

21 files changed

+1745
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ $RECYCLE.BIN/
4141
Network Trash Folder
4242
Temporary Items
4343
.apdisk
44+
*.obj
45+
Debug/Shapes.Build.CppClean.log
46+
*.log
47+
Debug/Shapes.tlog/CL.command.1.tlog
48+
*.tlog
49+
Debug/vc140.idb
50+
*.pdb
51+
freeglut.dll
52+
*.dll

Shapes.vcxproj

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{49AA5F09-BD33-487F-9627-0011C0B20145}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>Shapes</RootNamespace>
25+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>Application</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v140</PlatformToolset>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v140</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>Unicode</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v140</PlatformToolset>
45+
<CharacterSet>Unicode</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v140</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
73+
<LinkIncremental>true</LinkIncremental>
74+
</PropertyGroup>
75+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
76+
<LinkIncremental>true</LinkIncremental>
77+
</PropertyGroup>
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
79+
<LinkIncremental>false</LinkIncremental>
80+
</PropertyGroup>
81+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
82+
<LinkIncremental>false</LinkIncremental>
83+
</PropertyGroup>
84+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
85+
<ClCompile>
86+
<PrecompiledHeader>
87+
</PrecompiledHeader>
88+
<WarningLevel>Level3</WarningLevel>
89+
<Optimization>Disabled</Optimization>
90+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
91+
<AdditionalIncludeDirectories>%USERPROFILE%\Documents\freeglut\include;%USERPROFILE%\Documents\glew\include;%USERPROFILE%\Documents\glm;</AdditionalIncludeDirectories>
92+
</ClCompile>
93+
<Link>
94+
<SubSystem>Console</SubSystem>
95+
<GenerateDebugInformation>true</GenerateDebugInformation>
96+
<AdditionalLibraryDirectories>%USERPROFILE%\Documents\freeglut\lib;%USERPROFILE%\Documents\glew\lib\Release\Win32;</AdditionalLibraryDirectories>
97+
<AdditionalDependencies>freeglut.lib;glew32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
98+
</Link>
99+
</ItemDefinitionGroup>
100+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
101+
<ClCompile>
102+
<PrecompiledHeader>
103+
</PrecompiledHeader>
104+
<WarningLevel>Level3</WarningLevel>
105+
<Optimization>Disabled</Optimization>
106+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
</ClCompile>
108+
<Link>
109+
<SubSystem>Console</SubSystem>
110+
<GenerateDebugInformation>true</GenerateDebugInformation>
111+
</Link>
112+
</ItemDefinitionGroup>
113+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
114+
<ClCompile>
115+
<WarningLevel>Level3</WarningLevel>
116+
<PrecompiledHeader>
117+
</PrecompiledHeader>
118+
<Optimization>MaxSpeed</Optimization>
119+
<FunctionLevelLinking>true</FunctionLevelLinking>
120+
<IntrinsicFunctions>true</IntrinsicFunctions>
121+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122+
<AdditionalIncludeDirectories>%USERPROFILE%\Documents\freeglut\include;%USERPROFILE%\Documents\glew\include;%USERPROFILE%\Documents\glm;</AdditionalIncludeDirectories>
123+
</ClCompile>
124+
<Link>
125+
<SubSystem>Console</SubSystem>
126+
<GenerateDebugInformation>true</GenerateDebugInformation>
127+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
128+
<OptimizeReferences>true</OptimizeReferences>
129+
<AdditionalLibraryDirectories>%USERPROFILE%\Documents\freeglut\lib;%USERPROFILE%\Documents\glew\lib\Release\Win32;</AdditionalLibraryDirectories>
130+
<AdditionalDependencies>freeglut.lib;glew32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
131+
</Link>
132+
</ItemDefinitionGroup>
133+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
134+
<ClCompile>
135+
<WarningLevel>Level3</WarningLevel>
136+
<PrecompiledHeader>
137+
</PrecompiledHeader>
138+
<Optimization>MaxSpeed</Optimization>
139+
<FunctionLevelLinking>true</FunctionLevelLinking>
140+
<IntrinsicFunctions>true</IntrinsicFunctions>
141+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
142+
</ClCompile>
143+
<Link>
144+
<SubSystem>Console</SubSystem>
145+
<GenerateDebugInformation>true</GenerateDebugInformation>
146+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
147+
<OptimizeReferences>true</OptimizeReferences>
148+
</Link>
149+
</ItemDefinitionGroup>
150+
<ItemGroup>
151+
<Text Include="icosphere_reference.txt" />
152+
</ItemGroup>
153+
<ItemGroup>
154+
<ClInclude Include="constant_shader.h" />
155+
<ClInclude Include="cylinder.h" />
156+
<ClInclude Include="disc.h" />
157+
<ClInclude Include="phong_shader.h" />
158+
<ClInclude Include="shader.h" />
159+
<ClInclude Include="shape.h" />
160+
</ItemGroup>
161+
<ItemGroup>
162+
<ClCompile Include="constant_shader.cpp" />
163+
<ClCompile Include="cylinder.cpp" />
164+
<ClCompile Include="disc.cpp" />
165+
<ClCompile Include="main.cpp" />
166+
<ClCompile Include="phong_shader.cpp" />
167+
<ClCompile Include="shader.cpp" />
168+
<ClCompile Include="shape.cpp" />
169+
</ItemGroup>
170+
<ItemGroup>
171+
<None Include="constant.fs.glsl" />
172+
<None Include="constant.vs.glsl" />
173+
<None Include="per-fragment-phong.fs.glsl" />
174+
<None Include="per-fragment-phong.vs.glsl" />
175+
</ItemGroup>
176+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
177+
<ImportGroup Label="ExtensionTargets">
178+
</ImportGroup>
179+
</Project>

Shapes.vcxproj.filters

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
<Filter Include="Notes">
17+
<UniqueIdentifier>{a06abfc0-aefb-4706-bd4a-b4e87c4cbb9e}</UniqueIdentifier>
18+
</Filter>
19+
<Filter Include="Shaders">
20+
<UniqueIdentifier>{5197655a-93f3-4d6e-9b5b-72f1fbc42dfb}</UniqueIdentifier>
21+
</Filter>
22+
</ItemGroup>
23+
<ItemGroup>
24+
<Text Include="icosphere_reference.txt">
25+
<Filter>Notes</Filter>
26+
</Text>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<ClCompile Include="shape.cpp">
30+
<Filter>Source Files</Filter>
31+
</ClCompile>
32+
<ClCompile Include="main.cpp">
33+
<Filter>Source Files</Filter>
34+
</ClCompile>
35+
<ClCompile Include="shader.cpp">
36+
<Filter>Source Files</Filter>
37+
</ClCompile>
38+
<ClCompile Include="disc.cpp">
39+
<Filter>Source Files</Filter>
40+
</ClCompile>
41+
<ClCompile Include="phong_shader.cpp">
42+
<Filter>Source Files</Filter>
43+
</ClCompile>
44+
<ClCompile Include="constant_shader.cpp">
45+
<Filter>Source Files</Filter>
46+
</ClCompile>
47+
<ClCompile Include="cylinder.cpp">
48+
<Filter>Source Files</Filter>
49+
</ClCompile>
50+
</ItemGroup>
51+
<ItemGroup>
52+
<ClInclude Include="shape.h">
53+
<Filter>Header Files</Filter>
54+
</ClInclude>
55+
<ClInclude Include="shader.h">
56+
<Filter>Header Files</Filter>
57+
</ClInclude>
58+
<ClInclude Include="disc.h">
59+
<Filter>Header Files</Filter>
60+
</ClInclude>
61+
<ClInclude Include="phong_shader.h">
62+
<Filter>Source Files</Filter>
63+
</ClInclude>
64+
<ClInclude Include="constant_shader.h">
65+
<Filter>Header Files</Filter>
66+
</ClInclude>
67+
<ClInclude Include="cylinder.h">
68+
<Filter>Header Files</Filter>
69+
</ClInclude>
70+
</ItemGroup>
71+
<ItemGroup>
72+
<None Include="per-fragment-phong.fs.glsl">
73+
<Filter>Shaders</Filter>
74+
</None>
75+
<None Include="per-fragment-phong.vs.glsl">
76+
<Filter>Shaders</Filter>
77+
</None>
78+
<None Include="constant.vs.glsl">
79+
<Filter>Shaders</Filter>
80+
</None>
81+
<None Include="constant.fs.glsl">
82+
<Filter>Shaders</Filter>
83+
</None>
84+
</ItemGroup>
85+
</Project>

constant.fs.glsl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#version 410 core
2+
3+
// Output
4+
layout (location = 0) out vec4 color;
5+
6+
uniform vec3 ambient;
7+
8+
void main(void)
9+
{
10+
color = vec4(ambient, 1.0);
11+
}

constant.vs.glsl

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#version 410 core
2+
3+
// Per-vertex inputs
4+
layout (location = 0) in vec4 position;
5+
6+
// Matrices we'll need
7+
layout (std140) uniform constants
8+
{
9+
mat4 mv_matrix;
10+
mat4 proj_matrix;
11+
};
12+
13+
void main(void)
14+
{
15+
gl_Position = proj_matrix * mv_matrix * position;
16+
}

constant_shader.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <iostream>
2+
#include <stdexcept>
3+
#include <assert.h>
4+
5+
#include "constant_shader.h"
6+
7+
using namespace std;
8+
using namespace glm;
9+
10+
#ifndef BAD_GL_VALUE
11+
#define BAD_GL_VALUE (GLuint(-1))
12+
#endif // !BAD_GL_VALUE
13+
14+
void ConstantShader::Use(mat4 &model_matrix, mat4 &view_matrix, mat4 &projection_matrix)
15+
{
16+
this->GLReturnedError("ConstantShader::Use() - entering");
17+
Shader::Use();
18+
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this->uniforms_buffer);
19+
uniforms_block * block = (uniforms_block *) glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT);
20+
block->mv_matrix = view_matrix * model_matrix;
21+
block->proj_matrix = projection_matrix;
22+
// glUnmapBuffer(GL_UNIFORM_BUFFER);
23+
this->GLReturnedError("ConstantShader::Use() - exiting");
24+
}
25+
26+
void ConstantShader::UnUse()
27+
{
28+
this->GLReturnedError("ConstantShader::UnUse() - entering");
29+
glUnmapBuffer(GL_UNIFORM_BUFFER);
30+
Shader::UnUse();
31+
this->GLReturnedError("ConstantShader::UnUse() - exiting");
32+
}
33+
34+
void ConstantShader::CustomSetup()
35+
{
36+
glGenBuffers(1, &this->uniforms_buffer);
37+
glBindBuffer(GL_UNIFORM_BUFFER, this->uniforms_buffer);
38+
glBufferData(GL_UNIFORM_BUFFER, sizeof(uniforms_block), NULL, GL_DYNAMIC_DRAW);
39+
40+
Shader::Use();
41+
uniforms.ambient = glGetUniformLocation(this->program_id, "ambient");
42+
if (uniforms.ambient == BAD_GL_VALUE)
43+
throw std::exception("one or more of the uniforms in the phong shader was not found");
44+
Shader::UnUse();
45+
}
46+
47+
void ConstantShader::SetMaterial(glm::vec3 & ambient)
48+
{
49+
assert(this->is_used == true);
50+
glUniform3fv(uniforms.ambient, 1, (GLfloat *)(&ambient));
51+
}

constant_shader.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include "shader.h"
3+
4+
// Portions lifted from OpenGL SuperBible 7th Edition.
5+
6+
class ConstantShader : public Shader
7+
{
8+
public:
9+
void Use(glm::mat4 &model_matrix, glm::mat4 &view_matrix, glm::mat4 &projection_matrix);
10+
void UnUse();
11+
void SetMaterial(glm::vec3 & ambient);
12+
void CustomSetup();
13+
14+
private:
15+
GLuint uniforms_buffer;
16+
17+
struct uniforms_block
18+
{
19+
glm::mat4 mv_matrix;
20+
glm::mat4 proj_matrix;
21+
};
22+
23+
struct
24+
{
25+
GLuint ambient;
26+
} uniforms;
27+
};

0 commit comments

Comments
 (0)