Initial commit with codes from labs

This commit is contained in:
Mateusz Drewniak 2021-12-27 21:29:18 +01:00
parent 2491362607
commit 59301e15eb
166 changed files with 44722 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
dependencies
*.log
Debug
Release
*.dll

112
cw 2/grk-cw2.vcxproj Executable file
View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_color.frag" />
<None Include="shaders\shader_color.vert" />
<None Include="shaders\shader_tex.frag" />
<None Include="shaders\shader_tex.vert" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main_2_1a.cpp" />
<ClCompile Include="src\Render_Utils.cpp" />
<ClCompile Include="src\Shader_Loader.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Camera.h" />
<ClInclude Include="src\Render_Utils.h" />
<ClInclude Include="src\Shader_Loader.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B4031E08-6274-4FFD-B41C-F8EA29E977FB}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>grk-cw9</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>grk-cw2</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp\Release;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlibd.lib;assimp-vc141-mtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlib.lib;assimp-vc141-mt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

62
cw 2/grk-cw2.vcxproj.filters Executable file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Shader Files">
<UniqueIdentifier>{0a247bb8-2e8e-4a90-b0ef-17415b0941ba}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_color.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_color.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_tex.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_tex.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Shader_Loader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Box.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Render_Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\main_2_1a.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Shader_Loader.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Camera.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Render_Utils.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

4
cw 2/grk-cw2.vcxproj.user Executable file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

315
cw 2/models/spaceship.obj Executable file
View File

@ -0,0 +1,315 @@
# Blender v2.90.0 OBJ File: 'spaceship.blend'
# www.blender.org
mtllib spaceship.mtl
o spaceship
v -0.466043 -0.046099 0.061004
v -0.496632 -0.038727 -0.744142
v -0.284772 -0.093266 -0.411636
v -0.169612 -0.147446 -0.381196
v -0.169612 -0.147446 0.061004
v -0.091309 -0.100093 0.472421
v -0.182617 -0.069341 0.472421
v -0.182617 -0.001722 0.472421
v -0.466043 0.045632 0.061004
v -0.647568 0.071442 -0.238048
v -0.169612 0.164038 0.061004
v -0.284772 0.045632 -0.411636
v -0.169612 0.116537 -0.381196
v -0.053437 -0.049075 0.720448
v -0.053437 -0.102143 0.720448
v -0.040834 -0.049075 0.734564
v -0.040834 -0.102143 0.734564
v 0.000000 -0.049075 0.744142
v 0.000000 -0.118734 0.744142
v 0.040834 -0.049075 0.734564
v 0.000000 0.045779 0.472421
v 0.000000 -0.116684 0.472421
v 0.091309 -0.100093 0.472421
v 0.040834 -0.102143 0.734564
v 0.000000 0.116537 -0.350755
v 0.000000 0.164038 0.061004
v 0.169612 -0.147446 -0.381196
v 0.000000 -0.164038 -0.350755
v 0.169612 0.164038 0.061004
v 0.169612 0.116537 -0.381196
v 0.000000 -0.164038 0.061004
v 0.169612 -0.147446 0.061004
v -0.647568 -0.038727 -0.238048
v -0.496632 0.071442 -0.744142
v -0.091309 0.045779 0.472421
v 0.466043 -0.046099 0.061004
v 0.647568 0.071442 -0.238048
v 0.466043 0.045632 0.061004
v 0.496632 -0.038727 -0.744142
v 0.647568 -0.038727 -0.238048
v 0.284772 -0.093266 -0.411636
v 0.182617 -0.001722 0.472421
v 0.182617 -0.069341 0.472421
v 0.284772 0.045632 -0.411636
v 0.053437 -0.049075 0.720448
v 0.053437 -0.102143 0.720448
v 0.496632 0.071442 -0.744142
v 0.091309 0.045779 0.472421
vt 0.542758 0.543965
vt 0.356004 0.244407
vt 0.504680 0.319696
vt 0.553316 0.302407
vt 0.649859 0.471001
vt 0.766053 0.611338
vt 0.733075 0.633795
vt 0.942531 0.273938
vt 0.916601 0.470616
vt 0.908930 0.272020
vt 0.906245 0.133229
vt 0.060793 0.659810
vt 0.095301 0.442790
vt 0.182444 0.620892
vt 0.912119 0.905444
vt 0.989612 0.943366
vt 0.900946 0.955153
vt 0.229586 0.822972
vt 0.045790 0.812939
vt 0.871970 0.876051
vt 0.270733 0.797357
vt 0.928563 0.581569
vt 0.948002 0.582679
vt 0.928200 0.588981
vt 0.833604 0.696984
vt 0.841128 0.699424
vt 0.941370 0.472030
vt 0.927606 0.601110
vt 0.953122 0.602566
vt 0.116239 0.298971
vt 0.134935 0.296266
vt 0.170287 0.416872
vt 0.947639 0.590091
vt 0.858040 0.692927
vt 0.798664 0.589407
vt 1.000000 0.000000
vt 0.975078 0.013585
vt 0.974484 0.001457
vt 0.830416 0.568707
vt 0.869911 0.680359
vt 0.785184 0.955792
vt 0.850736 0.970525
vt 0.334379 0.757520
vt 0.252163 0.593452
vt 0.740866 0.846584
vt 0.807753 0.855379
vt 0.321881 0.566013
vt 0.410170 0.742478
vt 0.620171 0.273802
vt 0.672876 0.223217
vt 0.710068 0.430790
vt 0.769418 0.391811
vt 0.946599 0.135534
vt 0.413299 0.472597
vt 0.208789 0.994633
vt 0.953122 0.002304
vt 0.980750 0.982793
vt 0.912767 0.000000
vt 0.101366 0.309478
vt 0.132755 0.431644
vt 0.099001 0.317265
vt 0.989409 0.328628
vt 0.953122 0.469337
vt 0.955808 0.330547
vt 0.871271 0.326374
vt 0.706080 0.012535
vt 0.869769 0.170254
vt 0.705415 0.186739
vt 0.963479 0.131951
vt 0.988248 0.130536
vt 0.443922 0.509019
vt 0.463695 0.730833
vt 0.578150 0.603414
vt 0.692001 0.855970
vt 0.680828 0.905679
vt 0.605734 0.857085
vt 0.719632 0.941058
vt 0.975441 0.020998
vt 0.994879 0.019888
vt 0.142931 0.299975
vt 0.245429 0.383703
vt 0.994516 0.012475
vt 0.871271 0.672035
vt 0.861802 0.548533
vt 0.993477 0.467033
vt 1.000000 0.600262
vt 0.959645 0.602566
vt 0.617066 0.833945
vt 0.596872 0.896513
vt 0.207819 0.402100
vn -0.2502 -0.9682 0.0006
vn -0.3235 -0.9462 -0.0000
vn -0.3158 -0.9343 0.1651
vn -0.3186 -0.9329 0.1677
vn -0.3148 -0.9349 0.1641
vn -0.8235 0.0000 0.5673
vn -0.8548 0.0000 0.5189
vn -0.3487 0.8731 0.3407
vn 0.8434 0.0000 -0.5374
vn -0.4103 -0.9095 -0.0666
vn 0.0862 0.9958 0.0321
vn 0.0832 0.9962 0.0257
vn 0.0868 0.9957 0.0333
vn 0.2556 0.0000 -0.9668
vn -0.5043 0.8586 -0.0922
vn -0.8869 0.0000 0.4619
vn -0.7459 0.0000 0.6660
vn 0.0112 -0.9999 -0.0100
vn -0.2284 0.0000 0.9736
vn 0.0771 0.9413 0.3286
vn -0.1788 -0.9839 -0.0074
vn 0.2284 0.0000 0.9736
vn 0.3892 -0.9187 0.0677
vn 0.1766 0.0000 -0.9843
vn 0.0000 0.9934 -0.1146
vn -0.1766 0.0000 -0.9843
vn -0.0192 0.9941 -0.1068
vn 0.0974 -0.9952 -0.0000
vn -0.0974 -0.9952 -0.0000
vn -0.0965 -0.9866 0.1319
vn 0.1776 -0.9776 0.1125
vn -0.0272 -0.9996 -0.0081
vn 0.0827 0.9963 0.0247
vn -0.9583 -0.0000 -0.2858
vn -0.3892 -0.9187 0.0677
vn 0.0000 0.9403 0.3403
vn -0.4230 0.8237 0.3776
vn -0.4240 0.8230 0.3780
vn -0.4228 0.8239 0.3775
vn 0.0192 0.9941 -0.1068
vn -0.3672 0.9194 -0.1408
vn 0.0000 0.9611 0.2763
vn -0.4366 0.8392 0.3243
vn -0.3189 -0.9328 0.1681
vn -0.4270 0.8209 0.3792
vn -0.0771 0.9413 0.3286
vn -0.1776 -0.9776 0.1125
vn 0.1788 -0.9839 -0.0074
vn -0.3189 -0.9469 0.0409
vn 0.8548 -0.0000 0.5189
vn 0.0272 -0.9996 -0.0081
vn 0.4103 -0.9095 -0.0666
vn 0.3158 -0.9343 0.1651
vn 0.3186 -0.9329 0.1677
vn 0.3189 -0.9328 0.1681
vn 0.8235 0.0000 0.5673
vn 0.3672 0.9194 -0.1408
vn -0.0868 0.9957 0.0333
vn -0.0832 0.9962 0.0257
vn -0.0862 0.9958 0.0321
vn 0.2502 -0.9682 0.0006
vn -0.2556 0.0000 -0.9668
vn -0.8434 0.0000 -0.5374
vn 0.7459 0.0000 0.6660
vn 0.4228 0.8239 0.3775
vn 0.4240 0.8230 0.3780
vn 0.4230 0.8237 0.3776
vn 0.3189 -0.9469 0.0409
vn 0.8869 0.0000 0.4619
vn 0.9583 -0.0000 -0.2858
vn -0.0827 0.9963 0.0247
vn -0.0112 -0.9999 -0.0100
vn 0.4270 0.8209 0.3792
vn 0.5043 0.8586 -0.0922
vn 0.3487 0.8731 0.3407
vn 0.3235 -0.9462 -0.0000
vn 0.0965 -0.9866 0.1319
vn 0.4366 0.8392 0.3243
vn 0.3148 -0.9349 0.1641
usemtl cube1_auv
s 1
f 1/1/1 2/2/1 3/3/1
f 1/1/2 4/4/2 5/5/2
f 1/1/3 6/6/4 7/7/5
f 1/8/6 8/9/6 9/10/6
f 9/10/7 10/11/7 1/8/7
f 9/12/8 8/13/8 11/14/8
f 3/15/9 2/16/9 12/17/9
f 3/3/10 4/4/10 1/1/10
f 12/18/11 10/19/12 9/12/13
f 12/17/14 4/20/14 3/15/14
f 12/18/15 11/14/15 13/21/15
f 14/22/16 8/9/16 15/23/16
f 15/23/17 16/24/17 14/22/17
f 15/25/18 6/6/18 17/26/18
f 15/23/16 8/9/16 7/27/16
f 18/28/19 16/24/19 19/29/19
f 18/30/20 20/31/20 21/32/20
f 19/29/19 16/24/19 17/33/19
f 19/34/21 6/6/21 22/35/21
f 19/36/22 20/37/22 18/38/22
f 19/34/23 23/39/23 24/40/23
f 25/41/24 4/20/24 13/42/24
f 25/43/25 11/14/25 26/44/25
f 25/41/26 27/45/26 28/46/26
f 25/43/27 29/47/27 30/48/27
f 28/46/24 4/20/24 25/41/24
f 28/49/28 27/50/28 31/51/28
f 26/44/25 29/47/25 25/43/25
f 31/51/29 4/4/29 28/49/29
f 31/51/30 6/6/30 5/5/30
f 31/51/28 27/50/28 32/52/28
f 31/51/31 23/39/31 22/35/31
f 33/53/7 1/8/7 10/11/7
f 33/54/32 2/2/32 1/1/32
f 10/19/12 12/18/11 34/55/33
f 10/11/34 2/56/34 33/53/34
f 34/57/9 12/17/9 2/16/9
f 34/58/34 2/56/34 10/11/34
f 17/33/17 16/24/17 15/23/17
f 17/26/35 6/6/35 19/34/35
f 16/59/36 21/32/36 35/60/36
f 16/59/37 8/13/38 14/61/39
f 13/42/14 4/20/14 12/17/14
f 13/21/40 11/14/40 25/43/40
f 11/14/41 12/18/41 9/12/41
f 11/14/42 21/32/42 26/44/42
f 11/14/43 8/13/43 35/60/43
f 5/5/29 4/4/29 31/51/29
f 5/5/44 6/6/4 1/1/3
f 35/60/42 21/32/42 11/14/42
f 35/60/45 8/13/38 16/59/37
f 21/32/46 16/59/46 18/30/46
f 21/32/42 29/47/42 26/44/42
f 22/35/47 6/6/47 31/51/47
f 22/35/48 23/39/48 19/34/48
f 7/7/49 6/6/49 15/25/49
f 7/27/6 8/9/6 1/8/6
f 36/62/50 37/63/50 38/64/50
f 36/65/51 39/66/51 40/67/51
f 36/65/52 27/50/52 41/68/52
f 36/65/53 23/39/54 32/52/55
f 36/62/56 42/69/56 43/70/56
f 38/71/57 44/72/57 29/47/57
f 38/71/58 37/73/59 44/72/60
f 38/64/56 42/69/56 36/62/56
f 41/68/61 39/66/61 36/65/61
f 41/74/62 27/45/62 44/75/62
f 44/75/63 39/76/63 41/74/63
f 44/75/62 27/45/62 30/77/62
f 45/78/64 20/37/64 46/79/64
f 45/80/65 42/81/66 20/31/67
f 46/79/64 20/37/64 24/82/64
f 46/83/68 23/39/68 43/84/68
f 46/79/69 42/69/69 45/78/69
f 40/85/70 39/86/70 37/63/70
f 37/63/50 36/62/50 40/85/50
f 37/63/70 39/86/70 47/87/70
f 47/88/71 44/72/60 37/73/59
f 39/76/63 44/75/63 47/89/63
f 24/82/22 20/37/22 19/36/22
f 24/40/72 23/39/72 46/83/72
f 20/31/67 42/81/66 48/90/73
f 30/77/26 27/45/26 25/41/26
f 30/48/74 29/47/74 44/72/74
f 29/47/42 21/32/42 48/90/42
f 29/47/75 42/81/75 38/71/75
f 32/52/76 27/50/76 36/65/76
f 32/52/77 23/39/77 31/51/77
f 48/90/36 21/32/36 20/31/36
f 48/90/78 42/81/78 29/47/78
f 43/84/79 23/39/54 36/65/53
f 43/70/69 42/69/69 46/79/69

2500
cw 2/models/sphere.obj Executable file

File diff suppressed because it is too large Load Diff

7
cw 2/render.py Executable file
View File

@ -0,0 +1,7 @@
import os
rootdir = './'
for filename in os.listdir(rootdir):
if filename.endswith(".md"):
name = filename[:-3]
os.system(f'pandoc -s -o {name}.html {name}.md --css style.css')

8
cw 2/shaders/shader_2_1.frag Executable file
View File

@ -0,0 +1,8 @@
#version 430 core
in vec4 color;
void main()
{
gl_FragColor = color;
}

14
cw 2/shaders/shader_2_1.vert Executable file
View File

@ -0,0 +1,14 @@
#version 430 core
layout(location = 0) in vec4 vertexPosition;
layout(location = 1) in vec4 vertexColor;
uniform mat4 transformation;
out vec4 color;
void main()
{
color = vertexColor;
gl_Position = transformation * vertexPosition;
}

16
cw 2/shaders/shader_2_1b.frag Executable file
View File

@ -0,0 +1,16 @@
#version 430 core
out vec4 fragColor;
in float hue;
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main()
{
fragColor = vec4(hsv2rgb(vec3(hue,1,1)), 1.0);
}

11
cw 2/shaders/shader_2_1b.vert Executable file
View File

@ -0,0 +1,11 @@
#version 430 core
layout(location = 0) in vec4 vertexPosition;
layout(location = 1) in float vertexHue;
out float hue;
void main()
{
hue = vertexHue;
gl_Position = vertexPosition;
}

6
cw 2/shaders/shader_2_2.frag Executable file
View File

@ -0,0 +1,6 @@
#version 430 core
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

12
cw 2/shaders/shader_2_2.vert Executable file
View File

@ -0,0 +1,12 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec2 vertexTexCoord;
layout(location = 2) in vec3 vertexNormal;
uniform mat4 transformation;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

6
cw 2/shaders/shader_2_3.frag Executable file
View File

@ -0,0 +1,6 @@
#version 430 core
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

13
cw 2/shaders/shader_2_3.vert Executable file
View File

@ -0,0 +1,13 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec2 vertexTexCoord;
layout(location = 2) in vec3 vertexNormal;
uniform mat4 transformation;
uniform mat4 model;
void main()
{
gl_Position = transformation * model * vec4(vertexPosition, 1.0);
}

104
cw 2/src/Box.cpp Executable file
View File

@ -0,0 +1,104 @@
// dane 36 wierzcholkow i kolorow opisujace model pudelka
const float boxPositions[] = {
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
};
const float boxColors[] = {
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
};

32
cw 2/src/Camera.cpp Executable file
View File

@ -0,0 +1,32 @@
#include "Camera.h"
glm::mat4 Core::createPerspectiveMatrix(float zNear, float zFar)
{
const float frustumScale = 1.0f;
glm::mat4 perspective;
perspective[0][0] = frustumScale;
perspective[1][1] = frustumScale;
perspective[2][2] = (zFar + zNear) / (zNear - zFar);
perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
perspective[2][3] = -1;
perspective[3][3] = 0;
return perspective;
}
glm::mat4 Core::createViewMatrix( glm::vec3 position, glm::vec3 forward, glm::vec3 up )
{
glm::vec3 side = glm::cross(forward, up);
// Trzeba pamietac o minusie przy ustawianiu osi Z kamery.
// Wynika to z tego, ze standardowa macierz perspektywiczna zaklada, ze "z przodu" jest ujemna (a nie dodatnia) czesc osi Z.
glm::mat4 cameraRotation;
cameraRotation[0][0] = side.x; cameraRotation[1][0] = side.y; cameraRotation[2][0] = side.z;
cameraRotation[0][1] = up.x; cameraRotation[1][1] = up.y; cameraRotation[2][1] = up.z;
cameraRotation[0][2] = -forward.x; cameraRotation[1][2] = -forward.y; cameraRotation[2][2] = -forward.z;
glm::mat4 cameraTranslation;
cameraTranslation[3] = glm::vec4(-position, 1.0f);
return cameraRotation * cameraTranslation;
}

14
cw 2/src/Camera.h Executable file
View File

@ -0,0 +1,14 @@
#pragma once
#include "glm.hpp"
namespace Core
{
glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f);
// position - pozycja kamery
// forward - wektor "do przodu" kamery (jednostkowy)
// up - wektor "w gore" kamery (jednostkowy)
// up i forward musza byc ortogonalne!
glm::mat4 createViewMatrix(glm::vec3 position, glm::vec3 forward, glm::vec3 up);
}

21
cw 2/src/Render_Utils.cpp Executable file
View File

@ -0,0 +1,21 @@
#include "Render_Utils.h"
#include <algorithm>
#include "glew.h"
#include "freeglut.h"
void Core::DrawContext(Core::RenderContext& context)
{
glBindVertexArray(context.vertexArray);
glDrawElements(
GL_TRIANGLES, // mode
context.size, // count
GL_UNSIGNED_SHORT, // type
(void*)0 // element array buffer offset
);
glBindVertexArray(0);
}

68
cw 2/src/Render_Utils.h Executable file
View File

@ -0,0 +1,68 @@
#pragma once
#include "glm.hpp"
#include "glew.h"
//#include "objload.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <vector>
#include <iostream>
#define BUFFER_OFFSET(i) ((void*)(i))
namespace Core
{
struct RenderContext {
GLuint vertexArray;
GLuint vertexBuffer;
GLuint vertexIndexBuffer;
unsigned int size = 0;
void initFromAiMesh(aiMesh* mesh) {
vertexArray = 0;
vertexBuffer = 0;
vertexIndexBuffer = 0;
std::vector<float> textureCoord;
std::vector<unsigned int> indices;
//tex coord must be converted to 2d vecs
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
if (mesh->mTextureCoords[0] != nullptr) {
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
}
else {
textureCoord.push_back(0.0f);
textureCoord.push_back(0.0f);
}
}
if (mesh->mTextureCoords[0] == nullptr) {
std::cout << "no uv coords\n";
}
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
// retrieve all indices of the face and store them in the indices vector
for (unsigned int j = 0; j < face.mNumIndices; j++)
indices.push_back(face.mIndices[j]);
}
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
}
~RenderContext() {
glDeleteBuffers(1, &vertexBuffer);
glDeleteBuffers(1, &vertexIndexBuffer);
glDeleteVertexArrays(1, &vertexArray);
}
};
void DrawContext(RenderContext& context);
}

102
cw 2/src/Shader_Loader.cpp Executable file
View File

@ -0,0 +1,102 @@
#include "Shader_Loader.h"
#include<iostream>
#include<fstream>
#include<vector>
using namespace Core;
Shader_Loader::Shader_Loader(void){}
Shader_Loader::~Shader_Loader(void){}
std::string Shader_Loader::ReadShader(char *filename)
{
std::string shaderCode;
std::ifstream file(filename, std::ios::in);
if (!file.good())
{
std::cout << "Can't read file " << filename << std::endl;
std::terminate();
}
file.seekg(0, std::ios::end);
shaderCode.resize((unsigned int)file.tellg());
file.seekg(0, std::ios::beg);
file.read(&shaderCode[0], shaderCode.size());
file.close();
return shaderCode;
}
GLuint Shader_Loader::CreateShader(GLenum shaderType, std::string
source, char* shaderName)
{
int compile_result = 0;
GLuint shader = glCreateShader(shaderType);
const char *shader_code_ptr = source.c_str();
const int shader_code_size = source.size();
glShaderSource(shader, 1, &shader_code_ptr, &shader_code_size);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result);
//sprawdz bledy
if (compile_result == GL_FALSE)
{
int info_log_length = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);
std::vector<char> shader_log(info_log_length);
glGetShaderInfoLog(shader, info_log_length, NULL, &shader_log[0]);
std::cout << "ERROR compiling shader: " << shaderName << std::endl << &shader_log[0] << std::endl;
return 0;
}
return shader;
}
GLuint Shader_Loader::CreateProgram(char* vertexShaderFilename,
char* fragmentShaderFilename)
{
//wczytaj shadery
std::string vertex_shader_code = ReadShader(vertexShaderFilename);
std::string fragment_shader_code = ReadShader(fragmentShaderFilename);
GLuint vertex_shader = CreateShader(GL_VERTEX_SHADER, vertex_shader_code, "vertex shader");
GLuint fragment_shader = CreateShader(GL_FRAGMENT_SHADER, fragment_shader_code, "fragment shader");
int link_result = 0;
//stworz shader
GLuint program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &link_result);
//sprawdz bledy w linkerze
if (link_result == GL_FALSE)
{
int info_log_length = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);
std::vector<char> program_log(info_log_length);
glGetProgramInfoLog(program, info_log_length, NULL, &program_log[0]);
std::cout << "Shader Loader : LINK ERROR" << std::endl << &program_log[0] << std::endl;
return 0;
}
glDetachShader(program, vertex_shader);
glDetachShader(program, fragment_shader);
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
return program;
}
void Shader_Loader::DeleteProgram( GLuint program )
{
glDeleteProgram(program);
}

29
cw 2/src/Shader_Loader.h Executable file
View File

@ -0,0 +1,29 @@
#pragma once
#include "glew.h"
#include "freeglut.h"
#include <iostream>
namespace Core
{
class Shader_Loader
{
private:
std::string ReadShader(char *filename);
GLuint CreateShader(GLenum shaderType,
std::string source,
char* shaderName);
public:
Shader_Loader(void);
~Shader_Loader(void);
GLuint CreateProgram(char* VertexShaderFilename,
char* FragmentShaderFilename);
void DeleteProgram(GLuint program);
};
}

122
cw 2/src/main_2_1a.cpp Executable file
View File

@ -0,0 +1,122 @@
#include "glew.h"
#include "freeglut.h"
#include "glm.hpp"
#include "ext.hpp"
#include <iostream>
#include <cmath>
#include "Shader_Loader.h"
#include "Render_Utils.h"
#include "Box.cpp"
GLuint program;
Core::Shader_Loader shaderLoader;
unsigned int VAO;
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
// ZADANIE: W zalaczonym wyzej pliku Box.cpp znajduja sie tablice pozycji i kolorow wierzcholkow prostopadloscianu. Przesun go o wektor (0.5, 0.5, -0.2) i wyswietl go.
//
// Do shadera uzytego w tym zadaniu nalezy przeslac nie tylko pozycje, ale rowniez kolory wierzcholkow.
// W funkcji init należy przesłać pozycje i kolory do GPU
glUseProgram(program);
// Powiąż stworzone VAO za pomocą funkcji glBindVertexArray
// wykorzystaj glDrawArrays do narysowania prostopadłościanu
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glm::mat4 transformation;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUseProgram(0);
glutSwapBuffers();
}
unsigned int VBO;
void init()
{
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_2_1.vert", "shaders/shader_2_1.frag");
// Dokładny opis działania funkcji z poniższych punktów można znaleźć na slajdach z wykładu, w dokumentacji https://www.khronos.org/registry/OpenGL-Refpages/gl4/ funkcje są opisane także na stronach https://learnopengl.com/Getting-started/Hello-Triangle oraz https://open.gl/drawing
// Zainicjalizuj VertexArrayObject (VAO) i zapisz w nim atrybuty prostopadłościanu
// I Stwórz VAO
// 1. Stwórz nowy VAO za pomocą glGenVertexArrays i przypisz jego adres do zmiennej globalnej
glGenVertexArrays(1, &VAO);
// 2. Powiąż stworzone VAO za pomocą funkcji glBindVertexArray
glBindVertexArray(VAO);
// II Zainicjalizuj VBO
// 3. Stwórz VertexBufferObject do przechowywania pozycji wierzchołków za pomocą funkcji glGenBuffers
glGenBuffers(1, &VBO);
// 4. Powiąż stworzone VBO za pomocą funkcji glBindBuffer(GLenum target, GLuint )
glBindBuffer(GL_ARRAY_BUFFER, VBO);
// 5. Zaalokuj w GPU miejsce na tablice wierzchołków i kolorów za pomocą glBufferData pamiętaj, żeby zaalokować dość miejsca dla punktów i kolorów
glBufferData(GL_ARRAY_BUFFER, sizeof(boxPositions), boxPositions, GL_STATIC_DRAW);
// III Prześlij dane do karty graficznej
// A) Prześlij pozycję wierzchołków do karty graficznej
// 6. Aktywuj atrybut powiązany z pozycją wierchołków za pomocą glEnableVertexAttribArray(GLuint index). Indeks jest zapisany w shaderze wierzchołków w 3. lini. Można odpytać shader o indeks za pomocą funkcji glGetAttribLocation(GL uint program, const GLchar *name)
glEnableVertexAttribArray(0);
// 7. Przekaż dane za pomocą glBufferSubData
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(boxPositions), boxPositions);
// 8. Zdefiniuj jak OpenGL powinien interpretować dane za pomocą glVertexAttribPointer
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
// B) powtórz punkty 6-8 by przesłać wartości odpowiadające za kolor
glEnableVertexAttribArray(1);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(boxColors), boxColors);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)sizeof(float));
// 9. Uwolnij VAO za pomocą funkcji glBindVertexArray(0)
glBindVertexArray(0);
}
void shutdown()
{
shaderLoader.DeleteProgram(program);
}
void idle()
{
glutPostRedisplay();
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 200);
glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Pierwszy Program");
glewInit();
init();
glutDisplayFunc(renderScene);
glutIdleFunc(idle);
glutMainLoop();
shutdown();
return 0;
}

85
cw 2/src/main_2_1b.cpp Executable file
View File

@ -0,0 +1,85 @@
#include "glew.h"
#include "freeglut.h"
#include "glm.hpp"
#include "ext.hpp"
#include <iostream>
#include <cmath>
#include "Shader_Loader.h"
#include "Render_Utils.h"
#include "Box.cpp"
float points[] = {
0.0f,1.0f,0.f,1.f,
0.7818314824680298f,0.6234898018587336f,0.f,1.f,
0.9749279121818236f,-0.22252093395631434f,0.f,1.f,
0.43388373911755823f,-0.900968867902419f,0.f,1.f,
-0.433883739117558f,-0.9009688679024191f,0.f,1.f,
-0.9749279121818236f,-0.2225209339563146f,0.f,1.f,
-0.7818314824680299f,0.6234898018587334f,0.f,1.f,
};
float hues[] = {
0.0, 0.7142857142857143, 0.42857142857142855, 0.14285714285714285, 0.8571428571428571, 0.5714285714285714, 0.2857142857142857
};
GLuint program;
Core::Shader_Loader shaderLoader;
unsigned int VAO;
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
// ZADANIE: Powyżej w tablicy points znajdują się wierzchołki 7-kąta foremnego, zadanie polega na narysowaniu gwiazdy siedmioramiennej jak na obrazku zad1b.jpg. Do shadera należy przesłać pozycje wierzchołków i ich odcienie z tablicy hues podobnie jak w zadaniu 1a.
// Idealnie rozwiązane zadanie wymaga użycia indeksowania z użyciem Element Buffer Objects oraz trybu rysowania GL_LINE_STRIP
// (dodatkowe) Jedna krawędź przechodzi przez wszystkie odcienie zamiast z czerwonego do magenty. Co to powoduje? W jaki sposób byś to naprawił?
glUseProgram(program);
glUseProgram(0);
glutSwapBuffers();
}
void init()
{
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_2_1b.vert", "shaders/shader_2_1b.frag");
}
void shutdown()
{
shaderLoader.DeleteProgram(program);
}
void idle()
{
glutPostRedisplay();
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 200);
glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Pierwszy Program");
glewInit();
init();
glutDisplayFunc(renderScene);
glutIdleFunc(idle);
glutMainLoop();
shutdown();
return 0;
}

119
cw 2/src/main_2_2.cpp Executable file
View File

@ -0,0 +1,119 @@
#include "glew.h"
#include "freeglut.h"
#include "glm.hpp"
#include "ext.hpp"
#include <iostream>
#include <cmath>
#include "Shader_Loader.h"
#include "Render_Utils.h"
#include "Camera.h"
#include "Box.cpp"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
GLuint program;
Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext sphereContext;
float cameraAngle = 0;
glm::vec3 cameraPos = glm::vec3(-5, 0, 0);
glm::vec3 cameraDir;
void keyboard(unsigned char key, int x, int y)
{
float angleSpeed = 0.1f;
float moveSpeed = 0.1f;
switch(key)
{
case 'a': cameraAngle -= angleSpeed; break;
case 'd': cameraAngle += angleSpeed; break;
case 'w': cameraPos += cameraDir * moveSpeed; break;
case 's': cameraPos -= cameraDir * moveSpeed; break;
}
}
glm::mat4 createCameraMatrix()
{
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
glm::vec3 up = glm::vec3(0,1,0);
return Core::createViewMatrix(cameraPos, cameraDir, up);
}
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
glUseProgram(program);
glm::mat4 camera = createCameraMatrix();
glm::mat4 perspective = Core::createPerspectiveMatrix();
glm::mat4 transformation = perspective * camera;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUseProgram(0);
glutSwapBuffers();
}
void init()
{
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_2_2.vert", "shaders/shader_2_2.frag");
}
void shutdown()
{
shaderLoader.DeleteProgram(program);
}
void loadModelToContext(std::string path,Core::RenderContext& context)
{
Assimp::Importer import;
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
{
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
return;
}
}
void idle()
{
glutPostRedisplay();
}
int main(int argc, char ** argv)
{
loadModelToContext(".\\models\\spaceship.obj", sphereContext);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 200);
glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Pierwszy Program");
glewInit();
init();
glutKeyboardFunc(keyboard);
glutDisplayFunc(renderScene);
glutIdleFunc(idle);
glutMainLoop();
shutdown();
return 0;
}

107
cw 2/style.css Executable file
View File

@ -0,0 +1,107 @@
html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
body{
color:#444;
font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
font-size:12px;
line-height:1.5em;
padding:1em;
margin:auto;
max-width:42em;
background:#fefefe;
}
a{ color: #0645ad; text-decoration:none;}
a:visited{ color: #0b0080; }
a:hover{ color: #06e; }
a:active{ color:#faa700; }
a:focus{ outline: thin dotted; }
a:hover, a:active{ outline: 0; }
::-moz-selection{background:rgba(255,255,0,0.3);color:#000}
::selection{background:rgba(255,255,0,0.3);color:#000}
a::-moz-selection{background:rgba(255,255,0,0.3);color:#0645ad}
a::selection{background:rgba(255,255,0,0.3);color:#0645ad}
p{
margin:1em 0;
}
img{
max-width:100%;
}
h1,h2,h3,h4,h5,h6{
font-weight:normal;
color:#111;
line-height:1em;
}
h4,h5,h6{ font-weight: bold; }
h1{ font-size:2.5em; }
h2{ font-size:2em; }
h3{ font-size:1.5em; }
h4{ font-size:1.2em; }
h5{ font-size:1em; }
h6{ font-size:0.9em; }
blockquote{
color:#666666;
margin:0;
padding-left: 3em;
border-left: 0.5em #EEE solid;
}
hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
pre, code, kbd, samp { color: #000; font-family: monospace, monospace; _font-family: 'courier new', monospace; font-size: 0.98em; }
pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
b, strong { font-weight: bold; }
dfn { font-style: italic; }
ins { background: #ff9; color: #000; text-decoration: none; }
mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
sup { top: -0.5em; }
sub { bottom: -0.25em; }
ul, ol { margin: 1em 0; padding: 0 0 0 2em; }
li p:last-child { margin:0 }
dd { margin: 0 0 0 2em; }
img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; }
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
th { border-bottom: 1px solid black; }
td { vertical-align: top; }
@media only screen and (min-width: 480px) {
body{font-size:14px;}
}
@media only screen and (min-width: 768px) {
body{font-size:16px;}
}
@media print {
* { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
body{font-size:12pt; max-width:100%;}
a, a:visited { text-decoration: underline; }
hr { height: 1px; border:0; border-bottom:1px solid black; }
a[href]:after { content: " (" attr(href) ")"; }
abbr[title]:after { content: " (" attr(title) ")"; }
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
tr, img { page-break-inside: avoid; }
img { max-width: 100% !important; }
@page :left { margin: 15mm 20mm 15mm 10mm; }
@page :right { margin: 15mm 10mm 15mm 20mm; }
p, h2, h3 { orphans: 3; widows: 3; }
h2, h3 { page-break-after: avoid; }
}

BIN
cw 2/zad1b.JPG Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

103
cw 2/zadanie_2_2.html Executable file
View File

@ -0,0 +1,103 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>zadanie_2_2</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="style.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h1 id="ładowanie-modeli">Ładowanie modeli</h1>
<p>w tym zadaniu przećwiczymy ładowanie modeli z plików, wykorzystamy do tego bibliotekę assimp (The Open Asset Import Library ), która zapewnia wspólny interfejs dla różnych typów plików.</p>
<p>Funkcja <code>loadModelToContext</code> pobiera ścieżkę do pliku z modelem i wczytuje go przy użyciu importera assimp.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="at">const</span> aiScene* scene = <span class="kw">import</span>.ReadFile(path, aiProcess_TriangulateaiProcess_Triangulate | aiProcess_CalcTangentSpace);</span></code></pre></div>
<p>Importer przyjmuje ścieżkę i flagi preprocesingu, które mówią jakie operacje ma wykonać importer przed przekazaniem nam pliku. W naszym przypadku dokonuje triangularyzacji (zamienia wszystkie wielokąty na trójkąty) i oblicza przestrzeń styczną (o której będzie mowa później).</p>
<blockquote>
<p>Wywołaj funkcję dla ścieżki do statku <strong>./models/spaceship.obj</strong> i zmiennej globalnej <code>Core::RenderContext sphereContext</code>. Dodaj breakpoint po załadowaniu sceny i obejrzyj jak wygląda struktura załadowanego obiektu</p>
</blockquote>
<p>Załadowany obiekt posiada szereg pól jak na przykład tekstury, oświetlenia, materiały, węzły (<em>Node</em>) czy modele. Węzły odpowiadają za hierarchię elementów w modelu, co ułatwia jego animację, wykorzystamy to w późniejszych zajęciach, w trakcie tych zajęć będziemy się skupiać na modelach. Nasze obiekty składają się z tylko jednego modelu, wywołaj <code>context.initFromAiMesh</code> z nim jako argumentem.</p>
<h3 id="zadanie">Zadanie</h3>
<p>Jeśli tego nie zrobiłeś wywołaj metodę <code>context.initFromAiMesh</code> z argumentem<code>scene-&gt;mMeshes[0]</code> po wczytaniu sceny. Metoda nie jest kompletna, uzupełnij ją o ładowanie indeksów, wierzchołków, normalnych i współrzędnych tekstur do bufora. Współrzędne tekstur i indeksy zostały przekonwertowane do odpowiedniego formatu i znajdują się w zmiennych <code>std::vector&lt;float&gt; textureCoord</code> i <code>std::vector&lt;unsigned int&gt; indices</code> odpowiednio. Pozostałe są dostępne jako atrybuty <code>aiMesh</code>, mianowicie <code>mesh-&gt;mVertices</code> zawiera wierzchołki a <code>mesh-&gt;mNormals</code> normalne</p>
<p>Dodatkowo</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode c++"><code class="sourceCode cpp"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="dt">unsigned</span> <span class="dt">int</span> vertexDataBufferSize = <span class="kw">sizeof</span>(<span class="dt">float</span>) * mesh-&gt;mNumVertices * <span class="dv">3</span>;</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="dt">unsigned</span> <span class="dt">int</span> vertexNormalBufferSize = <span class="kw">sizeof</span>(<span class="dt">float</span>) * mesh-&gt;mNumVertices * <span class="dv">3</span>;</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="dt">unsigned</span> <span class="dt">int</span> vertexTexBufferSize = <span class="kw">sizeof</span>(<span class="dt">float</span>) * mesh-&gt;mNumVertices * <span class="dv">2</span>;</span></code></pre></div>
<p>zawierają rozmiary buforów.</p>
<p>Wykorzystaj w <code>renderScene</code> funkcję <code>Core::DrawContext(Core::RenderContext&amp; context)</code></p>
</body>
</html>

32
cw 2/zadanie_2_2.md Executable file
View File

@ -0,0 +1,32 @@
# Ładowanie modeli
w tym zadaniu przećwiczymy ładowanie modeli z plików, wykorzystamy do tego bibliotekę assimp (The Open Asset Import Library ), która zapewnia wspólny interfejs dla różnych typów plików.
Funkcja `loadModelToContext` pobiera ścieżkę do pliku z modelem i wczytuje go przy użyciu importera assimp.
```c++
const aiScene* scene = import.ReadFile(path, aiProcess_TriangulateaiProcess_Triangulate | aiProcess_CalcTangentSpace);
```
Importer przyjmuje ścieżkę i flagi preprocesingu, które mówią jakie operacje ma wykonać importer przed przekazaniem nam pliku. W naszym przypadku dokonuje triangularyzacji (zamienia wszystkie wielokąty na trójkąty) i oblicza przestrzeń styczną (o której będzie mowa później).
> Wywołaj funkcję dla ścieżki do statku **./models/spaceship.obj** i zmiennej globalnej `Core::RenderContext sphereContext`. Dodaj breakpoint po załadowaniu sceny i obejrzyj jak wygląda struktura załadowanego obiektu
Załadowany obiekt posiada szereg pól jak na przykład tekstury, oświetlenia, materiały, węzły (*Node*) czy modele. Węzły odpowiadają za hierarchię elementów w modelu, co ułatwia jego animację, wykorzystamy to w późniejszych zajęciach, w trakcie tych zajęć będziemy się skupiać na modelach. Nasze obiekty składają się z tylko jednego modelu, wywołaj `context.initFromAiMesh` z nim jako argumentem.
### Zadanie
Jeśli tego nie zrobiłeś wywołaj metodę `context.initFromAiMesh` z argumentem`scene->mMeshes[0]` po wczytaniu sceny. Metoda nie jest kompletna, uzupełnij ją o ładowanie indeksów, wierzchołków, normalnych i współrzędnych tekstur do bufora. Współrzędne tekstur i indeksy zostały przekonwertowane do odpowiedniego formatu i znajdują się w zmiennych `std::vector<float> textureCoord` i ` std::vector<unsigned int> indices` odpowiednio. Pozostałe są dostępne jako atrybuty `aiMesh`, mianowicie `mesh->mVertices` zawiera wierzchołki a `mesh->mNormals` normalne
Dodatkowo
```C++
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
```
zawierają rozmiary buforów.
Wykorzystaj w `renderScene` funkcję `Core::DrawContext(Core::RenderContext& context)`

118
cw 3/exercises_3.html Executable file
View File

@ -0,0 +1,118 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>exercises_3</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" />
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h2 id="perspective-projection">Perspective projection</h2>
<p>Exercises <strong>main_3_1</strong> starts where exercise <strong>main_2_1</strong> from previous class should end. You can see only a square not the whole box. We will display it with perspective projection, what will give us ilusion of depth.</p>
<h4 id="exercise-1">Exercise 1</h4>
<p>Perspective matrix is created by a function <code>createPerspectiveMatrix()</code>, look into definition of this function. Send a result of the function to shader.</p>
<p>Result is not exactly what we would expect. Reason for this is now the camera is inside the box. Add camera matrix to the transformation (this will allow us to move it with keyboard keys) and translate the box in such a way that the camera would land outside of it.</p>
<h4 id="exercise-1-1">Exercise 1*</h4>
<p>Modify the perspective matrix. Inside the function <code>createPerspectiveMatrix()</code> is a variable <code>frustumScale</code>. It is responsible for field of view, modify its value and see what effect is produced. To calculat is use a formula $ S = $, where <span class="math inline">\(fov\)</span> is the viewing angle.</p>
<h4 id="exercise-1-2">Exercise 1**</h4>
<p>Still we have a problem with stretching when the window shape is changed. Solution is to have different values of <strong>frustumScale</strong> for <strong>X</strong> and <strong>Y</strong> coordinates. For this use a function <code>onReshape</code>,which is called every time the screen size is changed. First calculate screen ratio and assign the result to a global variable <code>screenRatio</code>. Next multiply appropriate coordinate by <code>screenRatio</code> in <code>createPerspectiveMatrix()</code>.</p>
<h2 id="shaders">Shaders</h2>
<p>In this part we will use different objects than the box. Remove its initialization form <code>init</code> function and its drawcall in <code>renderScene</code>. Replace shaders to <code>shaders/shader_3_2.vert</code> and <code>shaders/shader_3_2.frag</code>.</p>
<h4 id="exercise-2">Exercise 2</h4>
<p>Load a spaceship and a sphere with <code>loadModelToContext</code> to according variables <code>Core::RenderContext</code>. Next display them with <code>Core::DrawContext</code> function. Finally place them in diferent locations in space.</p>
<h5 id="add-possibility-to-change-colours-of-different-objects">Add possibility to change colours of different objects:</h5>
<p>Create a variable <code>uniform vec3 objectColor</code> in the file <code>shader_3_2.frag</code>, which you will use to send the colour of an object in RGB format to the shader. The built-in shader variable <code>gl_FragColor</code> has type vec4 - RGBA. Set the .rgb part of the variable equal to <code>objectColor</code>, and the 4th element (.a) - <code>1.0f</code>. Now you can control the color of the drawn object, by sending values to the variable <code>objectColor</code> using the <code>function glUniform3f( int location, float v0, float v1, float v2 )</code>.</p>
<p>“location” indicates the address of the variable in GPU memory we want to send data to. You can retrieve this address with the function <code>glGetUniformLocation(program, "variable name")</code>.</p>
<h4 id="exercise-2-1">Exercise 2*</h4>
<p>Modify program in such a way, that colour of the ship would change in time.</p>
<h4 id="exercise-3">Exercise 3</h4>
<p>We want to display the normal vectors at each fragment as colors.</p>
<p>The normal vector of a vertex is accessible in the vertex shader (file with the extension <strong>.vert</strong>). The pixel color is defined in the fragment shader (<strong>.frag</strong>). Hence, we have to send the normal vector from vertex to fragment shader. The normal vector will be automatically interpolated.</p>
<p>Create a variable <code>out vec3 name</code> in the vertex shader and a corresponding variable <code>in vec3 name</code> in the fragment shader. Set the values in the vertex shader for the new variable - this will automatically set the value in the fragment shader. Keep in mind that you can only set variable values in the <code>main()</code> part of a shader. Use the new variable in the fragment shader to set the color of pixels: normalize the new variable and scale all the values to the range [0, 1] and use the result to define the R, G, B channels of the variable <code>gl_FragColor</code>.</p>
<h4 id="exercise-4">Exercise 4</h4>
<p>Create a function <code>drawObject</code> in the .cpp source file, which will make drawing objects more convienient. As input parameters we need a reference to <code>Core::RenderContext</code> as well as the model matrix of the object. Display a few objects in different positions (and look at the from different perspectives).</p>
<p>“Attach” the spaceship to the camera - its model matrix has to take into account the position and orientation of the camera such that it gives the impression you are steering the spaceship.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode c++"><code class="sourceCode cpp"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>glm::mat4 shipModelMatrix = </span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> glm::translate(cameraPos + cameraDir * <span class="fl">0.5</span><span class="bu">f</span> + glm::vec3(<span class="dv">0</span>,-<span class="fl">0.25</span><span class="bu">f</span>,<span class="dv">0</span>)) * </span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> glm::rotate(-cameraAngle + glm::radians(<span class="fl">90.0</span><span class="bu">f</span>), glm::vec3(<span class="dv">0</span>,<span class="dv">1</span>,<span class="dv">0</span>)) *</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> glm::scale(glm::vec3(<span class="fl">0.25</span><span class="bu">f</span>));</span></code></pre></div>
<p>Analize the above instruction and evaluate how else to perform the same task.</p>
<h4 id="exercise-5">Exercise 5</h4>
<p>Create a planetary system - with one immovable sphere at the center (sun) and a few orbiting planets with moons around it.</p>
</body>
</html>

71
cw 3/exercises_3.md Executable file
View File

@ -0,0 +1,71 @@
## Perspective projection
Exercises **main_3_1** starts where exercise **main_2_1** from previous class should end. You can see only a square not the whole box. We will display it with perspective projection, what will give us ilusion of depth.
#### Exercise 1
Perspective matrix is created by a function `createPerspectiveMatrix()`, look into definition of this function. Send a result of the function to shader.
Result is not exactly what we would expect. Reason for this is now the camera is inside the box. Add camera matrix to the transformation (this will allow us to move it with keyboard keys) and translate the box in such a way that the camera would land outside of it.
#### Exercise 1*
Modify the perspective matrix. Inside the function `createPerspectiveMatrix()` is a variable `frustumScale`. It is responsible for field of view, modify its value and see what effect is produced. To calculat is use a formula $ S = \frac{1}{tan\left( \frac{fov}{2}* \frac{\pi}{2}\right)} $, where $fov$ is the viewing angle.
#### Exercise 1**
Still we have a problem with stretching when the window shape is changed. Solution is to have different values of **frustumScale** for **X** and **Y** coordinates. For this use a function `onReshape`,which is called every time the screen size is changed. First calculate screen ratio and assign the result to a global variable `screenRatio`. Next multiply appropriate coordinate by `screenRatio` in `createPerspectiveMatrix()`.
## Shaders
In this part we will use different objects than the box. Remove its initialization form `init` function and its drawcall in `renderScene`. Replace shaders to `shaders/shader_3_2.vert` and `shaders/shader_3_2.frag`.
#### Exercise 2
Load a spaceship and a sphere with `loadModelToContext` to according variables `Core::RenderContext`. Next display them with `Core::DrawContext` function. Finally place them in diferent locations in space.
##### Add possibility to change colours of different objects:
Create a variable `uniform vec3 objectColor` in the file `shader_3_2.frag`, which you will use to send the colour of an object in RGB format to the shader.
The built-in shader variable `gl_FragColor` has type vec4 - RGBA. Set the .rgb part of the variable equal to `objectColor`, and the 4th element (.a) - `1.0f`.
Now you can control the color of the drawn object, by sending values to the variable `objectColor` using the `function glUniform3f( int location, float v0, float v1, float v2 )`.
"location" indicates the address of the variable in GPU memory we want to send data to.
You can retrieve this address with the function `glGetUniformLocation(program, "variable name")`.
#### Exercise 2*
Modify program in such a way, that colour of the ship would change in time.
#### Exercise 3
We want to display the normal vectors at each fragment as colors.
The normal vector of a vertex is accessible in the vertex shader (file with the extension **.vert**). The pixel color is defined in the fragment shader (**.frag**).
Hence, we have to send the normal vector from vertex to fragment shader. The normal vector will be automatically interpolated.
Create a variable `out vec3 name` in the vertex shader and a corresponding variable `in vec3 name` in the fragment shader.
Set the values in the vertex shader for the new variable - this will automatically set the value in the fragment shader. Keep in mind that you can only set variable values in the `main()` part of a shader.
Use the new variable in the fragment shader to set the color of pixels: normalize the new variable and scale all the values to the range [0, 1] and use the result to define the R, G, B channels of the variable `gl_FragColor`.
#### Exercise 4
Create a function `drawObject` in the .cpp source file, which will make drawing objects more convienient.
As input parameters we need a reference to `Core::RenderContext` as well as the model matrix of the object.
Display a few objects in different positions (and look at the from different perspectives).
"Attach" the spaceship to the camera - its model matrix has to take into account the position and orientation of the camera such that it gives the impression you are steering the spaceship.
```C++
glm::mat4 shipModelMatrix =
glm::translate(cameraPos + cameraDir * 0.5f + glm::vec3(0,-0.25f,0)) *
glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0,1,0)) *
glm::scale(glm::vec3(0.25f));
```
Analize the above instruction and evaluate how else to perform the same task.
#### Exercise 5
Create a planetary system - with one immovable sphere at the center (sun) and a few orbiting planets with moons around it.

113
cw 3/grk-cw3.vcxproj Executable file
View File

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main_3_1.cpp" />
<ClCompile Include="src\Render_Utils.cpp" />
<ClCompile Include="src\Shader_Loader.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Camera.h" />
<ClInclude Include="src\objload.h" />
<ClInclude Include="src\Render_Utils.h" />
<ClInclude Include="src\Shader_Loader.h" />
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_3_1.frag" />
<None Include="shaders\shader_3_1.vert" />
<None Include="shaders\shader_3_2.frag" />
<None Include="shaders\shader_3_2.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F201D210-49F1-4EFF-B8A0-56D56880D14B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>grk-cw3</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>grk-cw3</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp\Release;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlibd.lib;assimp-vc141-mtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlib.lib;assimp-vc141-mt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

65
cw 3/grk-cw3.vcxproj.filters Executable file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Shader Files">
<UniqueIdentifier>{0a247bb8-2e8e-4a90-b0ef-17415b0941ba}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Render_Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Shader_Loader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Box.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\main_3_1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\objload.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Render_Utils.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Shader_Loader.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Camera.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_3_1.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_3_1.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_3_2.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_3_2.frag">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

4
cw 3/grk-cw3.vcxproj.user Executable file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

315
cw 3/models/spaceship.obj Executable file
View File

@ -0,0 +1,315 @@
# Blender v2.90.0 OBJ File: 'spaceship.blend'
# www.blender.org
mtllib spaceship.mtl
o spaceship
v -0.466043 -0.046099 0.061004
v -0.496632 -0.038727 -0.744142
v -0.284772 -0.093266 -0.411636
v -0.169612 -0.147446 -0.381196
v -0.169612 -0.147446 0.061004
v -0.091309 -0.100093 0.472421
v -0.182617 -0.069341 0.472421
v -0.182617 -0.001722 0.472421
v -0.466043 0.045632 0.061004
v -0.647568 0.071442 -0.238048
v -0.169612 0.164038 0.061004
v -0.284772 0.045632 -0.411636
v -0.169612 0.116537 -0.381196
v -0.053437 -0.049075 0.720448
v -0.053437 -0.102143 0.720448
v -0.040834 -0.049075 0.734564
v -0.040834 -0.102143 0.734564
v 0.000000 -0.049075 0.744142
v 0.000000 -0.118734 0.744142
v 0.040834 -0.049075 0.734564
v 0.000000 0.045779 0.472421
v 0.000000 -0.116684 0.472421
v 0.091309 -0.100093 0.472421
v 0.040834 -0.102143 0.734564
v 0.000000 0.116537 -0.350755
v 0.000000 0.164038 0.061004
v 0.169612 -0.147446 -0.381196
v 0.000000 -0.164038 -0.350755
v 0.169612 0.164038 0.061004
v 0.169612 0.116537 -0.381196
v 0.000000 -0.164038 0.061004
v 0.169612 -0.147446 0.061004
v -0.647568 -0.038727 -0.238048
v -0.496632 0.071442 -0.744142
v -0.091309 0.045779 0.472421
v 0.466043 -0.046099 0.061004
v 0.647568 0.071442 -0.238048
v 0.466043 0.045632 0.061004
v 0.496632 -0.038727 -0.744142
v 0.647568 -0.038727 -0.238048
v 0.284772 -0.093266 -0.411636
v 0.182617 -0.001722 0.472421
v 0.182617 -0.069341 0.472421
v 0.284772 0.045632 -0.411636
v 0.053437 -0.049075 0.720448
v 0.053437 -0.102143 0.720448
v 0.496632 0.071442 -0.744142
v 0.091309 0.045779 0.472421
vt 0.542758 0.543965
vt 0.356004 0.244407
vt 0.504680 0.319696
vt 0.553316 0.302407
vt 0.649859 0.471001
vt 0.766053 0.611338
vt 0.733075 0.633795
vt 0.942531 0.273938
vt 0.916601 0.470616
vt 0.908930 0.272020
vt 0.906245 0.133229
vt 0.060793 0.659810
vt 0.095301 0.442790
vt 0.182444 0.620892
vt 0.912119 0.905444
vt 0.989612 0.943366
vt 0.900946 0.955153
vt 0.229586 0.822972
vt 0.045790 0.812939
vt 0.871970 0.876051
vt 0.270733 0.797357
vt 0.928563 0.581569
vt 0.948002 0.582679
vt 0.928200 0.588981
vt 0.833604 0.696984
vt 0.841128 0.699424
vt 0.941370 0.472030
vt 0.927606 0.601110
vt 0.953122 0.602566
vt 0.116239 0.298971
vt 0.134935 0.296266
vt 0.170287 0.416872
vt 0.947639 0.590091
vt 0.858040 0.692927
vt 0.798664 0.589407
vt 1.000000 0.000000
vt 0.975078 0.013585
vt 0.974484 0.001457
vt 0.830416 0.568707
vt 0.869911 0.680359
vt 0.785184 0.955792
vt 0.850736 0.970525
vt 0.334379 0.757520
vt 0.252163 0.593452
vt 0.740866 0.846584
vt 0.807753 0.855379
vt 0.321881 0.566013
vt 0.410170 0.742478
vt 0.620171 0.273802
vt 0.672876 0.223217
vt 0.710068 0.430790
vt 0.769418 0.391811
vt 0.946599 0.135534
vt 0.413299 0.472597
vt 0.208789 0.994633
vt 0.953122 0.002304
vt 0.980750 0.982793
vt 0.912767 0.000000
vt 0.101366 0.309478
vt 0.132755 0.431644
vt 0.099001 0.317265
vt 0.989409 0.328628
vt 0.953122 0.469337
vt 0.955808 0.330547
vt 0.871271 0.326374
vt 0.706080 0.012535
vt 0.869769 0.170254
vt 0.705415 0.186739
vt 0.963479 0.131951
vt 0.988248 0.130536
vt 0.443922 0.509019
vt 0.463695 0.730833
vt 0.578150 0.603414
vt 0.692001 0.855970
vt 0.680828 0.905679
vt 0.605734 0.857085
vt 0.719632 0.941058
vt 0.975441 0.020998
vt 0.994879 0.019888
vt 0.142931 0.299975
vt 0.245429 0.383703
vt 0.994516 0.012475
vt 0.871271 0.672035
vt 0.861802 0.548533
vt 0.993477 0.467033
vt 1.000000 0.600262
vt 0.959645 0.602566
vt 0.617066 0.833945
vt 0.596872 0.896513
vt 0.207819 0.402100
vn -0.2502 -0.9682 0.0006
vn -0.3235 -0.9462 -0.0000
vn -0.3158 -0.9343 0.1651
vn -0.3186 -0.9329 0.1677
vn -0.3148 -0.9349 0.1641
vn -0.8235 0.0000 0.5673
vn -0.8548 0.0000 0.5189
vn -0.3487 0.8731 0.3407
vn 0.8434 0.0000 -0.5374
vn -0.4103 -0.9095 -0.0666
vn 0.0862 0.9958 0.0321
vn 0.0832 0.9962 0.0257
vn 0.0868 0.9957 0.0333
vn 0.2556 0.0000 -0.9668
vn -0.5043 0.8586 -0.0922
vn -0.8869 0.0000 0.4619
vn -0.7459 0.0000 0.6660
vn 0.0112 -0.9999 -0.0100
vn -0.2284 0.0000 0.9736
vn 0.0771 0.9413 0.3286
vn -0.1788 -0.9839 -0.0074
vn 0.2284 0.0000 0.9736
vn 0.3892 -0.9187 0.0677
vn 0.1766 0.0000 -0.9843
vn 0.0000 0.9934 -0.1146
vn -0.1766 0.0000 -0.9843
vn -0.0192 0.9941 -0.1068
vn 0.0974 -0.9952 -0.0000
vn -0.0974 -0.9952 -0.0000
vn -0.0965 -0.9866 0.1319
vn 0.1776 -0.9776 0.1125
vn -0.0272 -0.9996 -0.0081
vn 0.0827 0.9963 0.0247
vn -0.9583 -0.0000 -0.2858
vn -0.3892 -0.9187 0.0677
vn 0.0000 0.9403 0.3403
vn -0.4230 0.8237 0.3776
vn -0.4240 0.8230 0.3780
vn -0.4228 0.8239 0.3775
vn 0.0192 0.9941 -0.1068
vn -0.3672 0.9194 -0.1408
vn 0.0000 0.9611 0.2763
vn -0.4366 0.8392 0.3243
vn -0.3189 -0.9328 0.1681
vn -0.4270 0.8209 0.3792
vn -0.0771 0.9413 0.3286
vn -0.1776 -0.9776 0.1125
vn 0.1788 -0.9839 -0.0074
vn -0.3189 -0.9469 0.0409
vn 0.8548 -0.0000 0.5189
vn 0.0272 -0.9996 -0.0081
vn 0.4103 -0.9095 -0.0666
vn 0.3158 -0.9343 0.1651
vn 0.3186 -0.9329 0.1677
vn 0.3189 -0.9328 0.1681
vn 0.8235 0.0000 0.5673
vn 0.3672 0.9194 -0.1408
vn -0.0868 0.9957 0.0333
vn -0.0832 0.9962 0.0257
vn -0.0862 0.9958 0.0321
vn 0.2502 -0.9682 0.0006
vn -0.2556 0.0000 -0.9668
vn -0.8434 0.0000 -0.5374
vn 0.7459 0.0000 0.6660
vn 0.4228 0.8239 0.3775
vn 0.4240 0.8230 0.3780
vn 0.4230 0.8237 0.3776
vn 0.3189 -0.9469 0.0409
vn 0.8869 0.0000 0.4619
vn 0.9583 -0.0000 -0.2858
vn -0.0827 0.9963 0.0247
vn -0.0112 -0.9999 -0.0100
vn 0.4270 0.8209 0.3792
vn 0.5043 0.8586 -0.0922
vn 0.3487 0.8731 0.3407
vn 0.3235 -0.9462 -0.0000
vn 0.0965 -0.9866 0.1319
vn 0.4366 0.8392 0.3243
vn 0.3148 -0.9349 0.1641
usemtl cube1_auv
s 1
f 1/1/1 2/2/1 3/3/1
f 1/1/2 4/4/2 5/5/2
f 1/1/3 6/6/4 7/7/5
f 1/8/6 8/9/6 9/10/6
f 9/10/7 10/11/7 1/8/7
f 9/12/8 8/13/8 11/14/8
f 3/15/9 2/16/9 12/17/9
f 3/3/10 4/4/10 1/1/10
f 12/18/11 10/19/12 9/12/13
f 12/17/14 4/20/14 3/15/14
f 12/18/15 11/14/15 13/21/15
f 14/22/16 8/9/16 15/23/16
f 15/23/17 16/24/17 14/22/17
f 15/25/18 6/6/18 17/26/18
f 15/23/16 8/9/16 7/27/16
f 18/28/19 16/24/19 19/29/19
f 18/30/20 20/31/20 21/32/20
f 19/29/19 16/24/19 17/33/19
f 19/34/21 6/6/21 22/35/21
f 19/36/22 20/37/22 18/38/22
f 19/34/23 23/39/23 24/40/23
f 25/41/24 4/20/24 13/42/24
f 25/43/25 11/14/25 26/44/25
f 25/41/26 27/45/26 28/46/26
f 25/43/27 29/47/27 30/48/27
f 28/46/24 4/20/24 25/41/24
f 28/49/28 27/50/28 31/51/28
f 26/44/25 29/47/25 25/43/25
f 31/51/29 4/4/29 28/49/29
f 31/51/30 6/6/30 5/5/30
f 31/51/28 27/50/28 32/52/28
f 31/51/31 23/39/31 22/35/31
f 33/53/7 1/8/7 10/11/7
f 33/54/32 2/2/32 1/1/32
f 10/19/12 12/18/11 34/55/33
f 10/11/34 2/56/34 33/53/34
f 34/57/9 12/17/9 2/16/9
f 34/58/34 2/56/34 10/11/34
f 17/33/17 16/24/17 15/23/17
f 17/26/35 6/6/35 19/34/35
f 16/59/36 21/32/36 35/60/36
f 16/59/37 8/13/38 14/61/39
f 13/42/14 4/20/14 12/17/14
f 13/21/40 11/14/40 25/43/40
f 11/14/41 12/18/41 9/12/41
f 11/14/42 21/32/42 26/44/42
f 11/14/43 8/13/43 35/60/43
f 5/5/29 4/4/29 31/51/29
f 5/5/44 6/6/4 1/1/3
f 35/60/42 21/32/42 11/14/42
f 35/60/45 8/13/38 16/59/37
f 21/32/46 16/59/46 18/30/46
f 21/32/42 29/47/42 26/44/42
f 22/35/47 6/6/47 31/51/47
f 22/35/48 23/39/48 19/34/48
f 7/7/49 6/6/49 15/25/49
f 7/27/6 8/9/6 1/8/6
f 36/62/50 37/63/50 38/64/50
f 36/65/51 39/66/51 40/67/51
f 36/65/52 27/50/52 41/68/52
f 36/65/53 23/39/54 32/52/55
f 36/62/56 42/69/56 43/70/56
f 38/71/57 44/72/57 29/47/57
f 38/71/58 37/73/59 44/72/60
f 38/64/56 42/69/56 36/62/56
f 41/68/61 39/66/61 36/65/61
f 41/74/62 27/45/62 44/75/62
f 44/75/63 39/76/63 41/74/63
f 44/75/62 27/45/62 30/77/62
f 45/78/64 20/37/64 46/79/64
f 45/80/65 42/81/66 20/31/67
f 46/79/64 20/37/64 24/82/64
f 46/83/68 23/39/68 43/84/68
f 46/79/69 42/69/69 45/78/69
f 40/85/70 39/86/70 37/63/70
f 37/63/50 36/62/50 40/85/50
f 37/63/70 39/86/70 47/87/70
f 47/88/71 44/72/60 37/73/59
f 39/76/63 44/75/63 47/89/63
f 24/82/22 20/37/22 19/36/22
f 24/40/72 23/39/72 46/83/72
f 20/31/67 42/81/66 48/90/73
f 30/77/26 27/45/26 25/41/26
f 30/48/74 29/47/74 44/72/74
f 29/47/42 21/32/42 48/90/42
f 29/47/75 42/81/75 38/71/75
f 32/52/76 27/50/76 36/65/76
f 32/52/77 23/39/77 31/51/77
f 48/90/36 21/32/36 20/31/36
f 48/90/78 42/81/78 29/47/78
f 43/84/79 23/39/54 36/65/53
f 43/70/69 42/69/69 46/79/69

2500
cw 3/models/sphere.obj Executable file

File diff suppressed because it is too large Load Diff

8
cw 3/shaders/shader_3_1.frag Executable file
View File

@ -0,0 +1,8 @@
#version 430 core
in vec4 color;
void main()
{
gl_FragColor = color;
}

14
cw 3/shaders/shader_3_1.vert Executable file
View File

@ -0,0 +1,14 @@
#version 430 core
layout(location = 0) in vec4 vertexPosition;
layout(location = 1) in vec4 vertexColor;
uniform mat4 transformation;
out vec4 color;
void main()
{
color = vertexColor;
gl_Position = transformation * vertexPosition;
}

8
cw 3/shaders/shader_3_2.frag Executable file
View File

@ -0,0 +1,8 @@
#version 430 core
in vec3 vNormal;
void main()
{
gl_FragColor = vec4(0.,1.,0., 1. );
}

13
cw 3/shaders/shader_3_2.vert Executable file
View File

@ -0,0 +1,13 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 transformation;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

104
cw 3/src/Box.cpp Executable file
View File

@ -0,0 +1,104 @@
// dane 36 wierzcholkow i kolorow opisujace model pudelka
const float boxPositions[] = {
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
};
const float boxColors[] = {
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
};

31
cw 3/src/Camera.cpp Executable file
View File

@ -0,0 +1,31 @@
#include "Camera.h"
glm::mat4 Core::createPerspectiveMatrix(float zNear, float zFar, float frustumScale)
{
glm::mat4 perspective;
perspective[0][0] = 1.f;
perspective[1][1] = frustumScale;
perspective[2][2] = (zFar + zNear) / (zNear - zFar);
perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
perspective[2][3] = -1;
perspective[3][3] = 0;
return perspective;
}
glm::mat4 Core::createViewMatrix( glm::vec3 position, glm::vec3 forward, glm::vec3 up )
{
glm::vec3 side = glm::cross(forward, up);
// Trzeba pamietac o minusie przy ustawianiu osi Z kamery.
// Wynika to z tego, ze standardowa macierz perspektywiczna zaklada, ze "z przodu" jest ujemna (a nie dodatnia) czesc osi Z.
glm::mat4 cameraRotation;
cameraRotation[0][0] = side.x; cameraRotation[1][0] = side.y; cameraRotation[2][0] = side.z;
cameraRotation[0][1] = up.x; cameraRotation[1][1] = up.y; cameraRotation[2][1] = up.z;
cameraRotation[0][2] = -forward.x; cameraRotation[1][2] = -forward.y; cameraRotation[2][2] = -forward.z;
glm::mat4 cameraTranslation;
cameraTranslation[3] = glm::vec4(-position, 1.0f);
return cameraRotation * cameraTranslation;
}

14
cw 3/src/Camera.h Executable file
View File

@ -0,0 +1,14 @@
#pragma once
#include "glm.hpp"
namespace Core
{
glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f, float frustumScale = 1.f);
// position - pozycja kamery
// forward - wektor "do przodu" kamery (jednostkowy)
// up - wektor "w gore" kamery (jednostkowy)
// up i forward musza byc ortogonalne!
glm::mat4 createViewMatrix(glm::vec3 position, glm::vec3 forward, glm::vec3 up);
}

169
cw 3/src/Render_Utils.cpp Executable file
View File

@ -0,0 +1,169 @@
#include "Render_Utils.h"
#include <algorithm>
#include "glew.h"
#include "freeglut.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
void Core::RenderContext::initFromOBJ(obj::Model& model)
{
vertexArray = 0;
vertexBuffer = 0;
vertexIndexBuffer = 0;
unsigned int vertexDataBufferSize = sizeof(float) * model.vertex.size();
unsigned int vertexNormalBufferSize = sizeof(float) * model.normal.size();
unsigned int vertexTexBufferSize = sizeof(float) * model.texCoord.size();
size = model.faces["default"].size();
unsigned int vertexElementBufferSize = sizeof(unsigned short) * size;
glGenVertexArrays(1, &vertexArray);
glBindVertexArray(vertexArray);
glGenBuffers(1, &vertexIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &model.faces["default"][0], GL_STATIC_DRAW);
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, &model.vertex[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, &model.normal[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &model.texCoord[0]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
}
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
vertexArray = 0;
vertexBuffer = 0;
vertexIndexBuffer = 0;
std::vector<float> textureCoord;
std::vector<unsigned int> indices;
//tex coord must be converted to 2d vecs
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
if (mesh->mTextureCoords[0] != nullptr) {
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
}
else {
textureCoord.push_back(0.0f);
textureCoord.push_back(0.0f);
}
}
if (mesh->mTextureCoords[0] == nullptr) {
std::cout << "no uv coords\n";
}
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
// retrieve all indices of the face and store them in the indices vector
for (unsigned int j = 0; j < face.mNumIndices; j++)
indices.push_back(face.mIndices[j]);
}
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
unsigned int vertexTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexBiTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexElementBufferSize = sizeof(unsigned int) * indices.size();
size = indices.size();
glGenVertexArrays(1, &vertexArray);
glBindVertexArray(vertexArray);
glGenBuffers(1, &vertexIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
//std::cout << vertexBuffer;
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize + vertexBiTangentBufferSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, vertexTangentBufferSize, mesh->mTangents);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize));
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize));
}
void Core::DrawVertexArray(const float * vertexArray, int numVertices, int elementSize )
{
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, numVertices);
}
void Core::DrawVertexArrayIndexed( const float * vertexArray, const int * indexArray, int numIndexes, int elementSize )
{
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
glEnableVertexAttribArray(0);
glDrawElements(GL_TRIANGLES, numIndexes, GL_UNSIGNED_INT, indexArray);
}
void Core::DrawVertexArray( const VertexData & data )
{
int numAttribs = std::min(VertexData::MAX_ATTRIBS, data.NumActiveAttribs);
for(int i = 0; i < numAttribs; i++)
{
glVertexAttribPointer(i, data.Attribs[i].Size, GL_FLOAT, false, 0, data.Attribs[i].Pointer);
glEnableVertexAttribArray(i);
}
glDrawArrays(GL_TRIANGLES, 0, data.NumVertices);
}
void Core::DrawContext(Core::RenderContext& context)
{
glBindVertexArray(context.vertexArray);
glDrawElements(
GL_TRIANGLES, // mode
context.size, // count
GL_UNSIGNED_INT, // type
(void*)0 // element array buffer offset
);
glBindVertexArray(0);
}

72
cw 3/src/Render_Utils.h Executable file
View File

@ -0,0 +1,72 @@
#pragma once
#include "glm.hpp"
#include "glew.h"
#include "objload.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
namespace Core
{
struct RenderContext
{
GLuint vertexArray;
GLuint vertexBuffer;
GLuint vertexIndexBuffer;
int size = 0;
void initFromOBJ(obj::Model& model);
void initFromAssimpMesh(aiMesh* mesh);
};
// vertexArray - jednowymiarowa tablica zawierajaca wartosci opisujace pozycje kolejnych wierzcholkow w jednym ciagu (x1, y1, z1, w1, x2, y2, z2, w2, ...)
// numVertices - liczba wierzcholkow do narysowania
// elementSize - liczba wartosci opisujacych pojedynczy wierzcholek (np. 3 gdy wierzcholek opisany jest trojka (x, y, z))
void DrawVertexArray(const float * vertexArray, int numVertices, int elementSize);
// indexArray - jednowymiarowa tablica zawierajaca indeksy wierzcholkow kolejnych trojkatow w jednym ciagu (t1_i1, t1_i2, t1_i3, t2_i1, t2_i2, t2_i3, ...)
// numIndexes - liczba indeksow w tablicy indexArray
void DrawVertexArrayIndexed(const float * vertexArray, const int * indexArray, int numIndexes, int elementSize);
struct VertexAttribute
{
const void * Pointer;
int Size;
};
struct VertexData
{
static const int MAX_ATTRIBS = 8;
VertexAttribute Attribs[MAX_ATTRIBS];
int NumActiveAttribs;
int NumVertices;
};
// Ta funkcja sluzy do rysowania trojkatow, ktorych wierzcholki moga byc opisane wiecej niz jednym atrybutem.
// Funkcja przyjmuje jako parametr strukture, w ktorej nalezy zawrzec wszystkie potrzebne dane.
//
// Przykladowe wywolanie funkcji - narysowanie trojkata jak na pierwszych zajeciach:
/*
const float vertices[] = {
0.25f, 0.25f, 0.0f, 1.0f,
0.25f, -0.25f, 0.0f, 1.0f,
-0.25f, -0.25f, 0.0f, 1.0f
};
Core::VertexData vertexData;
vertexData.NumActiveAttribs = 1; // Liczba uzywanych atrybutow wierzcholka
vertexData.Attribs[0].Pointer = vertices; // Wskaznik na dane zerowego atrybutu
vertexData.Attribs[0].Size = 4; // Wielkosc zerowego atrybutu (ilosc liczb opisujacych ten atrybut w pojedynczym wierzcholku)
vertexData.NumVertices = 3; // Liczba wierzcholkow do narysowania
Core::DrawVertexArray(vertexData);
*/
void DrawVertexArray(const VertexData & data);
void DrawContext(RenderContext& context);
}

102
cw 3/src/Shader_Loader.cpp Executable file
View File

@ -0,0 +1,102 @@
#include "Shader_Loader.h"
#include<iostream>
#include<fstream>
#include<vector>
using namespace Core;
Shader_Loader::Shader_Loader(void){}
Shader_Loader::~Shader_Loader(void){}
std::string Shader_Loader::ReadShader(char *filename)
{
std::string shaderCode;
std::ifstream file(filename, std::ios::in);
if (!file.good())
{
std::cout << "Can't read file " << filename << std::endl;
std::terminate();
}
file.seekg(0, std::ios::end);
shaderCode.resize((unsigned int)file.tellg());
file.seekg(0, std::ios::beg);
file.read(&shaderCode[0], shaderCode.size());
file.close();
return shaderCode;
}
GLuint Shader_Loader::CreateShader(GLenum shaderType, std::string
source, char* shaderName)
{
int compile_result = 0;
GLuint shader = glCreateShader(shaderType);
const char *shader_code_ptr = source.c_str();
const int shader_code_size = source.size();
glShaderSource(shader, 1, &shader_code_ptr, &shader_code_size);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result);
//sprawdz bledy
if (compile_result == GL_FALSE)
{
int info_log_length = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);
std::vector<char> shader_log(info_log_length);
glGetShaderInfoLog(shader, info_log_length, NULL, &shader_log[0]);
std::cout << "ERROR compiling shader: " << shaderName << std::endl << &shader_log[0] << std::endl;
return 0;
}
return shader;
}
GLuint Shader_Loader::CreateProgram(char* vertexShaderFilename,
char* fragmentShaderFilename)
{
//wczytaj shadery
std::string vertex_shader_code = ReadShader(vertexShaderFilename);
std::string fragment_shader_code = ReadShader(fragmentShaderFilename);
GLuint vertex_shader = CreateShader(GL_VERTEX_SHADER, vertex_shader_code, "vertex shader");
GLuint fragment_shader = CreateShader(GL_FRAGMENT_SHADER, fragment_shader_code, "fragment shader");
int link_result = 0;
//stworz shader
GLuint program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &link_result);
//sprawdz bledy w linkerze
if (link_result == GL_FALSE)
{
int info_log_length = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);
std::vector<char> program_log(info_log_length);
glGetProgramInfoLog(program, info_log_length, NULL, &program_log[0]);
std::cout << "Shader Loader : LINK ERROR" << std::endl << &program_log[0] << std::endl;
return 0;
}
glDetachShader(program, vertex_shader);
glDetachShader(program, fragment_shader);
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
return program;
}
void Shader_Loader::DeleteProgram( GLuint program )
{
glDeleteProgram(program);
}

29
cw 3/src/Shader_Loader.h Executable file
View File

@ -0,0 +1,29 @@
#pragma once
#include "glew.h"
#include "freeglut.h"
#include <iostream>
namespace Core
{
class Shader_Loader
{
private:
std::string ReadShader(char *filename);
GLuint CreateShader(GLenum shaderType,
std::string source,
char* shaderName);
public:
Shader_Loader(void);
~Shader_Loader(void);
GLuint CreateProgram(char* VertexShaderFilename,
char* FragmentShaderFilename);
void DeleteProgram(GLuint program);
};
}

171
cw 3/src/main_3_1.cpp Executable file
View File

@ -0,0 +1,171 @@
#include "glew.h"
#include "freeglut.h"
#include "glm.hpp"
#include "ext.hpp"
#include <iostream>
#include <cmath>
#include "Shader_Loader.h"
#include "Render_Utils.h"
#include "Camera.h"
#include "Box.cpp"
GLuint program;
Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext sphereContext;
float cameraAngle = 0;
glm::vec3 cameraPos = glm::vec3(-5, 0, 0);
glm::vec3 cameraDir;
float screenRatio = 1.0f;
unsigned int VAO;
void keyboard(unsigned char key, int x, int y)
{
float angleSpeed = 0.1f;
float moveSpeed = 0.1f;
switch(key)
{
case 'a': cameraAngle -= angleSpeed; break;
case 'd': cameraAngle += angleSpeed; break;
case 'w': cameraPos += cameraDir * moveSpeed; break;
case 's': cameraPos -= cameraDir * moveSpeed; break;
}
}
glm::mat4 createPerspectiveMatrix()
{
float zNear = 0.1, zFar = 100.0;
int fov = 120;
float frustumScale = 1 / tan((fov / 2) * (3.14 / 2));
glm::mat4 perspective;
perspective[0][0] = frustumScale * screenRatio;
perspective[1][1] = frustumScale * screenRatio;
perspective[2][2] = (zFar + zNear) / (zNear - zFar);
perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
perspective[2][3] = -1;
perspective[3][3] = 0;
return perspective;
}
glm::mat4 createCameraMatrix()
{
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
glm::vec3 up = glm::vec3(0,1,0);
return Core::createViewMatrix(cameraPos, cameraDir, up);
}
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
glUseProgram(program);
glm::mat4 camera = createCameraMatrix();
glm::mat4 perspective = createPerspectiveMatrix();
glm::mat4 transformation = perspective * camera;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
//triangle drawcall
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glUseProgram(0);
glutSwapBuffers();
}
void loadModelToContext(std::string path, Core::RenderContext& context)
{
Assimp::Importer import;
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
{
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
return;
}
context.initFromAssimpMesh(scene->mMeshes[0]);
}
void init()
{
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_3_1.vert", "shaders/shader_3_1.frag");
// replace 3_1 shaders with 3_4 shaders for later exercises
//program = shaderLoader.CreateProgram("shaders/shader_3_2.vert", "shaders/shader_3_2.frag");
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
GLuint VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(boxPositions) + sizeof(boxColors), 0, GL_STATIC_DRAW);
GLuint vertexPosition = glGetAttribLocation(program, "vertexPosition");
glEnableVertexAttribArray(vertexPosition);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(boxPositions), boxPositions);
glVertexAttribPointer(vertexPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
GLuint vertexColor = glGetAttribLocation(program, "vertexColor");
glEnableVertexAttribArray(vertexColor);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(boxPositions), sizeof(boxColors), boxColors);
glVertexAttribPointer(vertexColor, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(boxPositions)));
glBindVertexArray(0);
}
void shutdown()
{
shaderLoader.DeleteProgram(program);
}
void idle()
{
glutPostRedisplay();
}
void onReshape(int width, int height)
{
glViewport(0, 0, width, height);
screenRatio = width / (float)height;
// https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 200);
glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Pierwszy Program");
glewInit();
init();
glutReshapeFunc(onReshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(renderScene);
glutIdleFunc(idle);
glutMainLoop();
shutdown();
return 0;
}

291
cw 3/src/objload.h Executable file
View File

@ -0,0 +1,291 @@
/* Copyright (c) 2012, Gerhard Reitmayr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#ifndef OBJLOAD_H_
#define OBJLOAD_H_
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <vector>
namespace obj {
struct Model {
std::vector<float> vertex; //< 3 * N entries
std::vector<float> texCoord; //< 2 * N entries
std::vector<float> normal; //< 3 * N entries
std::map<std::string, std::vector<unsigned short> > faces; //< assume triangels and uniform indexing
};
struct ObjModel {
struct FaceVertex {
FaceVertex() : v(-1), t(-1), n(-1) {}
int v, t, n;
bool operator<( const FaceVertex & other ) const;
bool operator==( const FaceVertex & other ) const;
};
typedef std::pair<std::vector<FaceVertex>, std::vector<unsigned> > FaceList;
std::vector<float> vertex; //< 3 * N entries
std::vector<float> texCoord; //< 2 * N entries
std::vector<float> normal; //< 3 * N entries
std::map<std::string, FaceList > faces;
};
inline ObjModel parseObjModel( std::istream & in);
inline void tesselateObjModel( ObjModel & obj);
inline ObjModel tesselateObjModel( const ObjModel & obj );
inline Model convertToModel( const ObjModel & obj );
inline Model loadModel( std::istream & in );
inline Model loadModelFromString( const std::string & in );
inline Model loadModelFromFile( const std::string & in );
inline std::ostream & operator<<( std::ostream & out, const Model & m );
inline std::ostream & operator<<( std::ostream & out, const ObjModel::FaceVertex & f);
// ---------------------------- Implementation starts here -----------------------
inline bool ObjModel::FaceVertex::operator<( const ObjModel::FaceVertex & other ) const {
return (v < other.v) || (v == other.v && t < other.t ) || (v == other.v && t == other.t && n < other.n);
}
inline bool ObjModel::FaceVertex::operator==( const ObjModel::FaceVertex & other ) const {
return (v == other.v && t == other.t && n == other.n);
}
template <typename T>
inline std::istream & operator>>(std::istream & in, std::vector<T> & vec ){
T temp;
if(in >> temp)
vec.push_back(temp);
return in;
}
template <typename T>
inline std::istream & operator>>(std::istream & in, std::set<T> & vec ){
T temp;
if(in >> temp)
vec.insert(temp);
return in;
}
inline std::istream & operator>>( std::istream & in, ObjModel::FaceVertex & f){
if(in >> f.v){
if(in.peek() == '/'){
in.get();
in >> f.t;
in.clear();
if(in.peek() == '/'){
in.get();
in >> f.n;
in.clear();
}
}
in.clear();
--f.v;
--f.t;
--f.n;
}
// std::cout << f << std::endl;
return in;
}
ObjModel parseObjModel( std::istream & in ){
char line[1024];
std::string op;
std::istringstream line_in;
std::set<std::string> groups;
groups.insert("default");
ObjModel data;
while(in.good()){
in.getline(line, 1023);
line_in.clear();
line_in.str(line);
if(!(line_in >> op))
continue;
if(op == "v")
line_in >> data.vertex >> data.vertex >> data.vertex;
else if(op == "vt")
line_in >> data.texCoord >> data.texCoord >> data.texCoord;
else if(op == "vn")
line_in >> data.normal >> data.normal >> data.normal;
else if(op == "g"){
groups.clear();
while(line_in >> groups) ;
groups.insert("default");
}
else if(op == "f") {
std::vector<ObjModel::FaceVertex> list;
while(line_in >> list) ;
for(std::set<std::string>::const_iterator g = groups.begin(); g != groups.end(); ++g){
ObjModel::FaceList & fl = data.faces[*g];
fl.second.push_back(fl.first.size());
fl.first.insert(fl.first.end(), list.begin(), list.end());
}
}
}
for(std::map<std::string, ObjModel::FaceList>::iterator g = data.faces.begin(); g != data.faces.end(); ++g){
ObjModel::FaceList & fl = g->second;
fl.second.push_back(fl.first.size());
}
return data;
}
inline void tesselateObjModel( std::vector<ObjModel::FaceVertex> & input, std::vector<unsigned> & input_start){
std::vector<ObjModel::FaceVertex> output;
std::vector<unsigned> output_start;
output.reserve(input.size());
output_start.reserve(input_start.size());
for(std::vector<unsigned>::const_iterator s = input_start.begin(); s != input_start.end() - 1; ++s){
const unsigned size = *(s+1) - *s;
if(size > 3){
const ObjModel::FaceVertex & start_vertex = input[*s];
for( int i = 1; i < (int)size-1; ++i){
output_start.push_back(output.size());
output.push_back(start_vertex);
output.push_back(input[*s+i]);
output.push_back(input[*s+i+1]);
}
} else {
output_start.push_back(output.size());
output.insert(output.end(), input.begin() + *s, input.begin() + *(s+1));
}
}
output_start.push_back(output.size());
input.swap(output);
input_start.swap(output_start);
}
void tesselateObjModel( ObjModel & obj){
for(std::map<std::string, ObjModel::FaceList>::iterator g = obj.faces.begin(); g != obj.faces.end(); ++g){
ObjModel::FaceList & fl = g->second;
tesselateObjModel(fl.first, fl.second);
}
}
Model convertToModel( const ObjModel & obj ) {
// insert all face vertices into a vector and make unique
std::vector<ObjModel::FaceVertex> unique(obj.faces.find("default")->second.first);
std::sort(unique.begin(), unique.end());
unique.erase( std::unique(unique.begin(), unique.end()), unique.end());
// build a new model with repeated vertices/texcoords/normals to have single indexing
Model model;
for(std::vector<ObjModel::FaceVertex>::const_iterator f = unique.begin(); f != unique.end(); ++f){
model.vertex.insert(model.vertex.end(), obj.vertex.begin() + 3*f->v, obj.vertex.begin() + 3*f->v + 3);
if(!obj.texCoord.empty()){
const int index = (f->t > -1) ? f->t : f->v;
model.texCoord.insert(model.texCoord.end(), obj.texCoord.begin() + 2*index, obj.texCoord.begin() + 2*index + 2);
}
if(!obj.normal.empty()){
const int index = (f->n > -1) ? f->n : f->v;
model.normal.insert(model.normal.end(), obj.normal.begin() + 3*index, obj.normal.begin() + 3*index + 3);
}
}
// look up unique index and transform face descriptions
for(std::map<std::string, ObjModel::FaceList>::const_iterator g = obj.faces.begin(); g != obj.faces.end(); ++g){
const std::string & name = g->first;
const ObjModel::FaceList & fl = g->second;
std::vector<unsigned short> & v = model.faces[g->first];
v.reserve(fl.first.size());
for(std::vector<ObjModel::FaceVertex>::const_iterator f = fl.first.begin(); f != fl.first.end(); ++f){
const unsigned short index = std::distance(unique.begin(), std::lower_bound(unique.begin(), unique.end(), *f));
v.push_back(index);
}
}
return model;
}
ObjModel tesselateObjModel( const ObjModel & obj ){
ObjModel result = obj;
tesselateObjModel(result);
return result;
}
Model loadModel( std::istream & in ){
ObjModel model = parseObjModel(in);
tesselateObjModel(model);
return convertToModel(model);
}
Model loadModelFromString( const std::string & str ){
std::istringstream in(str);
return loadModel(in);
}
Model loadModelFromFile( const std::string & str) {
std::ifstream in(str.c_str());
return loadModel(in);
}
inline std::ostream & operator<<( std::ostream & out, const ObjModel::FaceVertex & f){
out << f.v << "\t" << f.t << "\t" << f.n;
return out;
}
std::ostream & operator<<( std::ostream & out, const Model & m ){
if(!m.vertex.empty()){
out << "vertex\n";
for(int i = 0; i < (int)m.vertex.size(); ++i)
out << m.vertex[i] << (((i % 3) == 2)?"\n":"\t");
}
if(!m.texCoord.empty()){
out << "texCoord\n";
for(int i = 0; i < (int)m.texCoord.size(); ++i)
out << m.texCoord[i] << (((i % 2) == 1)?"\n":"\t");
}
if(!m.normal.empty()){
out << "normal\n";
for(int i = 0; i < (int)m.normal.size(); ++i)
out << m.normal[i] << (((i % 3) == 2)?"\n":"\t");
}
if(!m.faces.empty()){
out << "faces\t";
for(std::map<std::string, std::vector<unsigned short> >::const_iterator g = m.faces.begin(); g != m.faces.end(); ++g){
out << g->first << " ";
}
out << "\n";
// for(int i = 0; i < m.face.size(); ++i)
// out << m.face[i] << (((i % 3) == 2)?"\n":"\t");
}
return out;
}
} // namespace obj
#endif // OBJLOAD_H_

107
cw 3/style.css Executable file
View File

@ -0,0 +1,107 @@
html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
body{
color:#444;
font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
font-size:12px;
line-height:1.5em;
padding:1em;
margin:auto;
max-width:42em;
background:#fefefe;
}
a{ color: #0645ad; text-decoration:none;}
a:visited{ color: #0b0080; }
a:hover{ color: #06e; }
a:active{ color:#faa700; }
a:focus{ outline: thin dotted; }
a:hover, a:active{ outline: 0; }
::-moz-selection{background:rgba(255,255,0,0.3);color:#000}
::selection{background:rgba(255,255,0,0.3);color:#000}
a::-moz-selection{background:rgba(255,255,0,0.3);color:#0645ad}
a::selection{background:rgba(255,255,0,0.3);color:#0645ad}
p{
margin:1em 0;
}
img{
max-width:100%;
}
h1,h2,h3,h4,h5,h6{
font-weight:normal;
color:#111;
line-height:1em;
}
h4,h5,h6{ font-weight: bold; }
h1{ font-size:2.5em; }
h2{ font-size:2em; }
h3{ font-size:1.5em; }
h4{ font-size:1.2em; }
h5{ font-size:1em; }
h6{ font-size:0.9em; }
blockquote{
color:#666666;
margin:0;
padding-left: 3em;
border-left: 0.5em #EEE solid;
}
hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
pre, code, kbd, samp { color: #000; font-family: monospace, monospace; _font-family: 'courier new', monospace; font-size: 0.98em; }
pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
b, strong { font-weight: bold; }
dfn { font-style: italic; }
ins { background: #ff9; color: #000; text-decoration: none; }
mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
sup { top: -0.5em; }
sub { bottom: -0.25em; }
ul, ol { margin: 1em 0; padding: 0 0 0 2em; }
li p:last-child { margin:0 }
dd { margin: 0 0 0 2em; }
img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; }
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
th { border-bottom: 1px solid black; }
td { vertical-align: top; }
@media only screen and (min-width: 480px) {
body{font-size:14px;}
}
@media only screen and (min-width: 768px) {
body{font-size:16px;}
}
@media print {
* { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
body{font-size:12pt; max-width:100%;}
a, a:visited { text-decoration: underline; }
hr { height: 1px; border:0; border-bottom:1px solid black; }
a[href]:after { content: " (" attr(href) ")"; }
abbr[title]:after { content: " (" attr(title) ")"; }
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
tr, img { page-break-inside: avoid; }
img { max-width: 100% !important; }
@page :left { margin: 15mm 20mm 15mm 10mm; }
@page :right { margin: 15mm 10mm 15mm 20mm; }
p, h2, h3 { orphans: 3; widows: 3; }
h2, h3 { page-break-after: avoid; }
}

BIN
cw 3/zad3_1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
cw 3/zad3_2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
cw 3/zad3_3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
cw 3/zad3_4.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

122
cw 3/zadania_3.html Executable file
View File

@ -0,0 +1,122 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>zadania_3</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" />
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h2 id="rzutowanie-perspektywiczne">Rzutowanie perspektywiczne</h2>
<p>Zadania <strong>main_3_1</strong> zaczynają się w miejscu, w którym skończyło się zadanie <strong>main_2_1</strong> z poprzednich zajęć. Widać w nim jedynie kwadrat, nie cały prostopadłościan. Wyświetlimy go w rzutowaniu perspektywicznym, dzięki temu otrzymamy iluzję trzech wymiarów.</p>
<h4 id="zadanie-1">Zadanie 1</h4>
<p>Macierz perspektywy tworzy funkcja <code>createPerspectiveMatrix()</code>, przyjrzyj się definicji tej funkcji. Prześlij macierz perspektywy do shadera.</p>
<p>Wynik wygląda nie do końca tak jakbyśmy się spodziewali. Wynika to z tego, że kamera znajduje się wewnątrz prostopadłościanu. Dodaj macierz kamery do macierzy transformacji, dzięki temu będzie można przesuwać kamerę za pomocą klawiszy. Przesuń prostopadłościan tak, żeby można go było zobaczyć od zewnątrz.</p>
<h4 id="zadanie-1-1">Zadanie 1*</h4>
<p>Zmodyfikuj macierz perspektywy. W funkcji <code>createPerspectiveMatrix()</code> znajduje się zmienna <code>frustumScale</code>, która odpowiada ona za kąt widzenia, zmodyfikuj jej wartość i zobacz jaki jest efekt. By obliczyć jej wartość możesz skorzystać ze wzoru $ S = $, gdzie <span class="math inline">\(fov\)</span> oznacza kąt widzenia.</p>
<h4 id="zadanie-1-2">Zadanie 1**</h4>
<p>Wciąż jest problem z rozciąganiem się obrazu przy zmianie kształtu okna. Rozwiązaniem jest wstawienie różnej wartości <strong>frustumScale</strong> dla współrzędnych <strong>X</strong> i <strong>Y</strong>. by to naprawić wykorzystaj funkcję <code>onReshape</code>, która jest wywoływana przy zmianie wielkości ekranu. Najpierw oblicz w niej proporcje ekranu i przypisz do zmiennej globalnej <code>screenRatio</code>. Następnie przemnóż odpowiednią współrzędną przez <code>screenRatio</code> w funkcji <code>createPerspectiveMatrix()</code>.</p>
<h2 id="obsługa-shaderów">Obsługa Shaderów</h2>
<p>W tej części zadań będziemy korzystać z innych obiektów, usuń z funkcji <code>init</code> inicjalizację prostopadłościanu i jego rysowanie z funkcji <code>renderScene</code> oraz zamień shadery na <code>shaders/shader_3_2.vert</code> i <code>shaders/shader_3_2.frag</code>.</p>
<h4 id="zadanie-2">Zadanie 2</h4>
<p>Wczytaj statek i sferę za pomocą do <code>loadModelToContext</code> do odpowiednich <code>Core::RenderContext</code>. Następnie wyświetl je za pomocą funkcji <code>Core::DrawContext</code>. Rozmieść je w różnych miejscach w przestrzeni.</p>
<h5 id="dodaj-możliwość-zmiany-kolorów-obiektów">Dodaj możliwość zmiany kolorów obiektów:</h5>
<p>Stwórz zmienną <code>uniform vec3 objectColor</code> w pliku <code>shader_3_2.frag</code> (jej definicja musi się ona znajdować nad definicją funkcji <code>main</code>), wykorzystamy ją do przesłania koloru w formacie RGB do shadera. Zmienna wbudowana <code>gl_FragColor</code> jest typu <code>vec4</code> w formacie RGBA, współrzędne przyjmują wartości od od 0 do 1. Do części RGB przypisz wartość <code>objectColor</code> a do A wartość 1.</p>
<p>Możemy teraz ustawić kolor rysowanego obiektu ustawiając wartość zmiennej <code>objectColor</code> przed rysowaniem obiektu. Robimy to korzystając z funkcji <code>glUniform3f( int location, float v0, float v1, float v2 )</code>, gdzie parametr <code>location</code> oznacza adres zmiennej w pamięci karty graficznej, do której chcemy wartości wysłać. Można ten adres uzyskać wywołując funkcje <code>glGetUniformLocation(program, "nazwa zmiennej")</code>.</p>
<h4 id="zadanie-2-1">Zadanie 2*</h4>
<p>Zmodyfikuj program tak, żeby kolor statku zmieniał się w czasie.</p>
<h4 id="zadanie-3">Zadanie 3</h4>
<p>Wyświetl “kolor” wektora normalnego do powierzchni w danym punkcie.</p>
<blockquote>
<p>Wektor normalny to wektor prostopadły do powierzchni w danym punkcie, pozwala on na przykład na policzenie odbicia światła.</p>
</blockquote>
<p>Wektor normalny wierzcholka dostępny jest w <em>vertex shaderze</em> (plik z rozszerzeniem <strong>.vert</strong>). Kolor powierzchni (piksela) ustala sie jednak we <em>fragment shaderze</em> (<strong>.frag</strong>). Zatem należy przesłać wartość wektora normalnego z <em>vertex</em> do <em>fragment</em> shadera. Służą do tego specjalne zmienne (interpolatory).</p>
<p>Stwórz zmienną typu <code>out vec3 nazwa</code> w <em>vertex shaderze</em> oraz odpowiadająca mu zmienna <code>in vec3 nazwa</code> we <em>fragment shaderze</em>. Prześlij przy jej użyciu wartość wektora normalnego.</p>
<p>Użyj tej wartości, aby w jakiś sposób przypisać kolor pikselowi.</p>
<p>Aby otrzymać ładny efekt, najpierw znormalizuj wektor otrzymany przez <em>fragment shader</em>. Następnie przeskaluj wartości (x, y, z) wektora z przedziału [-1, 1] do [0, 1] i przypisz je do kanałów R, G, B zmiennej <code>gl_FragColor</code>.</p>
<p>#### Zadanie 4 Stwórz funkcje <code>drawObject</code>, która ułatwi rysowanie wielu obiektów. Na liście parametrów musza znaleźć się referencja do <code>Core::RenderContext</code> oraz macierz modelu (<em>model matrix</em>) obiektu. Wyświetl kilka obiektów w różnych pozycjach (i obejrzyj je z każdej strony).</p>
<p>“Przyczep” model statku do kamery - uzależnij jego macierz modelu od pozycji i orientacji kamery tak, aby wyglądało jakbyś poruszał(a) się statkiem.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode c++"><code class="sourceCode cpp"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>glm::mat4 shipModelMatrix = </span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> glm::translate(cameraPos + cameraDir * <span class="fl">0.5</span><span class="bu">f</span> + glm::vec3(<span class="dv">0</span>,-<span class="fl">0.25</span><span class="bu">f</span>,<span class="dv">0</span>)) * </span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> glm::rotate(-cameraAngle + glm::radians(<span class="fl">90.0</span><span class="bu">f</span>), glm::vec3(<span class="dv">0</span>,<span class="dv">1</span>,<span class="dv">0</span>)) *</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> glm::scale(glm::vec3(<span class="fl">0.25</span><span class="bu">f</span>));</span></code></pre></div>
<p>Przeanalizuj tą macierz modelu lub napisz własną.</p>
<h4 id="zadanie-5">Zadanie 5</h4>
<p>Stwórz układ planetarny - jedna nieruchoma kule na środku (Słonce) i kilka orbitujących wokół niej planet. Niech przynajmniej jedna planeta ma księżyce.</p>
</body>
</html>

72
cw 3/zadania_3.md Executable file
View File

@ -0,0 +1,72 @@
## Rzutowanie perspektywiczne
Zadania **main_3_1** zaczynają się w miejscu, w którym skończyło się zadanie **main_2_1** z poprzednich zajęć. Widać w nim jedynie kwadrat, nie cały prostopadłościan. Wyświetlimy go w rzutowaniu perspektywicznym, dzięki temu otrzymamy iluzję trzech wymiarów.
#### Zadanie 1
Macierz perspektywy tworzy funkcja `createPerspectiveMatrix()`, przyjrzyj się definicji tej funkcji. Prześlij macierz perspektywy do shadera.
Wynik wygląda nie do końca tak jakbyśmy się spodziewali. Wynika to z tego, że kamera znajduje się wewnątrz prostopadłościanu. Dodaj macierz kamery do macierzy transformacji, dzięki temu będzie można przesuwać kamerę za pomocą klawiszy. Przesuń prostopadłościan tak, żeby można go było zobaczyć od zewnątrz.
#### Zadanie 1*
Zmodyfikuj macierz perspektywy. W funkcji `createPerspectiveMatrix()` znajduje się zmienna `frustumScale`, która odpowiada ona za kąt widzenia, zmodyfikuj jej wartość i zobacz jaki jest efekt. By obliczyć jej wartość możesz skorzystać ze wzoru $ S = \frac{1}{tan\left( \frac{fov}{2}* \frac{\pi}{2}\right)} $, gdzie $fov$ oznacza kąt widzenia.
#### Zadanie 1**
Wciąż jest problem z rozciąganiem się obrazu przy zmianie kształtu okna. Rozwiązaniem jest wstawienie różnej wartości **frustumScale** dla współrzędnych **X** i **Y**. by to naprawić wykorzystaj funkcję `onReshape`, która jest wywoływana przy zmianie wielkości ekranu. Najpierw oblicz w niej proporcje ekranu i przypisz do zmiennej globalnej `screenRatio`. Następnie przemnóż odpowiednią współrzędną przez `screenRatio` w funkcji `createPerspectiveMatrix()`.
## Obsługa Shaderów
W tej części zadań będziemy korzystać z innych obiektów, usuń z funkcji `init` inicjalizację prostopadłościanu i jego rysowanie z funkcji `renderScene` oraz zamień shadery na `shaders/shader_3_2.vert` i `shaders/shader_3_2.frag`.
#### Zadanie 2
Wczytaj statek i sferę za pomocą do `loadModelToContext` do odpowiednich `Core::RenderContext`. Następnie wyświetl je za pomocą funkcji `Core::DrawContext`. Rozmieść je w różnych miejscach w przestrzeni.
##### Dodaj możliwość zmiany kolorów obiektów:
Stwórz zmienną `uniform vec3 objectColor` w pliku `shader_3_2.frag` (jej definicja musi się ona znajdować nad definicją funkcji `main`), wykorzystamy ją do przesłania koloru w formacie RGB do shadera. Zmienna wbudowana `gl_FragColor` jest typu `vec4` w formacie RGBA, współrzędne przyjmują wartości od od 0 do 1. Do części RGB przypisz wartość `objectColor` a do A wartość 1.
Możemy teraz ustawić kolor rysowanego obiektu ustawiając wartość zmiennej `objectColor` przed rysowaniem obiektu. Robimy to korzystając z funkcji `glUniform3f( int location, float v0, float v1, float v2 )`, gdzie parametr `location` oznacza adres zmiennej w pamięci karty graficznej, do której chcemy wartości wysłać. Można ten adres uzyskać wywołując funkcje `glGetUniformLocation(program, "nazwa zmiennej")`.
#### Zadanie 2*
Zmodyfikuj program tak, żeby kolor statku zmieniał się w czasie.
#### Zadanie 3
Wyświetl "kolor" wektora normalnego do powierzchni w danym punkcie.
> Wektor normalny to wektor prostopadły do powierzchni w danym punkcie, pozwala on na przykład na policzenie odbicia światła.
Wektor normalny wierzcholka dostępny jest w *vertex shaderze* (plik z rozszerzeniem **.vert**). Kolor powierzchni (piksela) ustala sie jednak we *fragment shaderze* (**.frag**). Zatem należy przesłać wartość wektora normalnego z *vertex* do *fragment* shadera. Służą do tego specjalne zmienne (interpolatory).
Stwórz zmienną typu `out vec3 nazwa` w *vertex shaderze* oraz odpowiadająca mu zmienna `in vec3 nazwa` we *fragment shaderze*. Prześlij przy jej użyciu wartość wektora normalnego.
Użyj tej wartości, aby w jakiś sposób przypisać kolor pikselowi.
Aby otrzymać ładny efekt, najpierw znormalizuj wektor otrzymany przez *fragment shader*.
Następnie przeskaluj wartości (x, y, z) wektora z przedziału [-1, 1] do [0, 1] i przypisz je do kanałów R, G, B zmiennej `gl_FragColor`.
#### Zadanie 4
Stwórz funkcje `drawObject`, która ułatwi rysowanie wielu obiektów.
Na liście parametrów musza znaleźć się referencja do `Core::RenderContext` oraz macierz modelu (*model matrix*) obiektu.
Wyświetl kilka obiektów w różnych pozycjach (i obejrzyj je z każdej strony).
"Przyczep" model statku do kamery - uzależnij jego macierz modelu od pozycji i orientacji kamery tak, aby wyglądało jakbyś poruszał(a) się statkiem.
```C++
glm::mat4 shipModelMatrix =
glm::translate(cameraPos + cameraDir * 0.5f + glm::vec3(0,-0.25f,0)) *
glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0,1,0)) *
glm::scale(glm::vec3(0.25f));
```
Przeanalizuj tą macierz modelu lub napisz własną.
#### Zadanie 5
Stwórz układ planetarny - jedna nieruchoma kule na środku (Słonce) i kilka orbitujących wokół niej planet.
Niech przynajmniej jedna planeta ma księżyce.

85
cw 4/cw4.md Executable file
View File

@ -0,0 +1,85 @@
### 0. (Jeżeli nie zrobiłeś poprzednich zadań związanych z shaderami)
Obejrzyj pliki shader_4_1.vert i shader_4_1.frag. Zwróć uwagę w szczególności na zmienna interpNormal, przy uzyciu ktorej wektory normalne wierzchołków dostępne w vertex shaderze przesyłane są do fragment shadera. Pliki shader_4_2.vert i shader_4_2.frag na razie nie będą wykorzystywane
### 1. Oblicz we fragment shaderze oświetlenie obiektu przy użyciu modelu Phonga dla światła rozproszonego (`diffuse`):
a) Przekaż źródło światła. Na razie przyjmiemy kierunkowy model oświetlenia, dlatego źródło będzie opisane jako wektor kierunkowy:
- Prześlij do *fragment shadera* zmienna typu `uniform vec3` (nazwij ją np. `lightDir`), w której będzie się znajdować wektor kierunkowy:
- Należy to zrobić podobnie do tego, jak przesyłana jest zmienna `objectColor`. Jedyna różnica będzie taka, ze kierunek padania światła nie zależy od obiektu, wiec wywołanie `glUniform3f` powinno pojawić się tylko raz, przed rysowaniem wszystkich obiektów.
- Jako kierunek światła wybierz dowolny wektor jednostkowy. (Możesz wziąć dowolny niezerowy wektor następnie go znormalizować)
b) Oblicz natężenie:
- znormalizuj wektor normalny przed użyciem go w obliczeniach (uśrednianie wektorów normalnych wierzchołków może spowodować, ze przestaje one być jednostkowe).
- Natężenie to iloczyn skalarny wektora normalnego powierzchni i odwrotnego wektora kierunku padania światła. Skorzystaj z funkcji `dot`.
- Natężenie nie może być ujemne. Przytnij natężenie do zera przy użyciu: `x = max(x, 0.0)`
c) Zastosuj obliczone natężenie aby zmodyfikować kolor obiektu:
- Przemnóż kolor RGB piksela przez obliczone natężenie.
### 2. Dlaczego oświetlenie statku nie zmienia się podczas jego obracania?
(Wektory normalne są w układzie lokalnym modelu, a wektor padania światła w układzie świata)
Należy wykonać transformacje wektorów normalnych do przestrzeni świata:
- Prześlij macierz modelu rysowanego obiektu (*model Matrix*) jako osobna zmienna do *vertex shadera* (`uniform mat4`).
- Przemnóż przez te macierz wektor normalny wierzchołka przed przeslaniem go do *fragment shadera*.
- Współrzędna **w** dopisana do wektora przed mnożeniem przez macierz powinna być ustawiona na 0. Wynika to z tego, ze w przypadku transformacji wektorów reprezentujących kierunki w przestrzeni, nie chcemy dokonywać translacji - np. wektor normalny do powierzchni zależy od orientacji obiektu, ale nie od jego pozycji (przesunięcia) w przestrzeni świata.
### 3. Uzupełnił model o czynnik światła odbitego (`specular`). W tym celu:
a) Potrzebny będzie wektor od rysowanego fragmentu do pozycji kamery:
- Wyślij pozycje kamery (`cameraPos`) jako kolejna zmienna do *fragment shadera*.
- Podobnie jak wektory normalne prześlij z *vertex* do *fragment shadera* pozycje wierzchołków (`vertexPosition`) w przestrzeni świata (czyli pomnożone przez macierz *modelMatrix*). Pamiętaj, ze tym razem wektory reprezentują punkty, a nie kierunki - współrzędna **w** przed mnożeniem musi być ustawiona na 1. W wyniku rasteryzacji otrzymamy w shaderze fragmentu jego pozycję (nazywaną pozycją fragmentu)
- Oblicz wektor **V** jako znormalizowaną różnice pozycji kamery i pozycji fragmentu.
b) Oblicz natężenie światła odbitego we *fragment shaderze*:
- Oblicz wektor kierunku odbicia światła **R** przy użyciu funkcji [`reflect`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/reflect.xhtml). Pamiętaj, żeby przesłać do funkcji odwrócony wektor kierunku światła.
- Oblicz natężenie: iloczyn skalarny **V** i **R**, przycięty do zera ( `max(...,0.0)` ), a następnie podniesiony do wysokiej potęgi (np. 8, 50, 1000), która jest miara połyskliwości powierzchni
c) Ustal ostateczny kolor piksela na `objectColor * diffuse + vec3(1.0) * specular`. Oznacza to najprostszy przypadek, gdy kolor światła odbitego jest biały.
### 4. Stwórz układ planetarny - jedna nieruchoma kule na środku (Słonce) i kilka orbitujących wokół niej planet.
Niech przynajmniej jedna planeta ma księżyce.
### 5. W układzie planetarnym obiektem oświetlającym powinno być słońce, dlatego zamień oświetlenie kierunkowe na punktowe:
- Zamiast przesyłać (w `lightDir`) kierunek światła, prześlij pozycję słońca (taką jak ustawiłeś w punkcie powyżej) jako uniform vec3 (nazwij go `lightPos`).
- Oblicz kierunek światła odejmując od pozycji fragmentu pozycję światła i normalizując ją. Zapisz wynik w zmiennej `lightDir`.
- Słońce będzie czarne, nie martw się tym, tylko spójrz na punkt następny
### 6. Źródło światła znajduje się wewnątrz kuli, która reprezentuje słońce, dlatego jest czarna. By to naprawić napisz osobny shader, który będzie odpowiadać za renderowanie słońca.
a) zainicjalizuj shader:
- Pliki **shader_4_2.vert**_ i **shader_4_2.frag** są identyczne jak **4_1** na przed zmianami, będą punktem wyjścia dla *shadera* słońca.
- Utwórz zmienną globalną `GLuint programSun` na shader słońca. Załaduj do niej powyższe shadery w funkcji init. (skorzystaj z `shaderLoader.CreateProgram`).
b) zmień shader dla słońca:
- funkcja `drawObject` korzysta z globalnej zmiennej `program` jako shader. Zmodyfikuj funkcję tak, żeby shader był jej argumentem.
- dodaj odpowiedni shader w wywołaniach `drawObject`
- Musisz zmienić shader na `programSun` na czas rysowania słońca przy użyciu funkcji `glUseProgram.` Pamiętaj, żeby nie rysować tym shaderem innych obiektów. (Najprościej będzie rysować słońce po wszystkich innych obiektach).
### 7.* Zmień shader słońca na bardziej realistyczny.
Na poniższym obrazku jest zdjęcie słońca. jest ono ciemniejsze na brzegach spróbuj uzyskać podobny efekt. Przydadzą się wektory z poprzednich punktów, jak wektor normalny i wektor **V**.
![](https://wi-images.condecdn.net/image/DEGypMQdE59/crop/1020/f/sunmeta.jpg)

101
cw 4/exercises 4.html Executable file
View File

@ -0,0 +1,101 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>exercises 4</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="style.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h2 id="i-phong-illumination-model">I Phong illumination model</h2>
<h3 id="i.0.-do-it-if-you-havent-done-previous-exercises-connected-to-shaders">I.0. (Do it if you havent done previous exercises connected to shaders)</h3>
<p>Took at the files <strong>shader_4_1.vert</strong> i <strong>shader_4_1.frag</strong>. Note how <em>normal vectors</em> are sent from <strong>vertex shader</strong> to <strong>fragment shader</strong> with variable <code>interpNormal</code>. Files shader_4_2.vert i shader_4_2.frag wont be used for now.</p>
<h3 id="i.1.-calculate-diffuse-phong-lightning-intensity-in-the-fragment-shader">I.1. Calculate diffuse Phong lightning intensity in the fragment shader:</h3>
<ol type="a">
<li>Send a light source. For now we will use directional light source, thus the light will be described by a unit vector:</li>
</ol>
<ul>
<li><p>Send to the fragment shader a variable of type <code>uniform vec3</code> (name it eg. <code>lightDir</code>), it will contain the light direction:</p></li>
<li><p>Do it the same way as <code>objectColor</code> is sent. Only difference is that the light direction is independent form a object, thus call of <code>glUniform3f</code> should be done only once before any draw call. Call <code>glUseProgram(program)</code> before sending the value.</p></li>
<li><p>As a light direction pick any unit vector. (You can take any nonzero vector and normalize it)</p></li>
</ul>
<ol start="2" type="a">
<li>Calculate diffusion intensity in fragment shader:</li>
</ol>
<ul>
<li><p>normalize the normal vector before using it (averaging during rasterization could have changed their size).</p></li>
<li><p>Intensity is equal to a dot product of surface normal vector and inverse light direction vector. Use the function <code>dot</code>.</p></li>
<li><p>Intensity cannot be negative. clamp it to zero from bellow with max function: <code>x = max(x, 0.0)</code></p></li>
</ul>
<ol start="3" type="a">
<li>Use calculated intensity to modify object color:</li>
</ol>
<ul>
<li>Multiply RGB values of the fragment wth the diffusion intensity.</li>
</ul>
<h3 id="i.2.-why-spaceship-illumination-is-not-changing-with-rotation">I.2. Why spaceship illumination is not changing with rotation?</h3>
<p>(Normal vectors are in local model space and the light direction vector is in world space)</p>
<p>All vertex normal vectors have to be transformed into world space:</p>
<ul>
<li><p>Send the model matrix of the object drawn as a separate variable to the vertex shader (<code>uniform mat4</code>).</p></li>
<li><p>Multiply the normal vector in the shader with the model matrix before sending it to the fragment shader.</p></li>
<li><p>The <strong>w</strong> coordinate of the normal vector has to be set to 0 before multipication with the model matrix. This is because the normal vector is a direction and not a point in homogeneous coordinates. We do not want to translate it during homogenization.</p></li>
</ul>
<h3 id="i.3.-add-specular-phong-lighting-to-the-model.">I.3. Add specular Phong lighting to the model.</h3>
<ol type="a">
<li>Define a vector describing the view direction (it depends on the surface and camera positions):</li>
</ol>
<ul>
<li><p>Send the camera position (<code>cameraPos</code>) as another variable to the fragment shader.</p></li>
<li><p>Analogously to the normal vectors of the vertex shader, send the vertex positions from vertex to fragment shader (vertexPosition) in world space (multiplied with the modelMatrix). This time around the vectors represent points and not directions - the <strong>w</strong> coordinate of the vertex positions has to be set to 1. In the result of rasterization we will recive fragment position in the fragment shader.</p></li>
<li><p>Calculate vector <strong>V</strong> (<em>view direciton vecor</em>) as a normalized difference of the camera position and the fragment position.</p></li>
</ul>
<ol start="2" type="a">
<li>Calculate specular light intensity in the fragment shader:</li>
</ol>
<ul>
<li><p>Obtain the reflected light direction <strong>R</strong> using the glsl function <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/reflect.xhtml"><code>reflect</code></a>. Remember to that light direction vector must be inverse.</p></li>
<li><p>Calculate the light intensity: dot product of <strong>V</strong> i <strong>R</strong>, clamped to zero ( <code>max(...,0.0)</code> )and then raised to high power (np. 8, 50, 1000), which is a measure of brilliancy.</p></li>
</ul>
<ol start="3" type="a">
<li>The shaded pixel color is: objectColor * diffuse + vec3(1.0) * specular. This describes the simplest case when the reflected light color is white.</li>
</ol>
<h3 id="i.4.-create-planetary-system---one-stationary-sphere-in-the-center-and-a-few-orbiting-planets.-at-least-one-planet-should-have-some-moons.">I.4. Create planetary system - one stationary sphere in the center and a few orbiting planets. At least one planet should have some moons.</h3>
<h3 id="i.5.-a-planetary-system-should-be-lit-by-a-sun-therefore-change-directional-lighting-to-point-lightning">I.5. A planetary system should be lit by a sun, therefore change directional lighting to point lightning :</h3>
<ul>
<li><p>Instead of sending (in <code>lightDir</code>) light direction, send the sun position to the fragment shader (the same that you set in the exercise above) as <code>uniform vec3</code> (call it <code>lightPos</code>).</p></li>
<li><p>Calculate the light direction by subtracting the sun position from the fragment position. Normalize the result and save it in the <code>lightDir</code> variable.</p></li>
<li><p>Sun will be black, dont worry about it, it will be fixed in the next task.</p></li>
</ul>
<h3 id="i.6.-light-source-is-inside-of-the-sphere-that-represents-the-sun-thus-it-is-black.-to-fix-it-create-another-shader-that-will-be-responsible-for-rendering-the-sun.">I.6. Light source is inside of the sphere that represents the sun, thus it is black. To fix it create another shader, that will be responsible for rendering the sun.</h3>
<p>Goal of this exercise is to create a shader (<strong>shader_4_sun.vert</strong>_ i <strong>shader_4_sun.frag</strong>), that will be responsible only for rendering the sun. Previous shaders (<strong>shader_4_1.vert</strong>_ i <strong>shader_4_1.frag</strong>) should still render other objects.</p>
<ol type="a">
<li>initialize <em>program</em> (shaders):</li>
</ol>
<ul>
<li><p>Files <strong>shader_4_sun.vert</strong> and <strong>shader_4_sun.frag</strong> are identical to <strong>4_1</strong> before your modifications, they will be starting point for sun shader.</p></li>
<li><p>Create global variable <code>GLuint programSun</code> which will be used to store sun shader address. Create <em>program</em> with <code>shaderLoader.CreateProgram</code> analogously to creation of <code>program</code> from <strong>shader_4_1.vert</strong> i <strong>shader_4_1.frag</strong> (input values are paths to vertex and fragment shaders <strong>shader_4_sun.vert</strong> i <strong>shader_4_sun.frag</strong>).</p></li>
</ul>
<ol start="2" type="a">
<li>Im more complex projects different types of objects are drawn with different shaders, thus architecture, that will allow it, is required in the application. Set appropriate <em>program</em> for sun rendering</li>
</ol>
<p>-function <code>drawObject</code> uses the global function <code>program</code>, to point drawing shaders. Add a function argument, which should contain a program address used in rendering.</p>
<p>-add appropriate program to <code>drawObject</code> calls.</p>
<h3 id="i.7.-change-sun-shader-to-more-realistic.">I.7.* Change sun shader to more realistic.</h3>
<p>On the picture bellow you can see a sun. It is darker on the corners, try to get a similar effect. Vectors from previous points will be useful, especially normal vector and the vector <strong>V</strong>.</p>
<p><img src="https://wi-images.condecdn.net/image/DEGypMQdE59/crop/1020/f/sunmeta.jpg" /></p>
</body>
</html>

113
cw 4/grk-cw4.vcxproj Executable file
View File

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main_4_1.cpp" />
<ClCompile Include="src\Render_Utils.cpp" />
<ClCompile Include="src\Shader_Loader.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Camera.h" />
<ClInclude Include="src\objload.h" />
<ClInclude Include="src\Render_Utils.h" />
<ClInclude Include="src\Shader_Loader.h" />
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_4_1.frag" />
<None Include="shaders\shader_4_1.vert" />
<None Include="shaders\shader_4_sun.frag" />
<None Include="shaders\shader_4_sun.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C9BB5347-723E-4274-B60A-4A69989E9DC3}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>grk-cw4</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>grk-cw4</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp\Release;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlibd.lib;assimp-vc141-mtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlib.lib;assimp-vc141-mt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

65
cw 4/grk-cw4.vcxproj.filters Executable file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Shader Files">
<UniqueIdentifier>{0a247bb8-2e8e-4a90-b0ef-17415b0941ba}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Render_Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Shader_Loader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Box.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\main_4_1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\objload.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Render_Utils.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Shader_Loader.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Camera.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_4_sun.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_sun.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_1.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_1.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

4
cw 4/grk-cw4.vcxproj.user Executable file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

315
cw 4/models/spaceship.obj Executable file
View File

@ -0,0 +1,315 @@
# Blender v2.90.0 OBJ File: 'spaceship.blend'
# www.blender.org
mtllib spaceship.mtl
o spaceship
v -0.466043 -0.046099 0.061004
v -0.496632 -0.038727 -0.744142
v -0.284772 -0.093266 -0.411636
v -0.169612 -0.147446 -0.381196
v -0.169612 -0.147446 0.061004
v -0.091309 -0.100093 0.472421
v -0.182617 -0.069341 0.472421
v -0.182617 -0.001722 0.472421
v -0.466043 0.045632 0.061004
v -0.647568 0.071442 -0.238048
v -0.169612 0.164038 0.061004
v -0.284772 0.045632 -0.411636
v -0.169612 0.116537 -0.381196
v -0.053437 -0.049075 0.720448
v -0.053437 -0.102143 0.720448
v -0.040834 -0.049075 0.734564
v -0.040834 -0.102143 0.734564
v 0.000000 -0.049075 0.744142
v 0.000000 -0.118734 0.744142
v 0.040834 -0.049075 0.734564
v 0.000000 0.045779 0.472421
v 0.000000 -0.116684 0.472421
v 0.091309 -0.100093 0.472421
v 0.040834 -0.102143 0.734564
v 0.000000 0.116537 -0.350755
v 0.000000 0.164038 0.061004
v 0.169612 -0.147446 -0.381196
v 0.000000 -0.164038 -0.350755
v 0.169612 0.164038 0.061004
v 0.169612 0.116537 -0.381196
v 0.000000 -0.164038 0.061004
v 0.169612 -0.147446 0.061004
v -0.647568 -0.038727 -0.238048
v -0.496632 0.071442 -0.744142
v -0.091309 0.045779 0.472421
v 0.466043 -0.046099 0.061004
v 0.647568 0.071442 -0.238048
v 0.466043 0.045632 0.061004
v 0.496632 -0.038727 -0.744142
v 0.647568 -0.038727 -0.238048
v 0.284772 -0.093266 -0.411636
v 0.182617 -0.001722 0.472421
v 0.182617 -0.069341 0.472421
v 0.284772 0.045632 -0.411636
v 0.053437 -0.049075 0.720448
v 0.053437 -0.102143 0.720448
v 0.496632 0.071442 -0.744142
v 0.091309 0.045779 0.472421
vt 0.542758 0.543965
vt 0.356004 0.244407
vt 0.504680 0.319696
vt 0.553316 0.302407
vt 0.649859 0.471001
vt 0.766053 0.611338
vt 0.733075 0.633795
vt 0.942531 0.273938
vt 0.916601 0.470616
vt 0.908930 0.272020
vt 0.906245 0.133229
vt 0.060793 0.659810
vt 0.095301 0.442790
vt 0.182444 0.620892
vt 0.912119 0.905444
vt 0.989612 0.943366
vt 0.900946 0.955153
vt 0.229586 0.822972
vt 0.045790 0.812939
vt 0.871970 0.876051
vt 0.270733 0.797357
vt 0.928563 0.581569
vt 0.948002 0.582679
vt 0.928200 0.588981
vt 0.833604 0.696984
vt 0.841128 0.699424
vt 0.941370 0.472030
vt 0.927606 0.601110
vt 0.953122 0.602566
vt 0.116239 0.298971
vt 0.134935 0.296266
vt 0.170287 0.416872
vt 0.947639 0.590091
vt 0.858040 0.692927
vt 0.798664 0.589407
vt 1.000000 0.000000
vt 0.975078 0.013585
vt 0.974484 0.001457
vt 0.830416 0.568707
vt 0.869911 0.680359
vt 0.785184 0.955792
vt 0.850736 0.970525
vt 0.334379 0.757520
vt 0.252163 0.593452
vt 0.740866 0.846584
vt 0.807753 0.855379
vt 0.321881 0.566013
vt 0.410170 0.742478
vt 0.620171 0.273802
vt 0.672876 0.223217
vt 0.710068 0.430790
vt 0.769418 0.391811
vt 0.946599 0.135534
vt 0.413299 0.472597
vt 0.208789 0.994633
vt 0.953122 0.002304
vt 0.980750 0.982793
vt 0.912767 0.000000
vt 0.101366 0.309478
vt 0.132755 0.431644
vt 0.099001 0.317265
vt 0.989409 0.328628
vt 0.953122 0.469337
vt 0.955808 0.330547
vt 0.871271 0.326374
vt 0.706080 0.012535
vt 0.869769 0.170254
vt 0.705415 0.186739
vt 0.963479 0.131951
vt 0.988248 0.130536
vt 0.443922 0.509019
vt 0.463695 0.730833
vt 0.578150 0.603414
vt 0.692001 0.855970
vt 0.680828 0.905679
vt 0.605734 0.857085
vt 0.719632 0.941058
vt 0.975441 0.020998
vt 0.994879 0.019888
vt 0.142931 0.299975
vt 0.245429 0.383703
vt 0.994516 0.012475
vt 0.871271 0.672035
vt 0.861802 0.548533
vt 0.993477 0.467033
vt 1.000000 0.600262
vt 0.959645 0.602566
vt 0.617066 0.833945
vt 0.596872 0.896513
vt 0.207819 0.402100
vn -0.2502 -0.9682 0.0006
vn -0.3235 -0.9462 -0.0000
vn -0.3158 -0.9343 0.1651
vn -0.3186 -0.9329 0.1677
vn -0.3148 -0.9349 0.1641
vn -0.8235 0.0000 0.5673
vn -0.8548 0.0000 0.5189
vn -0.3487 0.8731 0.3407
vn 0.8434 0.0000 -0.5374
vn -0.4103 -0.9095 -0.0666
vn 0.0862 0.9958 0.0321
vn 0.0832 0.9962 0.0257
vn 0.0868 0.9957 0.0333
vn 0.2556 0.0000 -0.9668
vn -0.5043 0.8586 -0.0922
vn -0.8869 0.0000 0.4619
vn -0.7459 0.0000 0.6660
vn 0.0112 -0.9999 -0.0100
vn -0.2284 0.0000 0.9736
vn 0.0771 0.9413 0.3286
vn -0.1788 -0.9839 -0.0074
vn 0.2284 0.0000 0.9736
vn 0.3892 -0.9187 0.0677
vn 0.1766 0.0000 -0.9843
vn 0.0000 0.9934 -0.1146
vn -0.1766 0.0000 -0.9843
vn -0.0192 0.9941 -0.1068
vn 0.0974 -0.9952 -0.0000
vn -0.0974 -0.9952 -0.0000
vn -0.0965 -0.9866 0.1319
vn 0.1776 -0.9776 0.1125
vn -0.0272 -0.9996 -0.0081
vn 0.0827 0.9963 0.0247
vn -0.9583 -0.0000 -0.2858
vn -0.3892 -0.9187 0.0677
vn 0.0000 0.9403 0.3403
vn -0.4230 0.8237 0.3776
vn -0.4240 0.8230 0.3780
vn -0.4228 0.8239 0.3775
vn 0.0192 0.9941 -0.1068
vn -0.3672 0.9194 -0.1408
vn 0.0000 0.9611 0.2763
vn -0.4366 0.8392 0.3243
vn -0.3189 -0.9328 0.1681
vn -0.4270 0.8209 0.3792
vn -0.0771 0.9413 0.3286
vn -0.1776 -0.9776 0.1125
vn 0.1788 -0.9839 -0.0074
vn -0.3189 -0.9469 0.0409
vn 0.8548 -0.0000 0.5189
vn 0.0272 -0.9996 -0.0081
vn 0.4103 -0.9095 -0.0666
vn 0.3158 -0.9343 0.1651
vn 0.3186 -0.9329 0.1677
vn 0.3189 -0.9328 0.1681
vn 0.8235 0.0000 0.5673
vn 0.3672 0.9194 -0.1408
vn -0.0868 0.9957 0.0333
vn -0.0832 0.9962 0.0257
vn -0.0862 0.9958 0.0321
vn 0.2502 -0.9682 0.0006
vn -0.2556 0.0000 -0.9668
vn -0.8434 0.0000 -0.5374
vn 0.7459 0.0000 0.6660
vn 0.4228 0.8239 0.3775
vn 0.4240 0.8230 0.3780
vn 0.4230 0.8237 0.3776
vn 0.3189 -0.9469 0.0409
vn 0.8869 0.0000 0.4619
vn 0.9583 -0.0000 -0.2858
vn -0.0827 0.9963 0.0247
vn -0.0112 -0.9999 -0.0100
vn 0.4270 0.8209 0.3792
vn 0.5043 0.8586 -0.0922
vn 0.3487 0.8731 0.3407
vn 0.3235 -0.9462 -0.0000
vn 0.0965 -0.9866 0.1319
vn 0.4366 0.8392 0.3243
vn 0.3148 -0.9349 0.1641
usemtl cube1_auv
s 1
f 1/1/1 2/2/1 3/3/1
f 1/1/2 4/4/2 5/5/2
f 1/1/3 6/6/4 7/7/5
f 1/8/6 8/9/6 9/10/6
f 9/10/7 10/11/7 1/8/7
f 9/12/8 8/13/8 11/14/8
f 3/15/9 2/16/9 12/17/9
f 3/3/10 4/4/10 1/1/10
f 12/18/11 10/19/12 9/12/13
f 12/17/14 4/20/14 3/15/14
f 12/18/15 11/14/15 13/21/15
f 14/22/16 8/9/16 15/23/16
f 15/23/17 16/24/17 14/22/17
f 15/25/18 6/6/18 17/26/18
f 15/23/16 8/9/16 7/27/16
f 18/28/19 16/24/19 19/29/19
f 18/30/20 20/31/20 21/32/20
f 19/29/19 16/24/19 17/33/19
f 19/34/21 6/6/21 22/35/21
f 19/36/22 20/37/22 18/38/22
f 19/34/23 23/39/23 24/40/23
f 25/41/24 4/20/24 13/42/24
f 25/43/25 11/14/25 26/44/25
f 25/41/26 27/45/26 28/46/26
f 25/43/27 29/47/27 30/48/27
f 28/46/24 4/20/24 25/41/24
f 28/49/28 27/50/28 31/51/28
f 26/44/25 29/47/25 25/43/25
f 31/51/29 4/4/29 28/49/29
f 31/51/30 6/6/30 5/5/30
f 31/51/28 27/50/28 32/52/28
f 31/51/31 23/39/31 22/35/31
f 33/53/7 1/8/7 10/11/7
f 33/54/32 2/2/32 1/1/32
f 10/19/12 12/18/11 34/55/33
f 10/11/34 2/56/34 33/53/34
f 34/57/9 12/17/9 2/16/9
f 34/58/34 2/56/34 10/11/34
f 17/33/17 16/24/17 15/23/17
f 17/26/35 6/6/35 19/34/35
f 16/59/36 21/32/36 35/60/36
f 16/59/37 8/13/38 14/61/39
f 13/42/14 4/20/14 12/17/14
f 13/21/40 11/14/40 25/43/40
f 11/14/41 12/18/41 9/12/41
f 11/14/42 21/32/42 26/44/42
f 11/14/43 8/13/43 35/60/43
f 5/5/29 4/4/29 31/51/29
f 5/5/44 6/6/4 1/1/3
f 35/60/42 21/32/42 11/14/42
f 35/60/45 8/13/38 16/59/37
f 21/32/46 16/59/46 18/30/46
f 21/32/42 29/47/42 26/44/42
f 22/35/47 6/6/47 31/51/47
f 22/35/48 23/39/48 19/34/48
f 7/7/49 6/6/49 15/25/49
f 7/27/6 8/9/6 1/8/6
f 36/62/50 37/63/50 38/64/50
f 36/65/51 39/66/51 40/67/51
f 36/65/52 27/50/52 41/68/52
f 36/65/53 23/39/54 32/52/55
f 36/62/56 42/69/56 43/70/56
f 38/71/57 44/72/57 29/47/57
f 38/71/58 37/73/59 44/72/60
f 38/64/56 42/69/56 36/62/56
f 41/68/61 39/66/61 36/65/61
f 41/74/62 27/45/62 44/75/62
f 44/75/63 39/76/63 41/74/63
f 44/75/62 27/45/62 30/77/62
f 45/78/64 20/37/64 46/79/64
f 45/80/65 42/81/66 20/31/67
f 46/79/64 20/37/64 24/82/64
f 46/83/68 23/39/68 43/84/68
f 46/79/69 42/69/69 45/78/69
f 40/85/70 39/86/70 37/63/70
f 37/63/50 36/62/50 40/85/50
f 37/63/70 39/86/70 47/87/70
f 47/88/71 44/72/60 37/73/59
f 39/76/63 44/75/63 47/89/63
f 24/82/22 20/37/22 19/36/22
f 24/40/72 23/39/72 46/83/72
f 20/31/67 42/81/66 48/90/73
f 30/77/26 27/45/26 25/41/26
f 30/48/74 29/47/74 44/72/74
f 29/47/42 21/32/42 48/90/42
f 29/47/75 42/81/75 38/71/75
f 32/52/76 27/50/76 36/65/76
f 32/52/77 23/39/77 31/51/77
f 48/90/36 21/32/36 20/31/36
f 48/90/78 42/81/78 29/47/78
f 43/84/79 23/39/54 36/65/53
f 43/70/69 42/69/69 46/79/69

2500
cw 4/models/sphere.obj Executable file

File diff suppressed because it is too large Load Diff

19
cw 4/shaders/shader_4_1.frag Executable file
View File

@ -0,0 +1,19 @@
#version 430 core
uniform vec3 objectColor;
uniform vec3 lightDir;
uniform vec3 cameraPos;
in vec3 interpNormal;
in vec3 normalVertexPosition;
void main()
{
float intensity = dot(interpNormal, 1 - normalize(lightDir));
intensity = max(intensity, 0.0);
gl_FragColor = vec4(objectColor * intensity, 1.0);
vec3 v = cameraPos - normalVertexPosition;
vec3 r = reflect(normalVertexPosition, 1 - lightDir);
float specular = pow(max(v * r, 0.0), 8);
gl_FragColor = vec4((objectColor * diffuse + vec3(1.0) * specular), 1.0);
}

18
cw 4/shaders/shader_4_1.vert Executable file
View File

@ -0,0 +1,18 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 1) in vec3 vertexNormal;
uniform mat4 modelMatrix;
uniform mat4 transformation;
out vec3 interpNormal;
out vec3 normalVertexPosition;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
interpNormal = (vec4(vertexNormal, 0) * modelMatrix).xyz;
vec3 normalVertexPosition = (vec4(vertexPosition, 1) * modelMatrix).xyz;
}

10
cw 4/shaders/shader_4_sun.frag Executable file
View File

@ -0,0 +1,10 @@
#version 430 core
uniform vec3 objectColor;
in vec3 interpNormal;
void main()
{
gl_FragColor = vec4(objectColor, 1.0);
}

15
cw 4/shaders/shader_4_sun.vert Executable file
View File

@ -0,0 +1,15 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec2 vertexTexCoord;
layout(location = 2) in vec3 vertexNormal;
uniform mat4 transformation;
out vec3 interpNormal;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
interpNormal = vertexNormal;
}

104
cw 4/src/Box.cpp Executable file
View File

@ -0,0 +1,104 @@
// dane 36 wierzcholkow i kolorow opisujace model pudelka
const float boxPositions[] = {
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
};
const float boxColors[] = {
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
};

31
cw 4/src/Camera.cpp Executable file
View File

@ -0,0 +1,31 @@
#include "Camera.h"
glm::mat4 Core::createPerspectiveMatrix(float zNear, float zFar, float frustumScale)
{
glm::mat4 perspective;
perspective[0][0] = 1.f;
perspective[1][1] = frustumScale;
perspective[2][2] = (zFar + zNear) / (zNear - zFar);
perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
perspective[2][3] = -1;
perspective[3][3] = 0;
return perspective;
}
glm::mat4 Core::createViewMatrix( glm::vec3 position, glm::vec3 forward, glm::vec3 up )
{
glm::vec3 side = glm::cross(forward, up);
// Trzeba pamietac o minusie przy ustawianiu osi Z kamery.
// Wynika to z tego, ze standardowa macierz perspektywiczna zaklada, ze "z przodu" jest ujemna (a nie dodatnia) czesc osi Z.
glm::mat4 cameraRotation;
cameraRotation[0][0] = side.x; cameraRotation[1][0] = side.y; cameraRotation[2][0] = side.z;
cameraRotation[0][1] = up.x; cameraRotation[1][1] = up.y; cameraRotation[2][1] = up.z;
cameraRotation[0][2] = -forward.x; cameraRotation[1][2] = -forward.y; cameraRotation[2][2] = -forward.z;
glm::mat4 cameraTranslation;
cameraTranslation[3] = glm::vec4(-position, 1.0f);
return cameraRotation * cameraTranslation;
}

14
cw 4/src/Camera.h Executable file
View File

@ -0,0 +1,14 @@
#pragma once
#include "glm.hpp"
namespace Core
{
glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f, float frustumScale = 1.f);
// position - pozycja kamery
// forward - wektor "do przodu" kamery (jednostkowy)
// up - wektor "w gore" kamery (jednostkowy)
// up i forward musza byc ortogonalne!
glm::mat4 createViewMatrix(glm::vec3 position, glm::vec3 forward, glm::vec3 up);
}

169
cw 4/src/Render_Utils.cpp Executable file
View File

@ -0,0 +1,169 @@
#include "Render_Utils.h"
#include <algorithm>
#include "glew.h"
#include "freeglut.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
void Core::RenderContext::initFromOBJ(obj::Model& model)
{
vertexArray = 0;
vertexBuffer = 0;
vertexIndexBuffer = 0;
unsigned int vertexDataBufferSize = sizeof(float) * model.vertex.size();
unsigned int vertexNormalBufferSize = sizeof(float) * model.normal.size();
unsigned int vertexTexBufferSize = sizeof(float) * model.texCoord.size();
size = model.faces["default"].size();
unsigned int vertexElementBufferSize = sizeof(unsigned short) * size;
glGenVertexArrays(1, &vertexArray);
glBindVertexArray(vertexArray);
glGenBuffers(1, &vertexIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &model.faces["default"][0], GL_STATIC_DRAW);
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, &model.vertex[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, &model.normal[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &model.texCoord[0]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
}
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
vertexArray = 0;
vertexBuffer = 0;
vertexIndexBuffer = 0;
std::vector<float> textureCoord;
std::vector<unsigned int> indices;
//tex coord must be converted to 2d vecs
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
if (mesh->mTextureCoords[0] != nullptr) {
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
}
else {
textureCoord.push_back(0.0f);
textureCoord.push_back(0.0f);
}
}
if (mesh->mTextureCoords[0] == nullptr) {
std::cout << "no uv coords\n";
}
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
// retrieve all indices of the face and store them in the indices vector
for (unsigned int j = 0; j < face.mNumIndices; j++)
indices.push_back(face.mIndices[j]);
}
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
unsigned int vertexTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexBiTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexElementBufferSize = sizeof(unsigned int) * indices.size();
size = indices.size();
glGenVertexArrays(1, &vertexArray);
glBindVertexArray(vertexArray);
glGenBuffers(1, &vertexIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
//std::cout << vertexBuffer;
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize + vertexBiTangentBufferSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, vertexTangentBufferSize, mesh->mTangents);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize));
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize));
}
void Core::DrawVertexArray(const float * vertexArray, int numVertices, int elementSize )
{
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, numVertices);
}
void Core::DrawVertexArrayIndexed( const float * vertexArray, const int * indexArray, int numIndexes, int elementSize )
{
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
glEnableVertexAttribArray(0);
glDrawElements(GL_TRIANGLES, numIndexes, GL_UNSIGNED_INT, indexArray);
}
void Core::DrawVertexArray( const VertexData & data )
{
int numAttribs = std::min(VertexData::MAX_ATTRIBS, data.NumActiveAttribs);
for(int i = 0; i < numAttribs; i++)
{
glVertexAttribPointer(i, data.Attribs[i].Size, GL_FLOAT, false, 0, data.Attribs[i].Pointer);
glEnableVertexAttribArray(i);
}
glDrawArrays(GL_TRIANGLES, 0, data.NumVertices);
}
void Core::DrawContext(Core::RenderContext& context)
{
glBindVertexArray(context.vertexArray);
glDrawElements(
GL_TRIANGLES, // mode
context.size, // count
GL_UNSIGNED_INT, // type
(void*)0 // element array buffer offset
);
glBindVertexArray(0);
}

72
cw 4/src/Render_Utils.h Executable file
View File

@ -0,0 +1,72 @@
#pragma once
#include "glm.hpp"
#include "glew.h"
#include "objload.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
namespace Core
{
struct RenderContext
{
GLuint vertexArray;
GLuint vertexBuffer;
GLuint vertexIndexBuffer;
int size = 0;
void initFromOBJ(obj::Model& model);
void initFromAssimpMesh(aiMesh* mesh);
};
// vertexArray - jednowymiarowa tablica zawierajaca wartosci opisujace pozycje kolejnych wierzcholkow w jednym ciagu (x1, y1, z1, w1, x2, y2, z2, w2, ...)
// numVertices - liczba wierzcholkow do narysowania
// elementSize - liczba wartosci opisujacych pojedynczy wierzcholek (np. 3 gdy wierzcholek opisany jest trojka (x, y, z))
void DrawVertexArray(const float * vertexArray, int numVertices, int elementSize);
// indexArray - jednowymiarowa tablica zawierajaca indeksy wierzcholkow kolejnych trojkatow w jednym ciagu (t1_i1, t1_i2, t1_i3, t2_i1, t2_i2, t2_i3, ...)
// numIndexes - liczba indeksow w tablicy indexArray
void DrawVertexArrayIndexed(const float * vertexArray, const int * indexArray, int numIndexes, int elementSize);
struct VertexAttribute
{
const void * Pointer;
int Size;
};
struct VertexData
{
static const int MAX_ATTRIBS = 8;
VertexAttribute Attribs[MAX_ATTRIBS];
int NumActiveAttribs;
int NumVertices;
};
// Ta funkcja sluzy do rysowania trojkatow, ktorych wierzcholki moga byc opisane wiecej niz jednym atrybutem.
// Funkcja przyjmuje jako parametr strukture, w ktorej nalezy zawrzec wszystkie potrzebne dane.
//
// Przykladowe wywolanie funkcji - narysowanie trojkata jak na pierwszych zajeciach:
/*
const float vertices[] = {
0.25f, 0.25f, 0.0f, 1.0f,
0.25f, -0.25f, 0.0f, 1.0f,
-0.25f, -0.25f, 0.0f, 1.0f
};
Core::VertexData vertexData;
vertexData.NumActiveAttribs = 1; // Liczba uzywanych atrybutow wierzcholka
vertexData.Attribs[0].Pointer = vertices; // Wskaznik na dane zerowego atrybutu
vertexData.Attribs[0].Size = 4; // Wielkosc zerowego atrybutu (ilosc liczb opisujacych ten atrybut w pojedynczym wierzcholku)
vertexData.NumVertices = 3; // Liczba wierzcholkow do narysowania
Core::DrawVertexArray(vertexData);
*/
void DrawVertexArray(const VertexData & data);
void DrawContext(RenderContext& context);
}

102
cw 4/src/Shader_Loader.cpp Executable file
View File

@ -0,0 +1,102 @@
#include "Shader_Loader.h"
#include<iostream>
#include<fstream>
#include<vector>
using namespace Core;
Shader_Loader::Shader_Loader(void){}
Shader_Loader::~Shader_Loader(void){}
std::string Shader_Loader::ReadShader(char *filename)
{
std::string shaderCode;
std::ifstream file(filename, std::ios::in);
if (!file.good())
{
std::cout << "Can't read file " << filename << std::endl;
std::terminate();
}
file.seekg(0, std::ios::end);
shaderCode.resize((unsigned int)file.tellg());
file.seekg(0, std::ios::beg);
file.read(&shaderCode[0], shaderCode.size());
file.close();
return shaderCode;
}
GLuint Shader_Loader::CreateShader(GLenum shaderType, std::string
source, char* shaderName)
{
int compile_result = 0;
GLuint shader = glCreateShader(shaderType);
const char *shader_code_ptr = source.c_str();
const int shader_code_size = source.size();
glShaderSource(shader, 1, &shader_code_ptr, &shader_code_size);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result);
//sprawdz bledy
if (compile_result == GL_FALSE)
{
int info_log_length = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);
std::vector<char> shader_log(info_log_length);
glGetShaderInfoLog(shader, info_log_length, NULL, &shader_log[0]);
std::cout << "ERROR compiling shader: " << shaderName << std::endl << &shader_log[0] << std::endl;
return 0;
}
return shader;
}
GLuint Shader_Loader::CreateProgram(char* vertexShaderFilename,
char* fragmentShaderFilename)
{
//wczytaj shadery
std::string vertex_shader_code = ReadShader(vertexShaderFilename);
std::string fragment_shader_code = ReadShader(fragmentShaderFilename);
GLuint vertex_shader = CreateShader(GL_VERTEX_SHADER, vertex_shader_code, "vertex shader");
GLuint fragment_shader = CreateShader(GL_FRAGMENT_SHADER, fragment_shader_code, "fragment shader");
int link_result = 0;
//stworz shader
GLuint program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &link_result);
//sprawdz bledy w linkerze
if (link_result == GL_FALSE)
{
int info_log_length = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);
std::vector<char> program_log(info_log_length);
glGetProgramInfoLog(program, info_log_length, NULL, &program_log[0]);
std::cout << "Shader Loader : LINK ERROR" << std::endl << &program_log[0] << std::endl;
return 0;
}
glDetachShader(program, vertex_shader);
glDetachShader(program, fragment_shader);
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
return program;
}
void Shader_Loader::DeleteProgram( GLuint program )
{
glDeleteProgram(program);
}

29
cw 4/src/Shader_Loader.h Executable file
View File

@ -0,0 +1,29 @@
#pragma once
#include "glew.h"
#include "freeglut.h"
#include <iostream>
namespace Core
{
class Shader_Loader
{
private:
std::string ReadShader(char *filename);
GLuint CreateShader(GLenum shaderType,
std::string source,
char* shaderName);
public:
Shader_Loader(void);
~Shader_Loader(void);
GLuint CreateProgram(char* VertexShaderFilename,
char* FragmentShaderFilename);
void DeleteProgram(GLuint program);
};
}

174
cw 4/src/main_3_1.cpp Executable file
View File

@ -0,0 +1,174 @@
#include "glew.h"
#include "freeglut.h"
#include "glm.hpp"
#include "ext.hpp"
#include <iostream>
#include <cmath>
#include "Shader_Loader.h"
#include "Render_Utils.h"
#include "Camera.h"
#include "Box.cpp"
GLuint program;
Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext sphereContext;
float cameraAngle = 0;
glm::vec3 cameraPos = glm::vec3(-5, 0, 0);
glm::vec3 cameraDir;
float screenRatio = 1.0f;
unsigned int VAO;
void keyboard(unsigned char key, int x, int y)
{
float angleSpeed = 0.1f;
float moveSpeed = 0.1f;
switch(key)
{
case 'a': cameraAngle -= angleSpeed; break;
case 'd': cameraAngle += angleSpeed; break;
case 'w': cameraPos += cameraDir * moveSpeed; break;
case 's': cameraPos -= cameraDir * moveSpeed; break;
}
}
glm::mat4 createPerspectiveMatrix()
{
float zNear = 0.1, zFar = 100.0;
float frustumScale = 1.0f;
glm::mat4 perspective;
perspective[0][0] = frustumScale;
perspective[1][1] = frustumScale;
perspective[2][2] = (zFar + zNear) / (zNear - zFar);
perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
perspective[2][3] = -1;
perspective[3][3] = 0;
return perspective;
}
glm::mat4 createCameraMatrix()
{
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
glm::vec3 up = glm::vec3(0,1,0);
return Core::createViewMatrix(cameraPos, cameraDir, up);
}
void drawObject(Core::RenderContext& context, glm::mat4 modelMatrix) {
glm::mat4 camera = createCameraMatrix();
glm::mat4 perspective = createPerspectiveMatrix();
glm::mat4 transformation = perspective * camera * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
//triangle drawcall
Core::DrawContext(context);
}
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
glUseProgram(program);
glm::mat4 camera = createCameraMatrix();
glm::mat4 perspective = createPerspectiveMatrix();
glm::mat4 model = glm::translate(glm::vec3(1.f, 1.f, -1.f)) * glm::eulerAngleX(0.3f);
glm::mat4 transformation = perspective*camera*model;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
//triangle drawcall
Core::DrawContext(shipContext);
model = glm::translate(glm::vec3(1.f, -1.f, -1.f));
transformation = perspective * camera * model;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
Core::DrawContext(sphereContext);
drawObject(sphereContext, glm::translate(glm::vec3(2.f, 1.f, 0.f)));
glUseProgram(0);
glutSwapBuffers();
}
void loadModelToContext(std::string path, Core::RenderContext& context)
{
Assimp::Importer import;
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
{
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
return;
}
context.initFromAssimpMesh(scene->mMeshes[0]);
}
void init()
{
glEnable(GL_DEPTH_TEST);
//program = shaderLoader.CreateProgram("shaders/shader_3_1.vert", "shaders/shader_3_1.frag");
// replace 3_1 shaders with 3_4 shaders for later exercises
program = shaderLoader.CreateProgram("shaders/shader_3_2.vert", "shaders/shader_3_2.frag");
loadModelToContext("models/sphere.obj", sphereContext);
loadModelToContext("models/spaceship.obj", shipContext);
}
void shutdown()
{
shaderLoader.DeleteProgram(program);
}
void idle()
{
glutPostRedisplay();
}
void onReshape(int width, int height)
{
glViewport(0, 0, width, height);
// https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 200);
glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Pierwszy Program");
glewInit();
init();
glutReshapeFunc(onReshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(renderScene);
glutIdleFunc(idle);
glutMainLoop();
shutdown();
return 0;
}

148
cw 4/src/main_4_1.cpp Executable file
View File

@ -0,0 +1,148 @@
#include "glew.h"
#include "freeglut.h"
#include "glm.hpp"
#include "ext.hpp"
#include <iostream>
#include <cmath>
#include "Shader_Loader.h"
#include "Render_Utils.h"
#include "Camera.h"
#include "Box.cpp"
GLuint program;
GLuint programSun;
Core::Shader_Loader shaderLoader;
obj::Model shipModel;
obj::Model sphereModel;
Core::RenderContext shipContext;
Core::RenderContext sphereContext;
float cameraAngle = 0;
glm::vec3 cameraPos = glm::vec3(-6, 0, 0);
glm::vec3 cameraDir;
glm::mat4 cameraMatrix, perspectiveMatrix;
void keyboard(unsigned char key, int x, int y)
{
float angleSpeed = 0.1f;
float moveSpeed = 0.1f;
switch(key)
{
case 'z': cameraAngle -= angleSpeed; break;
case 'x': cameraAngle += angleSpeed; break;
case 'w': cameraPos += cameraDir * moveSpeed; break;
case 's': cameraPos -= cameraDir * moveSpeed; break;
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
case 'a': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
case 'e': cameraPos += glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
case 'q': cameraPos -= glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
}
}
glm::mat4 createCameraMatrix()
{
// Obliczanie kierunku patrzenia kamery (w plaszczyznie x-z) przy uzyciu zmiennej cameraAngle kontrolowanej przez klawisze.
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
glm::vec3 up = glm::vec3(0,1,0);
return Core::createViewMatrix(cameraPos, cameraDir, up);
}
void drawObject(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
{
glUseProgram(program);
glUniform3f(glGetUniformLocation(program, "objectColor"), color.x, color.y, color.z);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
Core::DrawContext(context);
glUseProgram(0);
}
void renderScene()
{
// Aktualizacja macierzy widoku i rzutowania. Macierze sa przechowywane w zmiennych globalnych, bo uzywa ich funkcja drawObject.
// (Bardziej elegancko byloby przekazac je jako argumenty do funkcji, ale robimy tak dla uproszczenia kodu.
// Jest to mozliwe dzieki temu, ze macierze widoku i rzutowania sa takie same dla wszystkich obiektow!)
cameraMatrix = createCameraMatrix();
perspectiveMatrix = Core::createPerspectiveMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
glUseProgram(program);
// Macierz statku "przyczepia" go do kamery. Warto przeanalizowac te linijke i zrozumiec jak to dziala.
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
glUniform3f(glGetUniformLocation(program, "lightDir"), 0.5, 0.5, 3);
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos[0], cameraPos[1], cameraPos[2]);
drawObject(shipContext, shipModelMatrix, glm::vec3(0.6f));
drawObject(sphereContext, glm::translate(glm::vec3(2, 0, 2)), glm::vec3(1.0f, 0.5f, 0.2f));
drawObject(sphereContext, glm::translate(glm::vec3(-2, 0, -2)), glm::vec3(0.0f, 0.6f, 0.9f));
glutSwapBuffers();
}
void loadModelToContext(std::string path, Core::RenderContext& context)
{
Assimp::Importer import;
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
{
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
return;
}
context.initFromAssimpMesh(scene->mMeshes[0]);
}
void init()
{
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_4_1.vert", "shaders/shader_4_1.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_4_sun.vert", "shaders/shader_4_sun.frag");
loadModelToContext("models/spaceship.obj", shipContext);
loadModelToContext("models/sphere.obj", sphereContext);
}
void shutdown()
{
shaderLoader.DeleteProgram(program);
}
void idle()
{
glutPostRedisplay();
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 300);
glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Pierwszy Program");
glewInit();
init();
glutKeyboardFunc(keyboard);
glutDisplayFunc(renderScene);
glutIdleFunc(idle);
glutMainLoop();
shutdown();
return 0;
}

291
cw 4/src/objload.h Executable file
View File

@ -0,0 +1,291 @@
/* Copyright (c) 2012, Gerhard Reitmayr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#ifndef OBJLOAD_H_
#define OBJLOAD_H_
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <vector>
namespace obj {
struct Model {
std::vector<float> vertex; //< 3 * N entries
std::vector<float> texCoord; //< 2 * N entries
std::vector<float> normal; //< 3 * N entries
std::map<std::string, std::vector<unsigned short> > faces; //< assume triangels and uniform indexing
};
struct ObjModel {
struct FaceVertex {
FaceVertex() : v(-1), t(-1), n(-1) {}
int v, t, n;
bool operator<( const FaceVertex & other ) const;
bool operator==( const FaceVertex & other ) const;
};
typedef std::pair<std::vector<FaceVertex>, std::vector<unsigned> > FaceList;
std::vector<float> vertex; //< 3 * N entries
std::vector<float> texCoord; //< 2 * N entries
std::vector<float> normal; //< 3 * N entries
std::map<std::string, FaceList > faces;
};
inline ObjModel parseObjModel( std::istream & in);
inline void tesselateObjModel( ObjModel & obj);
inline ObjModel tesselateObjModel( const ObjModel & obj );
inline Model convertToModel( const ObjModel & obj );
inline Model loadModel( std::istream & in );
inline Model loadModelFromString( const std::string & in );
inline Model loadModelFromFile( const std::string & in );
inline std::ostream & operator<<( std::ostream & out, const Model & m );
inline std::ostream & operator<<( std::ostream & out, const ObjModel::FaceVertex & f);
// ---------------------------- Implementation starts here -----------------------
inline bool ObjModel::FaceVertex::operator<( const ObjModel::FaceVertex & other ) const {
return (v < other.v) || (v == other.v && t < other.t ) || (v == other.v && t == other.t && n < other.n);
}
inline bool ObjModel::FaceVertex::operator==( const ObjModel::FaceVertex & other ) const {
return (v == other.v && t == other.t && n == other.n);
}
template <typename T>
inline std::istream & operator>>(std::istream & in, std::vector<T> & vec ){
T temp;
if(in >> temp)
vec.push_back(temp);
return in;
}
template <typename T>
inline std::istream & operator>>(std::istream & in, std::set<T> & vec ){
T temp;
if(in >> temp)
vec.insert(temp);
return in;
}
inline std::istream & operator>>( std::istream & in, ObjModel::FaceVertex & f){
if(in >> f.v){
if(in.peek() == '/'){
in.get();
in >> f.t;
in.clear();
if(in.peek() == '/'){
in.get();
in >> f.n;
in.clear();
}
}
in.clear();
--f.v;
--f.t;
--f.n;
}
// std::cout << f << std::endl;
return in;
}
ObjModel parseObjModel( std::istream & in ){
char line[1024];
std::string op;
std::istringstream line_in;
std::set<std::string> groups;
groups.insert("default");
ObjModel data;
while(in.good()){
in.getline(line, 1023);
line_in.clear();
line_in.str(line);
if(!(line_in >> op))
continue;
if(op == "v")
line_in >> data.vertex >> data.vertex >> data.vertex;
else if(op == "vt")
line_in >> data.texCoord >> data.texCoord >> data.texCoord;
else if(op == "vn")
line_in >> data.normal >> data.normal >> data.normal;
else if(op == "g"){
groups.clear();
while(line_in >> groups) ;
groups.insert("default");
}
else if(op == "f") {
std::vector<ObjModel::FaceVertex> list;
while(line_in >> list) ;
for(std::set<std::string>::const_iterator g = groups.begin(); g != groups.end(); ++g){
ObjModel::FaceList & fl = data.faces[*g];
fl.second.push_back(fl.first.size());
fl.first.insert(fl.first.end(), list.begin(), list.end());
}
}
}
for(std::map<std::string, ObjModel::FaceList>::iterator g = data.faces.begin(); g != data.faces.end(); ++g){
ObjModel::FaceList & fl = g->second;
fl.second.push_back(fl.first.size());
}
return data;
}
inline void tesselateObjModel( std::vector<ObjModel::FaceVertex> & input, std::vector<unsigned> & input_start){
std::vector<ObjModel::FaceVertex> output;
std::vector<unsigned> output_start;
output.reserve(input.size());
output_start.reserve(input_start.size());
for(std::vector<unsigned>::const_iterator s = input_start.begin(); s != input_start.end() - 1; ++s){
const unsigned size = *(s+1) - *s;
if(size > 3){
const ObjModel::FaceVertex & start_vertex = input[*s];
for( int i = 1; i < (int)size-1; ++i){
output_start.push_back(output.size());
output.push_back(start_vertex);
output.push_back(input[*s+i]);
output.push_back(input[*s+i+1]);
}
} else {
output_start.push_back(output.size());
output.insert(output.end(), input.begin() + *s, input.begin() + *(s+1));
}
}
output_start.push_back(output.size());
input.swap(output);
input_start.swap(output_start);
}
void tesselateObjModel( ObjModel & obj){
for(std::map<std::string, ObjModel::FaceList>::iterator g = obj.faces.begin(); g != obj.faces.end(); ++g){
ObjModel::FaceList & fl = g->second;
tesselateObjModel(fl.first, fl.second);
}
}
Model convertToModel( const ObjModel & obj ) {
// insert all face vertices into a vector and make unique
std::vector<ObjModel::FaceVertex> unique(obj.faces.find("default")->second.first);
std::sort(unique.begin(), unique.end());
unique.erase( std::unique(unique.begin(), unique.end()), unique.end());
// build a new model with repeated vertices/texcoords/normals to have single indexing
Model model;
for(std::vector<ObjModel::FaceVertex>::const_iterator f = unique.begin(); f != unique.end(); ++f){
model.vertex.insert(model.vertex.end(), obj.vertex.begin() + 3*f->v, obj.vertex.begin() + 3*f->v + 3);
if(!obj.texCoord.empty()){
const int index = (f->t > -1) ? f->t : f->v;
model.texCoord.insert(model.texCoord.end(), obj.texCoord.begin() + 2*index, obj.texCoord.begin() + 2*index + 2);
}
if(!obj.normal.empty()){
const int index = (f->n > -1) ? f->n : f->v;
model.normal.insert(model.normal.end(), obj.normal.begin() + 3*index, obj.normal.begin() + 3*index + 3);
}
}
// look up unique index and transform face descriptions
for(std::map<std::string, ObjModel::FaceList>::const_iterator g = obj.faces.begin(); g != obj.faces.end(); ++g){
const std::string & name = g->first;
const ObjModel::FaceList & fl = g->second;
std::vector<unsigned short> & v = model.faces[g->first];
v.reserve(fl.first.size());
for(std::vector<ObjModel::FaceVertex>::const_iterator f = fl.first.begin(); f != fl.first.end(); ++f){
const unsigned short index = std::distance(unique.begin(), std::lower_bound(unique.begin(), unique.end(), *f));
v.push_back(index);
}
}
return model;
}
ObjModel tesselateObjModel( const ObjModel & obj ){
ObjModel result = obj;
tesselateObjModel(result);
return result;
}
Model loadModel( std::istream & in ){
ObjModel model = parseObjModel(in);
tesselateObjModel(model);
return convertToModel(model);
}
Model loadModelFromString( const std::string & str ){
std::istringstream in(str);
return loadModel(in);
}
Model loadModelFromFile( const std::string & str) {
std::ifstream in(str.c_str());
return loadModel(in);
}
inline std::ostream & operator<<( std::ostream & out, const ObjModel::FaceVertex & f){
out << f.v << "\t" << f.t << "\t" << f.n;
return out;
}
std::ostream & operator<<( std::ostream & out, const Model & m ){
if(!m.vertex.empty()){
out << "vertex\n";
for(int i = 0; i < (int)m.vertex.size(); ++i)
out << m.vertex[i] << (((i % 3) == 2)?"\n":"\t");
}
if(!m.texCoord.empty()){
out << "texCoord\n";
for(int i = 0; i < (int)m.texCoord.size(); ++i)
out << m.texCoord[i] << (((i % 2) == 1)?"\n":"\t");
}
if(!m.normal.empty()){
out << "normal\n";
for(int i = 0; i < (int)m.normal.size(); ++i)
out << m.normal[i] << (((i % 3) == 2)?"\n":"\t");
}
if(!m.faces.empty()){
out << "faces\t";
for(std::map<std::string, std::vector<unsigned short> >::const_iterator g = m.faces.begin(); g != m.faces.end(); ++g){
out << g->first << " ";
}
out << "\n";
// for(int i = 0; i < m.face.size(); ++i)
// out << m.face[i] << (((i % 3) == 2)?"\n":"\t");
}
return out;
}
} // namespace obj
#endif // OBJLOAD_H_

107
cw 4/style.css Executable file
View File

@ -0,0 +1,107 @@
html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
body{
color:#444;
font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
font-size:12px;
line-height:1.5em;
padding:1em;
margin:auto;
max-width:42em;
background:#fefefe;
}
a{ color: #0645ad; text-decoration:none;}
a:visited{ color: #0b0080; }
a:hover{ color: #06e; }
a:active{ color:#faa700; }
a:focus{ outline: thin dotted; }
a:hover, a:active{ outline: 0; }
::-moz-selection{background:rgba(255,255,0,0.3);color:#000}
::selection{background:rgba(255,255,0,0.3);color:#000}
a::-moz-selection{background:rgba(255,255,0,0.3);color:#0645ad}
a::selection{background:rgba(255,255,0,0.3);color:#0645ad}
p{
margin:1em 0;
}
img{
max-width:100%;
}
h1,h2,h3,h4,h5,h6{
font-weight:normal;
color:#111;
line-height:1em;
}
h4,h5,h6{ font-weight: bold; }
h1{ font-size:2.5em; }
h2{ font-size:2em; }
h3{ font-size:1.5em; }
h4{ font-size:1.2em; }
h5{ font-size:1em; }
h6{ font-size:0.9em; }
blockquote{
color:#666666;
margin:0;
padding-left: 3em;
border-left: 0.5em #EEE solid;
}
hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
pre, code, kbd, samp { color: #000; font-family: monospace, monospace; _font-family: 'courier new', monospace; font-size: 0.98em; }
pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
b, strong { font-weight: bold; }
dfn { font-style: italic; }
ins { background: #ff9; color: #000; text-decoration: none; }
mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
sup { top: -0.5em; }
sub { bottom: -0.25em; }
ul, ol { margin: 1em 0; padding: 0 0 0 2em; }
li p:last-child { margin:0 }
dd { margin: 0 0 0 2em; }
img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; }
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
th { border-bottom: 1px solid black; }
td { vertical-align: top; }
@media only screen and (min-width: 480px) {
body{font-size:14px;}
}
@media only screen and (min-width: 768px) {
body{font-size:16px;}
}
@media print {
* { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
body{font-size:12pt; max-width:100%;}
a, a:visited { text-decoration: underline; }
hr { height: 1px; border:0; border-bottom:1px solid black; }
a[href]:after { content: " (" attr(href) ")"; }
abbr[title]:after { content: " (" attr(title) ")"; }
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
tr, img { page-break-inside: avoid; }
img { max-width: 100% !important; }
@page :left { margin: 15mm 20mm 15mm 10mm; }
@page :right { margin: 15mm 10mm 15mm 20mm; }
p, h2, h3 { orphans: 3; widows: 3; }
h2, h3 { page-break-after: avoid; }
}

BIN
cw 4/sun.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

100
cw 4/zadania 4.html Executable file
View File

@ -0,0 +1,100 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>zadania 4</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="style.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h2 id="i-oświetlenie-phonga">I Oświetlenie Phonga</h2>
<h3 id="i.0.-jeżeli-nie-zrobiłeś-poprzednich-zadań-związanych-z-shaderami">I.0. (Jeżeli nie zrobiłeś poprzednich zadań związanych z shaderami)</h3>
<p>Obejrzyj pliki <strong>shader_4_1.vert</strong> i <strong>shader_4_1.frag</strong>. Zwróć uwagę w szczególności na zmienną <code>interpNormal</code>, przy uzyciu ktorej wektory normalne są przesyłane z <strong>vertex shaderze</strong> do <strong>fragment shadera</strong>. Pliki shader_4_2.vert i shader_4_2.frag na razie nie będą wykorzystywane</p>
<h3 id="i.1.-oblicz-we-fragment-shaderze-oświetlenie-obiektu-przy-użyciu-modelu-phonga-dla-światła-rozproszonego-diffuse">I.1. Oblicz we fragment shaderze oświetlenie obiektu przy użyciu modelu Phonga dla światła rozproszonego (<code>diffuse</code>):</h3>
<ol type="a">
<li>Przekaż źródło światła. Na razie przyjmiemy kierunkowy model oświetlenia, dlatego źródło będzie opisane jako wektor kierunkowy:</li>
</ol>
<ul>
<li><p>Prześlij do fragment shadera zmienna typu <code>uniform vec3</code> (nazwij ją np. <code>lightDir</code>), w której będzie się znajdować wektor kierunkowy:</p></li>
<li><p>Należy to zrobić podobnie do tego, jak przesyłana jest zmienna <code>objectColor</code>. Jedyna różnica będzie taka, ze kierunek padania światła nie zależy od obiektu, wiec wywołanie <code>glUniform3f</code> powinno pojawić się tylko raz, przed rysowaniem wszystkich obiektów.Wywołaj <code>glUseProgram(program)</code> przed przesłaniem zmiennej.</p></li>
<li><p>Jako kierunek światła wybierz dowolny wektor jednostkowy. (Możesz wziąć dowolny niezerowy wektor następnie go znormalizować)</p></li>
</ul>
<ol start="2" type="a">
<li>Oblicz natężenie w shaderze fragmentów:</li>
</ol>
<ul>
<li><p>znormalizuj wektor normalny przed użyciem go w obliczeniach (uśrednianie wektorów normalnych wierzchołków może spowodować, ze przestaje one być jednostkowe).</p></li>
<li><p>Natężenie to iloczyn skalarny wektora normalnego powierzchni i odwrotnego wektora kierunku padania światła. Skorzystaj z funkcji <code>dot</code>.</p></li>
<li><p>Natężenie nie może być ujemne. Przytnij natężenie do zera przy użyciu: <code>x = max(x, 0.0)</code></p></li>
</ul>
<ol start="3" type="a">
<li>Zastosuj obliczone natężenie aby zmodyfikować kolor obiektu:</li>
</ol>
<ul>
<li>Przemnóż kolor RGB fragmentu przez obliczone natężenie.</li>
</ul>
<h3 id="i.2.-dlaczego-oświetlenie-statku-nie-zmienia-się-podczas-jego-obracania">I.2. Dlaczego oświetlenie statku nie zmienia się podczas jego obracania?</h3>
<p>(Wektory normalne są w układzie lokalnym modelu, a wektor padania światła w układzie świata)</p>
<p>Należy wykonać transformacje wektorów normalnych do przestrzeni świata:</p>
<ul>
<li><p>Prześlij macierz modelu rysowanego obiektu (<em>model Matrix</em>) jako osobna zmienna do vertex shadera (<code>uniform mat4</code>).</p></li>
<li><p>Przemnóż przez te macierz wektor normalny wierzchołka przed przeslaniem go do fragment shadera.</p></li>
<li><p>Współrzędna <strong>w</strong> dopisana do wektora przed mnożeniem przez macierz powinna być ustawiona na 0. Wynika to z tego, ze w przypadku transformacji wektorów reprezentujących kierunki w przestrzeni, nie chcemy dokonywać translacji - np. wektor normalny do powierzchni zależy od orientacji obiektu, ale nie od jego pozycji (przesunięcia) w przestrzeni świata.</p></li>
</ul>
<h3 id="i.3.-uzupełnił-model-o-czynnik-światła-odbitego-specular.-w-tym-celu">I.3. Uzupełnił model o czynnik światła odbitego (<code>specular</code>). W tym celu:</h3>
<ol type="a">
<li>Potrzebny będzie wektor od rysowanego fragmentu do pozycji kamery:</li>
</ol>
<ul>
<li><p>Wyślij pozycje kamery (<code>cameraPos</code>) jako kolejna zmienna do fragment shadera.</p></li>
<li><p>Podobnie jak wektory normalne prześlij z vertex do fragment shadera pozycje wierzchołków (<code>vertexPosition</code>) w przestrzeni świata (czyli pomnożone przez macierz <strong>modelMatrix</strong>). Pamiętaj, ze tym razem wektory reprezentują punkty, a nie kierunki - współrzędna <strong>w</strong> przed mnożeniem musi być ustawiona na 1. W wyniku rasteryzacji otrzymamy w shaderze fragmentu jego pozycję (nazywaną pozycją fragmentu)</p></li>
<li><p>Oblicz wektor <strong>V</strong> (<em>view direction</em>) jako znormalizowaną różnice pozycji kamery i pozycji fragmentu.</p></li>
</ul>
<ol start="2" type="a">
<li>Oblicz natężenie światła odbitego we <em>fragment shaderze</em>:</li>
</ol>
<ul>
<li><p>Oblicz wektor kierunku odbicia światła <strong>R</strong> przy użyciu funkcji <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/reflect.xhtml"><code>reflect</code></a>. Pamiętaj, żeby przesłać do funkcji odwrócony wektor kierunku światła.</p></li>
<li><p>Oblicz natężenie: iloczyn skalarny <strong>V</strong> i <strong>R</strong>, przycięty do zera ( <code>max(...,0.0)</code> ), a następnie podniesiony do wysokiej potęgi (np. 8, 50, 1000), która jest miara połyskliwości powierzchni</p></li>
</ul>
<ol start="3" type="a">
<li>Ustal ostateczny kolor piksela na <code>objectColor * diffuse + vec3(1.0) * specular</code>. Oznacza to najprostszy przypadek, gdy kolor światła odbitego jest biały.</li>
</ol>
<h3 id="i.4.-stwórz-układ-planetarny---jedna-nieruchoma-kule-na-środku-słonce-i-kilka-orbitujących-wokół-niej-planet.">I.4. Stwórz układ planetarny - jedna nieruchoma kule na środku (Słonce) i kilka orbitujących wokół niej planet.</h3>
<p>Niech przynajmniej jedna planeta ma księżyce.</p>
<h3 id="i.5.-w-układzie-planetarnym-obiektem-oświetlającym-powinno-być-słońce-dlatego-zamień-oświetlenie-kierunkowe-na-punktowe">I.5. W układzie planetarnym obiektem oświetlającym powinno być słońce, dlatego zamień oświetlenie kierunkowe na punktowe:</h3>
<ul>
<li><p>Zamiast przesyłać (w <code>lightDir</code>) kierunek światła, prześlij pozycję słońca do fragment shadera (taką jak ustawiłeś w punkcie powyżej) jako uniform vec3 (nazwij go <code>lightPos</code>).</p></li>
<li><p>Oblicz kierunek światła odejmując od pozycji fragmentu pozycję światła, znormalizuj wynik. Zapisz wynik w zmiennej <code>lightDir</code>.</p></li>
<li><p>Słońce będzie czarne, nie martw się tym, tylko spójrz na punkt następny</p></li>
</ul>
<h3 id="i.6.-źródło-światła-znajduje-się-wewnątrz-kuli-która-reprezentuje-słońce-dlatego-jest-czarna.-by-to-naprawić-utwórz-osobny-shader-który-będzie-odpowiadać-za-renderowanie-słońca.">I.6. Źródło światła znajduje się wewnątrz kuli, która reprezentuje słońce, dlatego jest czarna. By to naprawić utwórz osobny shader, który będzie odpowiadać za renderowanie słońca.</h3>
<p>Celem tego zadania jest stworzenie shadera (<strong>shader_4_sun.vert</strong>_ i <strong>shader_4_sun.frag</strong>), który będzie odpowiadał wyłącznie za rysowanie słońca. Poprzednie shadery (<strong>shader_4_1.vert</strong>_ i <strong>shader_4_1.frag</strong>) nadal mają rysować pozostałe obiekty. a) zainicjalizuj <em>program</em> (shadery): - Pliki <strong>shader_4_sun.vert</strong> i <strong>shader_4_sun.frag</strong> są identyczne jak <strong>4_1</strong> przed zmianami, będą punktem wyjścia dla <em>shadera</em> słońca.</p>
<ul>
<li>Utwórz zmienną globalną <code>GLuint programSun</code> na adres shadera słońca. Stwórz <em>program</em> za pomocą <code>shaderLoader.CreateProgram</code> analogicznie jak tworzy się <code>program</code> z <strong>shader_4_1.vert</strong> i <strong>shader_4_1.frag</strong> (parametry wejściowe to ścieżka do shadera wierzchołków i fragmentów <strong>shader_4_sun.vert</strong> i <strong>shader_4_sun.frag</strong>).</li>
</ul>
<ol start="2" type="a">
<li>W skomplikowanym projekcie różne typy obiektów rysuje się przy użyciu różnych shaderów, zate potrzebna jest w programie architektura, która na to pozwala. Ustaw odpowiedni <em>program</em> (shadery) do rysowania słońca:</li>
</ol>
<ul>
<li>funkcja <code>drawObject</code> korzysta z globalnej zmiennej <code>program</code>, żeby wskazywać shadery do rysowania. Dodaj argument do funkcji, który będziesz przekazywać adres <em>programu</em>, który ma być wykorzystany do rysowania.</li>
<li>dodaj odpowiedni <em>program</em> w wywołaniach <code>drawObject</code></li>
</ul>
<h3 id="i.7.-zmień-shader-słońca-na-bardziej-realistyczny.">I.7.* Zmień shader słońca na bardziej realistyczny.</h3>
<p>Na poniższym obrazku jest zdjęcie słońca. jest ono ciemniejsze na brzegach spróbuj uzyskać podobny efekt. Przydadzą się wektory z poprzednich punktów, jak wektor normalny i wektor <strong>V</strong>.</p>
<p><img src="https://wi-images.condecdn.net/image/DEGypMQdE59/crop/1020/f/sunmeta.jpg" /></p>
</body>
</html>

127
cw 5/grk-cw5.vcxproj Executable file
View File

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main_5_1.cpp" />
<ClCompile Include="src\Render_Utils.cpp" />
<ClCompile Include="src\Shader_Loader.cpp" />
<ClCompile Include="src\SOIL\image_DXT.c" />
<ClCompile Include="src\SOIL\image_helper.c" />
<ClCompile Include="src\SOIL\SOIL.c" />
<ClCompile Include="src\SOIL\stb_image_aug.c" />
<ClCompile Include="src\Texture.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Camera.h" />
<ClInclude Include="src\objload.h" />
<ClInclude Include="src\Render_Utils.h" />
<ClInclude Include="src\Shader_Loader.h" />
<ClInclude Include="src\SOIL\image_DXT.h" />
<ClInclude Include="src\SOIL\image_helper.h" />
<ClInclude Include="src\SOIL\SOIL.h" />
<ClInclude Include="src\SOIL\stbi_DDS_aug.h" />
<ClInclude Include="src\SOIL\stbi_DDS_aug_c.h" />
<ClInclude Include="src\SOIL\stb_image_aug.h" />
<ClInclude Include="src\Texture.h" />
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_4_1.frag" />
<None Include="shaders\shader_4_1.vert" />
<None Include="shaders\shader_4_sun.frag" />
<None Include="shaders\shader_4_sun.vert" />
<None Include="shaders\shader_4_tex.frag" />
<None Include="shaders\shader_4_tex.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{3A5EA2E9-4B50-4E36-B2AA-7DC086FCD066}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>grk-cw5</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>grk-cw5</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\assimp\Release;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\debug\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlibd.lib;assimp-vc141-mtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\physx-4.1\include;$(SolutionDir)dependencies\physx-4.1\source\common\include;$(SolutionDir)dependencies\physx-4.1\source\common\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src;$(SolutionDir)dependencies\physx-4.1\source\physx\src\device;$(SolutionDir)dependencies\physx-4.1\source\physx\src\buffering;$(SolutionDir)dependencies\physx-4.1\source\physxgpu\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\include;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\contact;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\common;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\convex;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\distance;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\sweep;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\gjk;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\intersection;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\hf;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\pcm;$(SolutionDir)dependencies\physx-4.1\source\geomutils\src\ccd;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\api\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\software\include;$(SolutionDir)dependencies\physx-4.1\source\lowlevel\common\include\pipeline;$(SolutionDir)dependencies\physx-4.1\source\lowlevelaabb\include;$(SolutionDir)dependencies\physx-4.1\source\lowleveldynamics\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\include;$(SolutionDir)dependencies\physx-4.1\source\simulationcontroller\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\mesh;$(SolutionDir)dependencies\physx-4.1\source\physxcooking\src\convex;$(SolutionDir)dependencies\physx-4.1\source\scenequery\include;$(SolutionDir)dependencies\physx-4.1\source\physxmetadata\core\include;$(SolutionDir)dependencies\physx-4.1\source\immediatemode\include;$(SolutionDir)dependencies\physx-4.1\source\pvd\include;$(SolutionDir)dependencies\physx-4.1\source\foundation\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXExtensions_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysX_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXPvdSDK_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXVehicle_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCharacterKinematic_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCooking_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXCommon_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetUtils_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\SnippetRender_static_32.lib;$(SolutionDir)dependencies\physx-4.1\lib\win.x86_32.vc141.mt\release\PhysXFoundation_32.lib;opengl32.lib;freeglut.lib;glew32.lib;zlib.lib;assimp-vc141-mt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

110
cw 5/grk-cw5.vcxproj.filters Executable file
View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Shader Files">
<UniqueIdentifier>{0a247bb8-2e8e-4a90-b0ef-17415b0941ba}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\SOIL">
<UniqueIdentifier>{1e762b0e-a07f-4d7a-aedf-9503776529c7}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Render_Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Shader_Loader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Box.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\main_5_1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\image_helper.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\SOIL.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\stb_image_aug.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\image_DXT.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="src\Texture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\objload.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Render_Utils.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Shader_Loader.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Camera.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\image_DXT.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\image_helper.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\SOIL.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\stb_image_aug.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\stbi_DDS_aug.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\stbi_DDS_aug_c.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\Texture.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_4_sun.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_sun.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_1.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_1.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_tex.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_4_tex.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

4
cw 5/grk-cw5.vcxproj.user Executable file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

464
cw 5/models/spaceship.obj Executable file
View File

@ -0,0 +1,464 @@
# Exported from Wings 3D 1.0.1
#48 vertices, 92 faces
v -0.46604296 -4.6098739e-2 6.1004010e-2
v -0.46604296 4.5631895e-2 6.1004010e-2
v -0.28477197 -9.3266190e-2 -0.41163609
v -0.28477197 4.5631895e-2 -0.41163609
v -5.3436673e-2 -4.9075029e-2 0.72044817
v -5.3436673e-2 -0.10214269 0.72044817
v 0.0000000e+0 -4.9075029e-2 0.74414179
v 0.0000000e+0 -0.11873436 0.74414179
v 0.0000000e+0 0.11653721 -0.35075536
v 0.0000000e+0 -0.16403757 -0.35075536
v 0.0000000e+0 0.16403757 6.1004010e-2
v 0.0000000e+0 -0.16403757 6.1004010e-2
v -0.64756828 -3.8727536e-2 -0.23804752
v -0.64756828 7.1441743e-2 -0.23804752
v -0.49663244 7.1441743e-2 -0.74414179
v -0.49663244 -3.8727536e-2 -0.74414179
v -4.0833684e-2 -0.10214269 0.73456352
v -4.0833684e-2 -4.9075029e-2 0.73456352
v -0.16961230 0.11653721 -0.38119573
v -0.16961230 -0.14744589 -0.38119573
v -0.16961230 0.16403757 6.1004010e-2
v -0.16961230 -0.14744589 6.1004010e-2
v -9.1308654e-2 4.5778787e-2 0.47242135
v -9.1308654e-2 -0.10009243 0.47242135
v 0.0000000e+0 4.5778787e-2 0.47242135
v 0.0000000e+0 -0.11668411 0.47242135
v -0.18261731 -6.9341139e-2 0.47242135
v -0.18261731 -1.7215671e-3 0.47242135
v 0.46604296 -4.6098739e-2 6.1004010e-2
v 0.46604296 4.5631895e-2 6.1004010e-2
v 0.28477197 -9.3266190e-2 -0.41163609
v 0.28477197 4.5631895e-2 -0.41163609
v 5.3436673e-2 -4.9075029e-2 0.72044817
v 5.3436673e-2 -0.10214269 0.72044817
v 0.64756828 -3.8727536e-2 -0.23804752
v 0.64756828 7.1441743e-2 -0.23804752
v 0.49663244 7.1441743e-2 -0.74414179
v 0.49663244 -3.8727536e-2 -0.74414179
v 4.0833684e-2 -0.10214269 0.73456352
v 4.0833684e-2 -4.9075029e-2 0.73456352
v 0.16961230 0.11653721 -0.38119573
v 0.16961230 -0.14744589 -0.38119573
v 0.16961230 0.16403757 6.1004010e-2
v 0.16961230 -0.14744589 6.1004010e-2
v 9.1308654e-2 4.5778787e-2 0.47242135
v 9.1308654e-2 -0.10009243 0.47242135
v 0.18261731 -6.9341139e-2 0.47242135
v 0.18261731 -1.7215671e-3 0.47242135
vt 0.0000000e+0 0.69053970
vt 4.2285593e-2 0.71525416
vt 0.11847455 0.48783383
vt 0.16076015 0.51254829
vt 0.16331352 0.33807909
vt 0.17536475 0.59545214
vt 0.18715376 0.64617830
vt 0.21512694 0.12420912
vt 0.23028866 0.37309998
vt 0.27933871 3.3287708e-2
vt 0.29111566 1.8231410e-2
vt 0.29780728 0.0000000e+0
vt 0.30306274 0.16395866
vt 0.32256180 5.8152293e-2
vt 0.33503069 5.1982011e-2
vt 0.34659842 0.15855392
vt 0.34866807 4.3914835e-2
vt 0.35966131 0.56514644
vt 0.36786859 0.34315696
vt 0.38304782 0.66577476
vt 0.38362189 0.14708561
vt 0.40944282 0.52981351
vt 0.43912922 0.32433135
vt 0.44897715 0.70072227
vt 0.48119448 0.50585981
vt 0.52771590 0.47388085
vt 0.52771590 0.68855148
vt 0.53171542 0.29271280
vt 0.54359004 0.11090107
vt 0.54696463 8.9466723e-4
vt 0.56615771 0.0000000e+0
vt 0.58393029 6.3125387e-4
vt 0.58452235 0.11195282
vt 0.60240334 0.48892951
vt 0.60614015 0.29553098
vt 0.62473227 0.11194349
vt 0.66991430 0.50491521
vt 0.75162596 0.29695078
vt 0.77873865 0.65209135
vt 0.84024960 0.13148316
vt 0.84024960 0.42828199
vt 0.90677601 0.35344281
vt 0.92024753 0.0000000e+0
vt 1.00000000 0.20728785
vn -0.85484036 0.0000000e+0 0.51889108
vn -0.25024660 -0.96818192 6.4366946e-4
vn -0.41030048 -0.90951551 -6.6596220e-2
vn -0.82350309 0.0000000e+0 0.56731178
vn -0.31890558 -0.93276809 0.16805628
vn -0.31484356 -0.93485312 0.16408281
vn -2.7217819e-2 -0.99959657 -8.1173501e-3
vn -0.32350669 -0.94622588 0.0000000e+0
vn -0.82350309 0.0000000e+0 0.56731178
vn -0.85484036 0.0000000e+0 0.51889108
vn -0.85484036 0.0000000e+0 0.51889108
vn 8.6753709e-2 0.99567401 3.3272527e-2
vn -0.36724289 0.91939897 -0.14084814
vn -0.34874278 0.87308361 0.34073961
vn -0.82350309 0.0000000e+0 0.56731178
vn 0.84335584 0.0000000e+0 -0.53735549
vn -0.25024660 -0.96818192 6.4366946e-4
vn -0.41030048 -0.90951551 -6.6596220e-2
vn 0.25555460 0.0000000e+0 -0.96679462
vn 8.6753709e-2 0.99567401 3.3272527e-2
vn 0.84335584 0.0000000e+0 -0.53735549
vn 0.25555460 0.0000000e+0 -0.96679462
vn -0.36724289 0.91939897 -0.14084814
vn 0.84335584 0.0000000e+0 -0.53735549
vn 0.25555460 0.0000000e+0 -0.96679462
vn -0.50427448 0.85860405 -9.2229808e-2
vn 8.2673579e-2 0.99627162 2.4656288e-2
vn -0.88691408 0.0000000e+0 0.46193442
vn -0.74593766 0.0000000e+0 0.66601577
vn -0.42279812 0.82385482 0.37749832
vn -0.88691408 0.0000000e+0 0.46193442
vn -0.74593766 0.0000000e+0 0.66601577
vn 1.1166894e-2 -0.99988794 -9.9704414e-3
vn -0.88691408 0.0000000e+0 0.46193442
vn -0.31890277 -0.94690597 4.0866878e-2
vn -0.74593766 0.0000000e+0 0.66601577
vn -0.22836934 0.0000000e+0 0.97357457
vn -7.7079267e-2 0.94131828 0.32860109
vn 0.22836934 0.0000000e+0 0.97357457
vn 7.7079267e-2 0.94131828 0.32860109
vn -0.22836934 0.0000000e+0 0.97357457
vn -0.38916924 -0.91867155 6.7748717e-2
vn -0.22836934 0.0000000e+0 0.97357457
vn -0.17877724 -0.98386157 -7.4236827e-3
vn 0.22836934 0.0000000e+0 0.97357457
vn 0.38916924 -0.91867155 6.7748717e-2
vn 0.22836934 0.0000000e+0 0.97357457
vn 0.17877724 -0.98386157 -7.4236827e-3
vn 0.17664795 0.0000000e+0 -0.98427410
vn 0.0000000e+0 0.99341178 -0.11459949
vn 0.17664795 0.0000000e+0 -0.98427410
vn 1.9164607e-2 0.99409750 -0.10678429
vn -0.17664795 0.0000000e+0 -0.98427410
vn 0.0000000e+0 0.99341178 -0.11459949
vn -0.17664795 0.0000000e+0 -0.98427410
vn -1.9164607e-2 0.99409750 -0.10678429
vn -9.7356475e-2 -0.99524958 0.0000000e+0
vn 0.17664795 0.0000000e+0 -0.98427410
vn 9.7356475e-2 -0.99524958 0.0000000e+0
vn -0.17664795 0.0000000e+0 -0.98427410
vn 0.0000000e+0 0.99341178 -0.11459949
vn 0.0000000e+0 0.96108401 0.27625628
vn 0.0000000e+0 0.99341178 -0.11459949
vn 0.0000000e+0 0.96108401 0.27625628
vn -9.7356475e-2 -0.99524958 0.0000000e+0
vn -9.6505640e-2 -0.98655171 0.13191807
vn -9.7356475e-2 -0.99524958 0.0000000e+0
vn -0.17764671 -0.97763993 0.11252476
vn 9.7356475e-2 -0.99524958 0.0000000e+0
vn 9.6505640e-2 -0.98655171 0.13191807
vn 9.7356475e-2 -0.99524958 0.0000000e+0
vn 0.17764671 -0.97763993 0.11252476
vn -2.7217819e-2 -0.99959657 -8.1173501e-3
vn -0.95829012 0.0000000e+0 -0.28579720
vn -0.85484036 0.0000000e+0 0.51889108
vn -0.95829012 0.0000000e+0 -0.28579720
vn -0.85484036 0.0000000e+0 0.51889108
vn 8.6753709e-2 0.99567401 3.3272527e-2
vn 8.2673579e-2 0.99627162 2.4656288e-2
vn -0.95829012 0.0000000e+0 -0.28579720
vn -0.85484036 0.0000000e+0 0.51889108
vn -0.95829012 0.0000000e+0 -0.28579720
vn 0.84335584 0.0000000e+0 -0.53735549
vn 8.2673579e-2 0.99627162 2.4656288e-2
vn -0.95829012 0.0000000e+0 -0.28579720
vn 0.84335584 0.0000000e+0 -0.53735549
vn -0.25024660 -0.96818192 6.4366946e-4
vn -2.7217819e-2 -0.99959657 -8.1173501e-3
vn 0.84335584 0.0000000e+0 -0.53735549
vn -0.95829012 0.0000000e+0 -0.28579720
vn 1.1166894e-2 -0.99988794 -9.9704414e-3
vn -0.38916924 -0.91867155 6.7748717e-2
vn -0.22836934 0.0000000e+0 0.97357457
vn -0.74593766 0.0000000e+0 0.66601577
vn -0.22836934 0.0000000e+0 0.97357457
vn -7.7079267e-2 0.94131828 0.32860109
vn -0.74593766 0.0000000e+0 0.66601577
vn -0.42279812 0.82385482 0.37749832
vn -0.22836934 0.0000000e+0 0.97357457
vn -0.42702825 0.82086493 0.37924616
vn -0.74593766 0.0000000e+0 0.66601577
vn 0.0000000e+0 0.94033441 0.34025166
vn 0.25555460 0.0000000e+0 -0.96679462
vn 0.17664795 0.0000000e+0 -0.98427410
vn 1.9164607e-2 0.99409750 -0.10678429
vn -0.50427448 0.85860405 -9.2229808e-2
vn -9.7356475e-2 -0.99524958 0.0000000e+0
vn 0.17664795 0.0000000e+0 -0.98427410
vn -0.41030048 -0.90951551 -6.6596220e-2
vn 0.25555460 0.0000000e+0 -0.96679462
vn 0.25555460 0.0000000e+0 -0.96679462
vn 0.17664795 0.0000000e+0 -0.98427410
vn -9.7356475e-2 -0.99524958 0.0000000e+0
vn -0.32350669 -0.94622588 0.0000000e+0
vn 0.0000000e+0 0.99341178 -0.11459949
vn -0.36724289 0.91939897 -0.14084814
vn -0.34874278 0.87308361 0.34073961
vn 0.0000000e+0 0.96108401 0.27625628
vn 1.9164607e-2 0.99409750 -0.10678429
vn 0.0000000e+0 0.96108401 0.27625628
vn -0.43656100 0.83918947 0.32430777
vn -0.50427448 0.85860405 -9.2229808e-2
vn -9.6505640e-2 -0.98655171 0.13191807
vn -0.31890558 -0.93276809 0.16805628
vn -9.7356475e-2 -0.99524958 0.0000000e+0
vn -0.32350669 -0.94622588 0.0000000e+0
vn 0.0000000e+0 0.96108401 0.27625628
vn -0.43656100 0.83918947 0.32430777
vn -0.42702825 0.82086493 0.37924616
vn 0.0000000e+0 0.94033441 0.34025166
vn -9.6505640e-2 -0.98655171 0.13191807
vn 1.1166894e-2 -0.99988794 -9.9704414e-3
vn -0.38916924 -0.91867155 6.7748717e-2
vn -0.31890558 -0.93276809 0.16805628
vn -0.17877724 -0.98386157 -7.4236827e-3
vn -0.31484356 -0.93485312 0.16408281
vn -0.17764671 -0.97763993 0.11252476
vn -0.31890277 -0.94690597 4.0866878e-2
vn -7.7079267e-2 0.94131828 0.32860109
vn 0.0000000e+0 0.96108401 0.27625628
vn 0.0000000e+0 0.96108401 0.27625628
vn 0.0000000e+0 0.94033441 0.34025166
vn 7.7079267e-2 0.94131828 0.32860109
vn 0.0000000e+0 0.96108401 0.27625628
vn 0.0000000e+0 0.96108401 0.27625628
vn 0.0000000e+0 0.94033441 0.34025166
vn -0.17877724 -0.98386157 -7.4236827e-3
vn -0.17764671 -0.97763993 0.11252476
vn 0.17877724 -0.98386157 -7.4236827e-3
vn 0.17764671 -0.97763993 0.11252476
vn -0.31484356 -0.93485312 0.16408281
vn -0.88691408 0.0000000e+0 0.46193442
vn -0.82350309 0.0000000e+0 0.56731178
vn -0.31890277 -0.94690597 4.0866878e-2
vn -0.88691408 0.0000000e+0 0.46193442
vn -0.34874278 0.87308361 0.34073961
vn -0.82350309 0.0000000e+0 0.56731178
vn -0.42279812 0.82385482 0.37749832
vn -0.43656100 0.83918947 0.32430777
vn -0.88691408 0.0000000e+0 0.46193442
vn -0.82350309 0.0000000e+0 0.56731178
vn -0.42702825 0.82086493 0.37924616
vn 0.85484036 0.0000000e+0 0.51889108
vn 0.25024660 -0.96818192 6.4366946e-4
vn 0.41030048 -0.90951551 -6.6596220e-2
vn 0.82350309 0.0000000e+0 0.56731178
vn 0.31890558 -0.93276809 0.16805628
vn 0.31484356 -0.93485312 0.16408281
vn 2.7217819e-2 -0.99959657 -8.1173501e-3
vn 0.32350669 -0.94622588 0.0000000e+0
vn 0.82350309 0.0000000e+0 0.56731178
vn 0.85484036 0.0000000e+0 0.51889108
vn 0.85484036 0.0000000e+0 0.51889108
vn -8.6753709e-2 0.99567401 3.3272527e-2
vn 0.36724289 0.91939897 -0.14084814
vn 0.34874278 0.87308361 0.34073961
vn 0.82350309 0.0000000e+0 0.56731178
vn -0.84335584 0.0000000e+0 -0.53735549
vn 0.25024660 -0.96818192 6.4366946e-4
vn 0.41030048 -0.90951551 -6.6596220e-2
vn -0.25555460 0.0000000e+0 -0.96679462
vn -8.6753709e-2 0.99567401 3.3272527e-2
vn -0.84335584 0.0000000e+0 -0.53735549
vn -0.25555460 0.0000000e+0 -0.96679462
vn 0.36724289 0.91939897 -0.14084814
vn -0.84335584 0.0000000e+0 -0.53735549
vn -0.25555460 0.0000000e+0 -0.96679462
vn 0.50427448 0.85860405 -9.2229808e-2
vn -8.2673579e-2 0.99627162 2.4656288e-2
vn 0.88691408 0.0000000e+0 0.46193442
vn 0.74593766 0.0000000e+0 0.66601577
vn 0.42279812 0.82385482 0.37749832
vn 0.88691408 0.0000000e+0 0.46193442
vn 0.74593766 0.0000000e+0 0.66601577
vn -1.1166894e-2 -0.99988794 -9.9704414e-3
vn 0.88691408 0.0000000e+0 0.46193442
vn 0.31890277 -0.94690597 4.0866878e-2
vn 0.74593766 0.0000000e+0 0.66601577
vn 2.7217819e-2 -0.99959657 -8.1173501e-3
vn 0.95829012 0.0000000e+0 -0.28579720
vn 0.85484036 0.0000000e+0 0.51889108
vn 0.95829012 0.0000000e+0 -0.28579720
vn 0.85484036 0.0000000e+0 0.51889108
vn -8.6753709e-2 0.99567401 3.3272527e-2
vn -8.2673579e-2 0.99627162 2.4656288e-2
vn 0.95829012 0.0000000e+0 -0.28579720
vn 0.85484036 0.0000000e+0 0.51889108
vn 0.95829012 0.0000000e+0 -0.28579720
vn -0.84335584 0.0000000e+0 -0.53735549
vn -8.2673579e-2 0.99627162 2.4656288e-2
vn 0.95829012 0.0000000e+0 -0.28579720
vn -0.84335584 0.0000000e+0 -0.53735549
vn 0.25024660 -0.96818192 6.4366946e-4
vn 2.7217819e-2 -0.99959657 -8.1173501e-3
vn -0.84335584 0.0000000e+0 -0.53735549
vn 0.95829012 0.0000000e+0 -0.28579720
vn -1.1166894e-2 -0.99988794 -9.9704414e-3
vn 0.38916924 -0.91867155 6.7748717e-2
vn 0.22836934 0.0000000e+0 0.97357457
vn 0.74593766 0.0000000e+0 0.66601577
vn 0.22836934 0.0000000e+0 0.97357457
vn 7.7079267e-2 0.94131828 0.32860109
vn 0.74593766 0.0000000e+0 0.66601577
vn 0.42279812 0.82385482 0.37749832
vn 0.22836934 0.0000000e+0 0.97357457
vn 0.42702825 0.82086493 0.37924616
vn 0.74593766 0.0000000e+0 0.66601577
vn 0.0000000e+0 0.94033441 0.34025166
vn -0.25555460 0.0000000e+0 -0.96679462
vn -0.17664795 0.0000000e+0 -0.98427410
vn -1.9164607e-2 0.99409750 -0.10678429
vn 0.50427448 0.85860405 -9.2229808e-2
vn 9.7356475e-2 -0.99524958 0.0000000e+0
vn -0.17664795 0.0000000e+0 -0.98427410
vn 0.41030048 -0.90951551 -6.6596220e-2
vn -0.25555460 0.0000000e+0 -0.96679462
vn -0.25555460 0.0000000e+0 -0.96679462
vn -0.17664795 0.0000000e+0 -0.98427410
vn 9.7356475e-2 -0.99524958 0.0000000e+0
vn 0.32350669 -0.94622588 0.0000000e+0
vn 0.0000000e+0 0.99341178 -0.11459949
vn 0.36724289 0.91939897 -0.14084814
vn 0.34874278 0.87308361 0.34073961
vn 0.0000000e+0 0.96108401 0.27625628
vn -1.9164607e-2 0.99409750 -0.10678429
vn 0.0000000e+0 0.96108401 0.27625628
vn 0.43656100 0.83918947 0.32430777
vn 0.50427448 0.85860405 -9.2229808e-2
vn 9.6505640e-2 -0.98655171 0.13191807
vn 0.31890558 -0.93276809 0.16805628
vn 9.7356475e-2 -0.99524958 0.0000000e+0
vn 0.32350669 -0.94622588 0.0000000e+0
vn 0.0000000e+0 0.96108401 0.27625628
vn 0.43656100 0.83918947 0.32430777
vn 0.42702825 0.82086493 0.37924616
vn 0.0000000e+0 0.94033441 0.34025166
vn 9.6505640e-2 -0.98655171 0.13191807
vn -1.1166894e-2 -0.99988794 -9.9704414e-3
vn 0.38916924 -0.91867155 6.7748717e-2
vn 0.31890558 -0.93276809 0.16805628
vn 0.17877724 -0.98386157 -7.4236827e-3
vn 0.31484356 -0.93485312 0.16408281
vn 0.17764671 -0.97763993 0.11252476
vn 0.31890277 -0.94690597 4.0866878e-2
vn 0.31484356 -0.93485312 0.16408281
vn 0.88691408 0.0000000e+0 0.46193442
vn 0.82350309 0.0000000e+0 0.56731178
vn 0.31890277 -0.94690597 4.0866878e-2
vn 0.88691408 0.0000000e+0 0.46193442
vn 0.34874278 0.87308361 0.34073961
vn 0.82350309 0.0000000e+0 0.56731178
vn 0.42279812 0.82385482 0.37749832
vn 0.43656100 0.83918947 0.32430777
vn 0.88691408 0.0000000e+0 0.46193442
vn 0.82350309 0.0000000e+0 0.56731178
vn 0.42702825 0.82086493 0.37924616
g cube1_cube1_auv
usemtl cube1_auv
f 1/38/2 16/39/87 3/37/17
f 1/38/8 20/34/114 22/35/126
f 1/38/6 24/33/136 27/36/151
f 1/5/4 28/13/157 2/9/15
f 2/9/11 14/4/77 1/5/1
f 2/9/14 28/13/156 21/19/117
f 3/20/16 16/7/86 4/18/21
f 3/37/18 20/34/109 1/38/3
f 4/44/20 14/40/78 2/43/12
f 4/18/22 20/24/110 3/20/19
f 4/18/26 21/19/122 19/22/106
f 5/14/28 28/13/155 6/10/31
f 6/10/32 18/15/97 5/14/29
f 6/32/33 24/33/132 17/31/91
f 6/10/34 28/13/160 27/8/152
f 7/17/37 18/15/95 8/12/41
f 7/17/40 40/15/222 25/21/143
f 8/12/43 18/15/99 17/11/93
f 8/30/44 24/33/135 26/29/147
f 8/12/45 40/15/221 7/17/39
f 8/30/46 46/33/259 39/31/218
f 9/25/51 20/24/112 19/22/104
f 9/25/50 21/19/115 11/23/61
f 9/25/53 42/24/234 10/27/60
f 9/25/56 43/19/245 41/22/231
f 10/27/58 20/24/108 9/25/49
f 10/26/59 42/34/233 12/28/69
f 11/23/63 43/19/241 9/25/54
f 12/28/65 20/34/107 10/26/57
f 12/28/66 24/33/131 22/35/123
f 12/28/71 42/34/239 44/35/251
f 12/28/72 46/33/263 26/29/150
f 13/3/75 1/5/10 14/4/81
f 13/41/73 16/39/88 1/38/7
f 14/40/79 4/44/27 15/42/84
f 14/4/80 16/1/90 13/3/74
f 15/6/83 4/18/24 16/7/89
f 15/2/82 16/1/85 14/4/76
f 17/11/94 18/15/101 6/10/36
f 17/31/92 24/33/133 8/30/42
f 18/15/102 25/21/142 23/16/130
f 18/15/98 28/13/158 5/14/30
f 19/22/103 20/24/111 4/18/25
f 19/22/105 21/19/119 9/25/52
f 21/19/116 4/18/23 2/9/13
f 21/19/118 25/21/140 11/23/62
f 21/19/121 28/13/159 23/16/128
f 22/35/125 20/34/113 12/28/67
f 22/35/124 24/33/134 1/38/5
f 23/16/127 25/21/141 21/19/120
f 23/16/129 28/13/162 18/15/100
f 25/21/139 18/15/96 7/17/38
f 25/21/144 43/19/244 11/23/64
f 26/29/148 24/33/137 12/28/68
f 26/29/149 46/33/261 8/30/48
f 27/36/154 24/33/138 6/32/35
f 27/8/153 28/13/161 1/5/9
f 29/5/163 36/4/203 30/9/173
f 29/38/169 38/39/214 35/41/199
f 29/38/165 42/34/235 31/37/180
f 29/38/167 46/33/260 44/35/250
f 29/5/171 48/13/275 47/8/267
f 30/9/175 32/18/185 43/19/242
f 30/43/174 36/40/204 32/44/182
f 30/9/177 48/13/271 29/5/166
f 31/37/179 38/39/213 29/38/164
f 31/20/181 42/24/236 32/18/184
f 32/18/183 38/7/212 31/20/178
f 32/18/187 42/24/237 41/22/229
f 33/14/191 40/15/223 34/10/194
f 33/14/192 48/13/272 40/15/224
f 34/10/198 40/15/227 39/11/220
f 34/32/197 46/33/264 47/36/268
f 34/10/193 48/13/269 33/14/190
f 35/3/200 38/1/216 36/4/206
f 36/4/207 29/5/172 35/3/201
f 36/4/202 38/1/211 37/2/208
f 37/42/210 32/44/189 36/40/205
f 38/7/215 32/18/186 37/6/209
f 39/11/219 40/15/225 8/12/47
f 39/31/217 46/33/258 34/32/195
f 40/15/226 48/13/276 45/16/255
f 41/22/230 42/24/238 9/25/55
f 41/22/232 43/19/248 32/18/188
f 43/19/246 25/21/145 45/16/253
f 43/19/243 48/13/270 30/9/176
f 44/35/252 42/34/240 29/38/170
f 44/35/249 46/33/257 12/28/70
f 45/16/256 25/21/146 40/15/228
f 45/16/254 48/13/273 43/19/247
f 47/36/265 46/33/262 29/38/168
f 47/8/266 48/13/274 34/10/196

3189
cw 5/models/sphere.obj Executable file

File diff suppressed because it is too large Load Diff

21
cw 5/shaders/shader_4_1.frag Executable file
View File

@ -0,0 +1,21 @@
#version 410 core
uniform vec3 objectColor;
//uniform vec3 lightDir;
uniform vec3 lightPos;
uniform vec3 cameraPos;
in vec3 interpNormal;
in vec3 fragPos;
void main()
{
vec3 lightDir = normalize(lightPos-fragPos);
vec3 V = normalize(cameraPos-fragPos);
vec3 normal = normalize(interpNormal);
vec3 R = reflect(-normalize(lightDir),normal);
float specular = pow(max(0,dot(R,V)),10);
float diffuse = max(0,dot(normal,normalize(lightDir)));
gl_FragColor = vec4(mix(objectColor,objectColor*diffuse+vec3(1)*specular,0.9), 1.0);
}

17
cw 5/shaders/shader_4_1.vert Executable file
View File

@ -0,0 +1,17 @@
#version 410 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 1) in vec3 vertexNormal;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 interpNormal;
out vec3 fragPos;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
interpNormal = (modelMatrix*vec4(vertexNormal,0)).xyz;
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
}

17
cw 5/shaders/shader_4_sun.frag Executable file
View File

@ -0,0 +1,17 @@
#version 410 core
uniform vec3 objectColor;
//uniform vec3 lightDir;
uniform vec3 lightPos;
uniform vec3 cameraPos;
in vec3 interpNormal;
in vec3 fragPos;
void main()
{
vec3 normal = normalize(interpNormal);
vec3 V = normalize(cameraPos-fragPos);
float coef = max(0,dot(V,normal));
gl_FragColor = vec4(mix(objectColor,vec3(0.2,0.5,0),1-coef), 1.0);
}

18
cw 5/shaders/shader_4_sun.vert Executable file
View File

@ -0,0 +1,18 @@
#version 410 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 1) in vec3 vertexNormal;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 interpNormal;
out vec3 fragPos;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
interpNormal = (modelMatrix*vec4(vertexNormal,0)).xyz;
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
}

23
cw 5/shaders/shader_4_tex.frag Executable file
View File

@ -0,0 +1,23 @@
#version 410 core
uniform vec3 objectColor;
//uniform vec3 lightDir;
uniform vec3 lightPos;
uniform vec3 cameraPos;
uniform sampler2D colorTexture;
in vec2 vertexTexCoord;
in vec3 interpNormal;
in vec3 fragPos;
void main()
{
vec3 lightDir = normalize(lightPos-fragPos);
vec3 V = normalize(cameraPos-fragPos);
vec3 normal = normalize(interpNormal);
vec3 R = reflect(-normalize(lightDir),normal);
float specular = pow(max(0,dot(R,V)),10);
float diffuse = max(0,dot(normal,normalize(lightDir)));
gl_FragColor = vec4(mix(objectColor,objectColor*diffuse+vec3(1)*specular,0.9), 1.0);
}

22
cw 5/shaders/shader_4_tex.vert Executable file
View File

@ -0,0 +1,22 @@
#version 410 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec2 vertexTexCoord;
out vec3 interpNormal;
out vec3 fragPos;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
interpNormal = (modelMatrix*vec4(vertexNormal,0)).xyz;
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
}

104
cw 5/src/Box.cpp Executable file
View File

@ -0,0 +1,104 @@
// dane 36 wierzcholkow i kolorow opisujace model pudelka
const float boxPositions[] = {
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
0.25f, 0.25f, -0.75f, 1.0f,
-0.25f, 0.25f, 0.75f, 1.0f,
-0.25f, 0.25f, -0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, 0.75f, 1.0f,
0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, -0.75f, 1.0f,
-0.25f, -0.25f, 0.75f, 1.0f,
};
const float boxColors[] = {
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
};

31
cw 5/src/Camera.cpp Executable file
View File

@ -0,0 +1,31 @@
#include "Camera.h"
glm::mat4 Core::createPerspectiveMatrix(float zNear, float zFar, float frustumScale)
{
glm::mat4 perspective;
perspective[0][0] = 1.f;
perspective[1][1] = frustumScale;
perspective[2][2] = (zFar + zNear) / (zNear - zFar);
perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
perspective[2][3] = -1;
perspective[3][3] = 0;
return perspective;
}
glm::mat4 Core::createViewMatrix( glm::vec3 position, glm::vec3 forward, glm::vec3 up )
{
glm::vec3 side = glm::cross(forward, up);
// Trzeba pamietac o minusie przy ustawianiu osi Z kamery.
// Wynika to z tego, ze standardowa macierz perspektywiczna zaklada, ze "z przodu" jest ujemna (a nie dodatnia) czesc osi Z.
glm::mat4 cameraRotation;
cameraRotation[0][0] = side.x; cameraRotation[1][0] = side.y; cameraRotation[2][0] = side.z;
cameraRotation[0][1] = up.x; cameraRotation[1][1] = up.y; cameraRotation[2][1] = up.z;
cameraRotation[0][2] = -forward.x; cameraRotation[1][2] = -forward.y; cameraRotation[2][2] = -forward.z;
glm::mat4 cameraTranslation;
cameraTranslation[3] = glm::vec4(-position, 1.0f);
return cameraRotation * cameraTranslation;
}

14
cw 5/src/Camera.h Executable file
View File

@ -0,0 +1,14 @@
#pragma once
#include "glm.hpp"
namespace Core
{
glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f, float frustumScale = 1.f);
// position - pozycja kamery
// forward - wektor "do przodu" kamery (jednostkowy)
// up - wektor "w gore" kamery (jednostkowy)
// up i forward musza byc ortogonalne!
glm::mat4 createViewMatrix(glm::vec3 position, glm::vec3 forward, glm::vec3 up);
}

169
cw 5/src/Render_Utils.cpp Executable file
View File

@ -0,0 +1,169 @@
#include "Render_Utils.h"
#include <algorithm>
#include "glew.h"
#include "freeglut.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
void Core::RenderContext::initFromOBJ(obj::Model& model)
{
vertexArray = 0;
vertexBuffer = 0;
vertexIndexBuffer = 0;
unsigned int vertexDataBufferSize = sizeof(float) * model.vertex.size();
unsigned int vertexNormalBufferSize = sizeof(float) * model.normal.size();
unsigned int vertexTexBufferSize = sizeof(float) * model.texCoord.size();
size = model.faces["default"].size();
unsigned int vertexElementBufferSize = sizeof(unsigned short) * size;
glGenVertexArrays(1, &vertexArray);
glBindVertexArray(vertexArray);
glGenBuffers(1, &vertexIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &model.faces["default"][0], GL_STATIC_DRAW);
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, &model.vertex[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, &model.normal[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &model.texCoord[0]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
}
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
vertexArray = 0;
vertexBuffer = 0;
vertexIndexBuffer = 0;
std::vector<float> textureCoord;
std::vector<unsigned int> indices;
//tex coord must be converted to 2d vecs
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
if (mesh->mTextureCoords[0] != nullptr) {
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
}
else {
textureCoord.push_back(0.0f);
textureCoord.push_back(0.0f);
}
}
if (mesh->mTextureCoords[0] == nullptr) {
std::cout << "no uv coords\n";
}
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
// retrieve all indices of the face and store them in the indices vector
for (unsigned int j = 0; j < face.mNumIndices; j++)
indices.push_back(face.mIndices[j]);
}
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
unsigned int vertexTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexBiTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
unsigned int vertexElementBufferSize = sizeof(unsigned int) * indices.size();
size = indices.size();
glGenVertexArrays(1, &vertexArray);
glBindVertexArray(vertexArray);
glGenBuffers(1, &vertexIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
//std::cout << vertexBuffer;
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize + vertexBiTangentBufferSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, vertexTangentBufferSize, mesh->mTangents);
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize));
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize));
}
void Core::DrawVertexArray(const float * vertexArray, int numVertices, int elementSize )
{
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, numVertices);
}
void Core::DrawVertexArrayIndexed( const float * vertexArray, const int * indexArray, int numIndexes, int elementSize )
{
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
glEnableVertexAttribArray(0);
glDrawElements(GL_TRIANGLES, numIndexes, GL_UNSIGNED_INT, indexArray);
}
void Core::DrawVertexArray( const VertexData & data )
{
int numAttribs = std::min(VertexData::MAX_ATTRIBS, data.NumActiveAttribs);
for(int i = 0; i < numAttribs; i++)
{
glVertexAttribPointer(i, data.Attribs[i].Size, GL_FLOAT, false, 0, data.Attribs[i].Pointer);
glEnableVertexAttribArray(i);
}
glDrawArrays(GL_TRIANGLES, 0, data.NumVertices);
}
void Core::DrawContext(Core::RenderContext& context)
{
glBindVertexArray(context.vertexArray);
glDrawElements(
GL_TRIANGLES, // mode
context.size, // count
GL_UNSIGNED_INT, // type
(void*)0 // element array buffer offset
);
glBindVertexArray(0);
}

72
cw 5/src/Render_Utils.h Executable file
View File

@ -0,0 +1,72 @@
#pragma once
#include "glm.hpp"
#include "glew.h"
#include "objload.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
namespace Core
{
struct RenderContext
{
GLuint vertexArray;
GLuint vertexBuffer;
GLuint vertexIndexBuffer;
int size = 0;
void initFromOBJ(obj::Model& model);
void initFromAssimpMesh(aiMesh* mesh);
};
// vertexArray - jednowymiarowa tablica zawierajaca wartosci opisujace pozycje kolejnych wierzcholkow w jednym ciagu (x1, y1, z1, w1, x2, y2, z2, w2, ...)
// numVertices - liczba wierzcholkow do narysowania
// elementSize - liczba wartosci opisujacych pojedynczy wierzcholek (np. 3 gdy wierzcholek opisany jest trojka (x, y, z))
void DrawVertexArray(const float * vertexArray, int numVertices, int elementSize);
// indexArray - jednowymiarowa tablica zawierajaca indeksy wierzcholkow kolejnych trojkatow w jednym ciagu (t1_i1, t1_i2, t1_i3, t2_i1, t2_i2, t2_i3, ...)
// numIndexes - liczba indeksow w tablicy indexArray
void DrawVertexArrayIndexed(const float * vertexArray, const int * indexArray, int numIndexes, int elementSize);
struct VertexAttribute
{
const void * Pointer;
int Size;
};
struct VertexData
{
static const int MAX_ATTRIBS = 8;
VertexAttribute Attribs[MAX_ATTRIBS];
int NumActiveAttribs;
int NumVertices;
};
// Ta funkcja sluzy do rysowania trojkatow, ktorych wierzcholki moga byc opisane wiecej niz jednym atrybutem.
// Funkcja przyjmuje jako parametr strukture, w ktorej nalezy zawrzec wszystkie potrzebne dane.
//
// Przykladowe wywolanie funkcji - narysowanie trojkata jak na pierwszych zajeciach:
/*
const float vertices[] = {
0.25f, 0.25f, 0.0f, 1.0f,
0.25f, -0.25f, 0.0f, 1.0f,
-0.25f, -0.25f, 0.0f, 1.0f
};
Core::VertexData vertexData;
vertexData.NumActiveAttribs = 1; // Liczba uzywanych atrybutow wierzcholka
vertexData.Attribs[0].Pointer = vertices; // Wskaznik na dane zerowego atrybutu
vertexData.Attribs[0].Size = 4; // Wielkosc zerowego atrybutu (ilosc liczb opisujacych ten atrybut w pojedynczym wierzcholku)
vertexData.NumVertices = 3; // Liczba wierzcholkow do narysowania
Core::DrawVertexArray(vertexData);
*/
void DrawVertexArray(const VertexData & data);
void DrawContext(RenderContext& context);
}

2024
cw 5/src/SOIL/SOIL.c Executable file

File diff suppressed because it is too large Load Diff

433
cw 5/src/SOIL/SOIL.h Executable file
View File

@ -0,0 +1,433 @@
/**
@mainpage SOIL
Jonathan Dummer
2007-07-26-10.36
Simple OpenGL Image Library
A tiny c library for uploading images as
textures into OpenGL. Also saving and
loading of images is supported.
I'm using Sean's Tool Box image loader as a base:
http://www.nothings.org/
I'm upgrading it to load TGA and DDS files, and a direct
path for loading DDS files straight into OpenGL textures,
when applicable.
Image Formats:
- BMP load & save
- TGA load & save
- DDS load & save
- PNG load
- JPG load
OpenGL Texture Features:
- resample to power-of-two sizes
- MIPmap generation
- compressed texture S3TC formats (if supported)
- can pre-multiply alpha for you, for better compositing
- can flip image about the y-axis (except pre-compressed DDS files)
Thanks to:
* Sean Barret - for the awesome stb_image
* Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts
* everybody at gamedev.net
**/
#ifndef HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY
#define HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY
#ifdef __cplusplus
extern "C" {
#endif
/**
The format of images that may be loaded (force_channels).
SOIL_LOAD_AUTO leaves the image in whatever format it was found.
SOIL_LOAD_L forces the image to load as Luminous (greyscale)
SOIL_LOAD_LA forces the image to load as Luminous with Alpha
SOIL_LOAD_RGB forces the image to load as Red Green Blue
SOIL_LOAD_RGBA forces the image to load as Red Green Blue Alpha
**/
enum
{
SOIL_LOAD_AUTO = 0,
SOIL_LOAD_L = 1,
SOIL_LOAD_LA = 2,
SOIL_LOAD_RGB = 3,
SOIL_LOAD_RGBA = 4
};
/**
Passed in as reuse_texture_ID, will cause SOIL to
register a new texture ID using glGenTextures().
If the value passed into reuse_texture_ID > 0 then
SOIL will just re-use that texture ID (great for
reloading image assets in-game!)
**/
enum
{
SOIL_CREATE_NEW_ID = 0
};
/**
flags you can pass into SOIL_load_OGL_texture()
and SOIL_create_OGL_texture().
(note that if SOIL_FLAG_DDS_LOAD_DIRECT is used
the rest of the flags with the exception of
SOIL_FLAG_TEXTURE_REPEATS will be ignored while
loading already-compressed DDS files.)
SOIL_FLAG_POWER_OF_TWO: force the image to be POT
SOIL_FLAG_MIPMAPS: generate mipmaps for the texture
SOIL_FLAG_TEXTURE_REPEATS: otherwise will clamp
SOIL_FLAG_MULTIPLY_ALPHA: for using (GL_ONE,GL_ONE_MINUS_SRC_ALPHA) blending
SOIL_FLAG_INVERT_Y: flip the image vertically
SOIL_FLAG_COMPRESS_TO_DXT: if the card can display them, will convert RGB to DXT1, RGBA to DXT5
SOIL_FLAG_DDS_LOAD_DIRECT: will load DDS files directly without _ANY_ additional processing
SOIL_FLAG_NTSC_SAFE_RGB: clamps RGB components to the range [16,235]
SOIL_FLAG_CoCg_Y: Google YCoCg; RGB=>CoYCg, RGBA=>CoCgAY
SOIL_FLAG_TEXTURE_RECTANGE: uses ARB_texture_rectangle ; pixel indexed & no repeat or MIPmaps or cubemaps
**/
enum
{
SOIL_FLAG_POWER_OF_TWO = 1,
SOIL_FLAG_MIPMAPS = 2,
SOIL_FLAG_TEXTURE_REPEATS = 4,
SOIL_FLAG_MULTIPLY_ALPHA = 8,
SOIL_FLAG_INVERT_Y = 16,
SOIL_FLAG_COMPRESS_TO_DXT = 32,
SOIL_FLAG_DDS_LOAD_DIRECT = 64,
SOIL_FLAG_NTSC_SAFE_RGB = 128,
SOIL_FLAG_CoCg_Y = 256,
SOIL_FLAG_TEXTURE_RECTANGLE = 512
};
/**
The types of images that may be saved.
(TGA supports uncompressed RGB / RGBA)
(BMP supports uncompressed RGB)
(DDS supports DXT1 and DXT5)
**/
enum
{
SOIL_SAVE_TYPE_TGA = 0,
SOIL_SAVE_TYPE_BMP = 1,
SOIL_SAVE_TYPE_DDS = 2
};
/**
Defines the order of faces in a DDS cubemap.
I recommend that you use the same order in single
image cubemap files, so they will be interchangeable
with DDS cubemaps when using SOIL.
**/
#define SOIL_DDS_CUBEMAP_FACE_ORDER "EWUDNS"
/**
The types of internal fake HDR representations
SOIL_HDR_RGBE: RGB * pow( 2.0, A - 128.0 )
SOIL_HDR_RGBdivA: RGB / A
SOIL_HDR_RGBdivA2: RGB / (A*A)
**/
enum
{
SOIL_HDR_RGBE = 0,
SOIL_HDR_RGBdivA = 1,
SOIL_HDR_RGBdivA2 = 2
};
/**
Loads an image from disk into an OpenGL texture.
\param filename the name of the file to upload as a texture
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_load_OGL_texture
(
const char *filename,
int force_channels,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Loads 6 images from disk into an OpenGL cubemap texture.
\param x_pos_file the name of the file to upload as the +x cube face
\param x_neg_file the name of the file to upload as the -x cube face
\param y_pos_file the name of the file to upload as the +y cube face
\param y_neg_file the name of the file to upload as the -y cube face
\param z_pos_file the name of the file to upload as the +z cube face
\param z_neg_file the name of the file to upload as the -z cube face
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_load_OGL_cubemap
(
const char *x_pos_file,
const char *x_neg_file,
const char *y_pos_file,
const char *y_neg_file,
const char *z_pos_file,
const char *z_neg_file,
int force_channels,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Loads 1 image from disk and splits it into an OpenGL cubemap texture.
\param filename the name of the file to upload as a texture
\param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc.
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_load_OGL_single_cubemap
(
const char *filename,
const char face_order[6],
int force_channels,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Loads an HDR image from disk into an OpenGL texture.
\param filename the name of the file to upload as a texture
\param fake_HDR_format SOIL_HDR_RGBE, SOIL_HDR_RGBdivA, SOIL_HDR_RGBdivA2
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_load_OGL_HDR_texture
(
const char *filename,
int fake_HDR_format,
int rescale_to_max,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Loads an image from RAM into an OpenGL texture.
\param buffer the image data in RAM just as if it were still in a file
\param buffer_length the size of the buffer in bytes
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_load_OGL_texture_from_memory
(
const unsigned char *const buffer,
int buffer_length,
int force_channels,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Loads 6 images from memory into an OpenGL cubemap texture.
\param x_pos_buffer the image data in RAM to upload as the +x cube face
\param x_pos_buffer_length the size of the above buffer
\param x_neg_buffer the image data in RAM to upload as the +x cube face
\param x_neg_buffer_length the size of the above buffer
\param y_pos_buffer the image data in RAM to upload as the +x cube face
\param y_pos_buffer_length the size of the above buffer
\param y_neg_buffer the image data in RAM to upload as the +x cube face
\param y_neg_buffer_length the size of the above buffer
\param z_pos_buffer the image data in RAM to upload as the +x cube face
\param z_pos_buffer_length the size of the above buffer
\param z_neg_buffer the image data in RAM to upload as the +x cube face
\param z_neg_buffer_length the size of the above buffer
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_load_OGL_cubemap_from_memory
(
const unsigned char *const x_pos_buffer,
int x_pos_buffer_length,
const unsigned char *const x_neg_buffer,
int x_neg_buffer_length,
const unsigned char *const y_pos_buffer,
int y_pos_buffer_length,
const unsigned char *const y_neg_buffer,
int y_neg_buffer_length,
const unsigned char *const z_pos_buffer,
int z_pos_buffer_length,
const unsigned char *const z_neg_buffer,
int z_neg_buffer_length,
int force_channels,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Loads 1 image from RAM and splits it into an OpenGL cubemap texture.
\param buffer the image data in RAM just as if it were still in a file
\param buffer_length the size of the buffer in bytes
\param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc.
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_load_OGL_single_cubemap_from_memory
(
const unsigned char *const buffer,
int buffer_length,
const char face_order[6],
int force_channels,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Creates a 2D OpenGL texture from raw image data. Note that the raw data is
_NOT_ freed after the upload (so the user can load various versions).
\param data the raw data to be uploaded as an OpenGL texture
\param width the width of the image in pixels
\param height the height of the image in pixels
\param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_create_OGL_texture
(
const unsigned char *const data,
int width, int height, int channels,
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Creates an OpenGL cubemap texture by splitting up 1 image into 6 parts.
\param data the raw data to be uploaded as an OpenGL texture
\param width the width of the image in pixels
\param height the height of the image in pixels
\param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
\param face_order the order of the faces in the file, and combination of NSWEUD, for North, South, Up, etc.
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
\return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
SOIL_create_OGL_single_cubemap
(
const unsigned char *const data,
int width, int height, int channels,
const char face_order[6],
unsigned int reuse_texture_ID,
unsigned int flags
);
/**
Captures the OpenGL window (RGB) and saves it to disk
\return 0 if it failed, otherwise returns 1
**/
int
SOIL_save_screenshot
(
const char *filename,
int image_type,
int x, int y,
int width, int height
);
/**
Loads an image from disk into an array of unsigned chars.
Note that *channels return the original channel count of the
image. If force_channels was other than SOIL_LOAD_AUTO,
the resulting image has force_channels, but *channels may be
different (if the original image had a different channel
count).
\return 0 if failed, otherwise returns 1
**/
unsigned char*
SOIL_load_image
(
const char *filename,
int *width, int *height, int *channels,
int force_channels
);
/**
Loads an image from memory into an array of unsigned chars.
Note that *channels return the original channel count of the
image. If force_channels was other than SOIL_LOAD_AUTO,
the resulting image has force_channels, but *channels may be
different (if the original image had a different channel
count).
\return 0 if failed, otherwise returns 1
**/
unsigned char*
SOIL_load_image_from_memory
(
const unsigned char *const buffer,
int buffer_length,
int *width, int *height, int *channels,
int force_channels
);
/**
Saves an image from an array of unsigned chars (RGBA) to disk
\return 0 if failed, otherwise returns 1
**/
int
SOIL_save_image
(
const char *filename,
int image_type,
int width, int height, int channels,
const unsigned char *const data
);
/**
Frees the image data (note, this is just C's "free()"...this function is
present mostly so C++ programmers don't forget to use "free()" and call
"delete []" instead [8^)
**/
void
SOIL_free_image_data
(
unsigned char *img_data
);
/**
This function resturn a pointer to a string describing the last thing
that happened inside SOIL. It can be used to determine why an image
failed to load.
**/
const char*
SOIL_last_result
(
void
);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY */

632
cw 5/src/SOIL/image_DXT.c Executable file
View File

@ -0,0 +1,632 @@
/*
Jonathan Dummer
2007-07-31-10.32
simple DXT compression / decompression code
public domain
*/
#include "image_DXT.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* set this =1 if you want to use the covarince matrix method...
which is better than my method of using standard deviations
overall, except on the infintesimal chance that the power
method fails for finding the largest eigenvector */
#define USE_COV_MAT 1
/********* Function Prototypes *********/
/*
Takes a 4x4 block of pixels and compresses it into 8 bytes
in DXT1 format (color only, no alpha). Speed is valued
over prettyness, at least for now.
*/
void compress_DDS_color_block(
int channels,
const unsigned char *const uncompressed,
unsigned char compressed[8] );
/*
Takes a 4x4 block of pixels and compresses the alpha
component it into 8 bytes for use in DXT5 DDS files.
Speed is valued over prettyness, at least for now.
*/
void compress_DDS_alpha_block(
const unsigned char *const uncompressed,
unsigned char compressed[8] );
/********* Actual Exposed Functions *********/
int
save_image_as_DDS
(
const char *filename,
int width, int height, int channels,
const unsigned char *const data
)
{
/* variables */
FILE *fout;
unsigned char *DDS_data;
DDS_header header;
int DDS_size;
/* error check */
if( (NULL == filename) ||
(width < 1) || (height < 1) ||
(channels < 1) || (channels > 4) ||
(data == NULL ) )
{
return 0;
}
/* Convert the image */
if( (channels & 1) == 1 )
{
/* no alpha, just use DXT1 */
DDS_data = convert_image_to_DXT1( data, width, height, channels, &DDS_size );
} else
{
/* has alpha, so use DXT5 */
DDS_data = convert_image_to_DXT5( data, width, height, channels, &DDS_size );
}
/* save it */
memset( &header, 0, sizeof( DDS_header ) );
header.dwMagic = ('D' << 0) | ('D' << 8) | ('S' << 16) | (' ' << 24);
header.dwSize = 124;
header.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_LINEARSIZE;
header.dwWidth = width;
header.dwHeight = height;
header.dwPitchOrLinearSize = DDS_size;
header.sPixelFormat.dwSize = 32;
header.sPixelFormat.dwFlags = DDPF_FOURCC;
if( (channels & 1) == 1 )
{
header.sPixelFormat.dwFourCC = ('D' << 0) | ('X' << 8) | ('T' << 16) | ('1' << 24);
} else
{
header.sPixelFormat.dwFourCC = ('D' << 0) | ('X' << 8) | ('T' << 16) | ('5' << 24);
}
header.sCaps.dwCaps1 = DDSCAPS_TEXTURE;
/* write it out */
fout = fopen( filename, "wb");
fwrite( &header, sizeof( DDS_header ), 1, fout );
fwrite( DDS_data, 1, DDS_size, fout );
fclose( fout );
/* done */
free( DDS_data );
return 1;
}
unsigned char* convert_image_to_DXT1(
const unsigned char *const uncompressed,
int width, int height, int channels,
int *out_size )
{
unsigned char *compressed;
int i, j, x, y;
unsigned char ublock[16*3];
unsigned char cblock[8];
int index = 0, chan_step = 1;
int block_count = 0;
/* error check */
*out_size = 0;
if( (width < 1) || (height < 1) ||
(NULL == uncompressed) ||
(channels < 1) || (channels > 4) )
{
return NULL;
}
/* for channels == 1 or 2, I do not step forward for R,G,B values */
if( channels < 3 )
{
chan_step = 0;
}
/* get the RAM for the compressed image
(8 bytes per 4x4 pixel block) */
*out_size = ((width+3) >> 2) * ((height+3) >> 2) * 8;
compressed = (unsigned char*)malloc( *out_size );
/* go through each block */
for( j = 0; j < height; j += 4 )
{
for( i = 0; i < width; i += 4 )
{
/* copy this block into a new one */
int idx = 0;
int mx = 4, my = 4;
if( j+4 >= height )
{
my = height - j;
}
if( i+4 >= width )
{
mx = width - i;
}
for( y = 0; y < my; ++y )
{
for( x = 0; x < mx; ++x )
{
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels];
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step];
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step+chan_step];
}
for( x = mx; x < 4; ++x )
{
ublock[idx++] = ublock[0];
ublock[idx++] = ublock[1];
ublock[idx++] = ublock[2];
}
}
for( y = my; y < 4; ++y )
{
for( x = 0; x < 4; ++x )
{
ublock[idx++] = ublock[0];
ublock[idx++] = ublock[1];
ublock[idx++] = ublock[2];
}
}
/* compress the block */
++block_count;
compress_DDS_color_block( 3, ublock, cblock );
/* copy the data from the block into the main block */
for( x = 0; x < 8; ++x )
{
compressed[index++] = cblock[x];
}
}
}
return compressed;
}
unsigned char* convert_image_to_DXT5(
const unsigned char *const uncompressed,
int width, int height, int channels,
int *out_size )
{
unsigned char *compressed;
int i, j, x, y;
unsigned char ublock[16*4];
unsigned char cblock[8];
int index = 0, chan_step = 1;
int block_count = 0, has_alpha;
/* error check */
*out_size = 0;
if( (width < 1) || (height < 1) ||
(NULL == uncompressed) ||
(channels < 1) || ( channels > 4) )
{
return NULL;
}
/* for channels == 1 or 2, I do not step forward for R,G,B vales */
if( channels < 3 )
{
chan_step = 0;
}
/* # channels = 1 or 3 have no alpha, 2 & 4 do have alpha */
has_alpha = 1 - (channels & 1);
/* get the RAM for the compressed image
(16 bytes per 4x4 pixel block) */
*out_size = ((width+3) >> 2) * ((height+3) >> 2) * 16;
compressed = (unsigned char*)malloc( *out_size );
/* go through each block */
for( j = 0; j < height; j += 4 )
{
for( i = 0; i < width; i += 4 )
{
/* local variables, and my block counter */
int idx = 0;
int mx = 4, my = 4;
if( j+4 >= height )
{
my = height - j;
}
if( i+4 >= width )
{
mx = width - i;
}
for( y = 0; y < my; ++y )
{
for( x = 0; x < mx; ++x )
{
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels];
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step];
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step+chan_step];
ublock[idx++] =
has_alpha * uncompressed[(j+y)*width*channels+(i+x)*channels+channels-1]
+ (1-has_alpha)*255;
}
for( x = mx; x < 4; ++x )
{
ublock[idx++] = ublock[0];
ublock[idx++] = ublock[1];
ublock[idx++] = ublock[2];
ublock[idx++] = ublock[3];
}
}
for( y = my; y < 4; ++y )
{
for( x = 0; x < 4; ++x )
{
ublock[idx++] = ublock[0];
ublock[idx++] = ublock[1];
ublock[idx++] = ublock[2];
ublock[idx++] = ublock[3];
}
}
/* now compress the alpha block */
compress_DDS_alpha_block( ublock, cblock );
/* copy the data from the compressed alpha block into the main buffer */
for( x = 0; x < 8; ++x )
{
compressed[index++] = cblock[x];
}
/* then compress the color block */
++block_count;
compress_DDS_color_block( 4, ublock, cblock );
/* copy the data from the compressed color block into the main buffer */
for( x = 0; x < 8; ++x )
{
compressed[index++] = cblock[x];
}
}
}
return compressed;
}
/********* Helper Functions *********/
int convert_bit_range( int c, int from_bits, int to_bits )
{
int b = (1 << (from_bits - 1)) + c * ((1 << to_bits) - 1);
return (b + (b >> from_bits)) >> from_bits;
}
int rgb_to_565( int r, int g, int b )
{
return
(convert_bit_range( r, 8, 5 ) << 11) |
(convert_bit_range( g, 8, 6 ) << 05) |
(convert_bit_range( b, 8, 5 ) << 00);
}
void rgb_888_from_565( unsigned int c, int *r, int *g, int *b )
{
*r = convert_bit_range( (c >> 11) & 31, 5, 8 );
*g = convert_bit_range( (c >> 05) & 63, 6, 8 );
*b = convert_bit_range( (c >> 00) & 31, 5, 8 );
}
void compute_color_line_STDEV(
const unsigned char *const uncompressed,
int channels,
float point[3], float direction[3] )
{
const float inv_16 = 1.0f / 16.0f;
int i;
float sum_r = 0.0f, sum_g = 0.0f, sum_b = 0.0f;
float sum_rr = 0.0f, sum_gg = 0.0f, sum_bb = 0.0f;
float sum_rg = 0.0f, sum_rb = 0.0f, sum_gb = 0.0f;
/* calculate all data needed for the covariance matrix
( to compare with _rygdxt code) */
for( i = 0; i < 16*channels; i += channels )
{
sum_r += uncompressed[i+0];
sum_rr += uncompressed[i+0] * uncompressed[i+0];
sum_g += uncompressed[i+1];
sum_gg += uncompressed[i+1] * uncompressed[i+1];
sum_b += uncompressed[i+2];
sum_bb += uncompressed[i+2] * uncompressed[i+2];
sum_rg += uncompressed[i+0] * uncompressed[i+1];
sum_rb += uncompressed[i+0] * uncompressed[i+2];
sum_gb += uncompressed[i+1] * uncompressed[i+2];
}
/* convert the sums to averages */
sum_r *= inv_16;
sum_g *= inv_16;
sum_b *= inv_16;
/* and convert the squares to the squares of the value - avg_value */
sum_rr -= 16.0f * sum_r * sum_r;
sum_gg -= 16.0f * sum_g * sum_g;
sum_bb -= 16.0f * sum_b * sum_b;
sum_rg -= 16.0f * sum_r * sum_g;
sum_rb -= 16.0f * sum_r * sum_b;
sum_gb -= 16.0f * sum_g * sum_b;
/* the point on the color line is the average */
point[0] = sum_r;
point[1] = sum_g;
point[2] = sum_b;
#if USE_COV_MAT
/*
The following idea was from ryg.
(https://mollyrocket.com/forums/viewtopic.php?t=392)
The method worked great (less RMSE than mine) most of
the time, but had some issues handling some simple
boundary cases, like full green next to full red,
which would generate a covariance matrix like this:
| 1 -1 0 |
| -1 1 0 |
| 0 0 0 |
For a given starting vector, the power method can
generate all zeros! So no starting with {1,1,1}
as I was doing! This kind of error is still a
slight posibillity, but will be very rare.
*/
/* use the covariance matrix directly
(1st iteration, don't use all 1.0 values!) */
sum_r = 1.0f;
sum_g = 2.718281828f;
sum_b = 3.141592654f;
direction[0] = sum_r*sum_rr + sum_g*sum_rg + sum_b*sum_rb;
direction[1] = sum_r*sum_rg + sum_g*sum_gg + sum_b*sum_gb;
direction[2] = sum_r*sum_rb + sum_g*sum_gb + sum_b*sum_bb;
/* 2nd iteration, use results from the 1st guy */
sum_r = direction[0];
sum_g = direction[1];
sum_b = direction[2];
direction[0] = sum_r*sum_rr + sum_g*sum_rg + sum_b*sum_rb;
direction[1] = sum_r*sum_rg + sum_g*sum_gg + sum_b*sum_gb;
direction[2] = sum_r*sum_rb + sum_g*sum_gb + sum_b*sum_bb;
/* 3rd iteration, use results from the 2nd guy */
sum_r = direction[0];
sum_g = direction[1];
sum_b = direction[2];
direction[0] = sum_r*sum_rr + sum_g*sum_rg + sum_b*sum_rb;
direction[1] = sum_r*sum_rg + sum_g*sum_gg + sum_b*sum_gb;
direction[2] = sum_r*sum_rb + sum_g*sum_gb + sum_b*sum_bb;
#else
/* use my standard deviation method
(very robust, a tiny bit slower and less accurate) */
direction[0] = sqrt( sum_rr );
direction[1] = sqrt( sum_gg );
direction[2] = sqrt( sum_bb );
/* which has a greater component */
if( sum_gg > sum_rr )
{
/* green has greater component, so base the other signs off of green */
if( sum_rg < 0.0f )
{
direction[0] = -direction[0];
}
if( sum_gb < 0.0f )
{
direction[2] = -direction[2];
}
} else
{
/* red has a greater component */
if( sum_rg < 0.0f )
{
direction[1] = -direction[1];
}
if( sum_rb < 0.0f )
{
direction[2] = -direction[2];
}
}
#endif
}
void LSE_master_colors_max_min(
int *cmax, int *cmin,
int channels,
const unsigned char *const uncompressed )
{
int i, j;
/* the master colors */
int c0[3], c1[3];
/* used for fitting the line */
float sum_x[] = { 0.0f, 0.0f, 0.0f };
float sum_x2[] = { 0.0f, 0.0f, 0.0f };
float dot_max = 1.0f, dot_min = -1.0f;
float vec_len2 = 0.0f;
float dot;
/* error check */
if( (channels < 3) || (channels > 4) )
{
return;
}
compute_color_line_STDEV( uncompressed, channels, sum_x, sum_x2 );
vec_len2 = 1.0f / ( 0.00001f +
sum_x2[0]*sum_x2[0] + sum_x2[1]*sum_x2[1] + sum_x2[2]*sum_x2[2] );
/* finding the max and min vector values */
dot_max =
(
sum_x2[0] * uncompressed[0] +
sum_x2[1] * uncompressed[1] +
sum_x2[2] * uncompressed[2]
);
dot_min = dot_max;
for( i = 1; i < 16; ++i )
{
dot =
(
sum_x2[0] * uncompressed[i*channels+0] +
sum_x2[1] * uncompressed[i*channels+1] +
sum_x2[2] * uncompressed[i*channels+2]
);
if( dot < dot_min )
{
dot_min = dot;
} else if( dot > dot_max )
{
dot_max = dot;
}
}
/* and the offset (from the average location) */
dot = sum_x2[0]*sum_x[0] + sum_x2[1]*sum_x[1] + sum_x2[2]*sum_x[2];
dot_min -= dot;
dot_max -= dot;
/* post multiply by the scaling factor */
dot_min *= vec_len2;
dot_max *= vec_len2;
/* OK, build the master colors */
for( i = 0; i < 3; ++i )
{
/* color 0 */
c0[i] = (int)(0.5f + sum_x[i] + dot_max * sum_x2[i]);
if( c0[i] < 0 )
{
c0[i] = 0;
} else if( c0[i] > 255 )
{
c0[i] = 255;
}
/* color 1 */
c1[i] = (int)(0.5f + sum_x[i] + dot_min * sum_x2[i]);
if( c1[i] < 0 )
{
c1[i] = 0;
} else if( c1[i] > 255 )
{
c1[i] = 255;
}
}
/* down_sample (with rounding?) */
i = rgb_to_565( c0[0], c0[1], c0[2] );
j = rgb_to_565( c1[0], c1[1], c1[2] );
if( i > j )
{
*cmax = i;
*cmin = j;
} else
{
*cmax = j;
*cmin = i;
}
}
void
compress_DDS_color_block
(
int channels,
const unsigned char *const uncompressed,
unsigned char compressed[8]
)
{
/* variables */
int i;
int next_bit;
int enc_c0, enc_c1;
int c0[4], c1[4];
float color_line[] = { 0.0f, 0.0f, 0.0f, 0.0f };
float vec_len2 = 0.0f, dot_offset = 0.0f;
/* stupid order */
int swizzle4[] = { 0, 2, 3, 1 };
/* get the master colors */
LSE_master_colors_max_min( &enc_c0, &enc_c1, channels, uncompressed );
/* store the 565 color 0 and color 1 */
compressed[0] = (enc_c0 >> 0) & 255;
compressed[1] = (enc_c0 >> 8) & 255;
compressed[2] = (enc_c1 >> 0) & 255;
compressed[3] = (enc_c1 >> 8) & 255;
/* zero out the compressed data */
compressed[4] = 0;
compressed[5] = 0;
compressed[6] = 0;
compressed[7] = 0;
/* reconstitute the master color vectors */
rgb_888_from_565( enc_c0, &c0[0], &c0[1], &c0[2] );
rgb_888_from_565( enc_c1, &c1[0], &c1[1], &c1[2] );
/* the new vector */
vec_len2 = 0.0f;
for( i = 0; i < 3; ++i )
{
color_line[i] = (float)(c1[i] - c0[i]);
vec_len2 += color_line[i] * color_line[i];
}
if( vec_len2 > 0.0f )
{
vec_len2 = 1.0f / vec_len2;
}
/* pre-proform the scaling */
color_line[0] *= vec_len2;
color_line[1] *= vec_len2;
color_line[2] *= vec_len2;
/* compute the offset (constant) portion of the dot product */
dot_offset = color_line[0]*c0[0] + color_line[1]*c0[1] + color_line[2]*c0[2];
/* store the rest of the bits */
next_bit = 8*4;
for( i = 0; i < 16; ++i )
{
/* find the dot product of this color, to place it on the line
(should be [-1,1]) */
int next_value = 0;
float dot_product =
color_line[0] * uncompressed[i*channels+0] +
color_line[1] * uncompressed[i*channels+1] +
color_line[2] * uncompressed[i*channels+2] -
dot_offset;
/* map to [0,3] */
next_value = (int)( dot_product * 3.0f + 0.5f );
if( next_value > 3 )
{
next_value = 3;
} else if( next_value < 0 )
{
next_value = 0;
}
/* OK, store this value */
compressed[next_bit >> 3] |= swizzle4[ next_value ] << (next_bit & 7);
next_bit += 2;
}
/* done compressing to DXT1 */
}
void
compress_DDS_alpha_block
(
const unsigned char *const uncompressed,
unsigned char compressed[8]
)
{
/* variables */
int i;
int next_bit;
int a0, a1;
float scale_me;
/* stupid order */
int swizzle8[] = { 1, 7, 6, 5, 4, 3, 2, 0 };
/* get the alpha limits (a0 > a1) */
a0 = a1 = uncompressed[3];
for( i = 4+3; i < 16*4; i += 4 )
{
if( uncompressed[i] > a0 )
{
a0 = uncompressed[i];
} else if( uncompressed[i] < a1 )
{
a1 = uncompressed[i];
}
}
/* store those limits, and zero the rest of the compressed dataset */
compressed[0] = a0;
compressed[1] = a1;
/* zero out the compressed data */
compressed[2] = 0;
compressed[3] = 0;
compressed[4] = 0;
compressed[5] = 0;
compressed[6] = 0;
compressed[7] = 0;
/* store the all of the alpha values */
next_bit = 8*2;
scale_me = 7.9999f / (a0 - a1);
for( i = 3; i < 16*4; i += 4 )
{
/* convert this alpha value to a 3 bit number */
int svalue;
int value = (int)((uncompressed[i] - a1) * scale_me);
svalue = swizzle8[ value&7 ];
/* OK, store this value, start with the 1st byte */
compressed[next_bit >> 3] |= svalue << (next_bit & 7);
if( (next_bit & 7) > 5 )
{
/* spans 2 bytes, fill in the start of the 2nd byte */
compressed[1 + (next_bit >> 3)] |= svalue >> (8 - (next_bit & 7) );
}
next_bit += 3;
}
/* done compressing to DXT1 */
}

123
cw 5/src/SOIL/image_DXT.h Executable file
View File

@ -0,0 +1,123 @@
/*
Jonathan Dummer
2007-07-31-10.32
simple DXT compression / decompression code
public domain
*/
#ifndef HEADER_IMAGE_DXT
#define HEADER_IMAGE_DXT
/**
Converts an image from an array of unsigned chars (RGB or RGBA) to
DXT1 or DXT5, then saves the converted image to disk.
\return 0 if failed, otherwise returns 1
**/
int
save_image_as_DDS
(
const char *filename,
int width, int height, int channels,
const unsigned char *const data
);
/**
take an image and convert it to DXT1 (no alpha)
**/
unsigned char*
convert_image_to_DXT1
(
const unsigned char *const uncompressed,
int width, int height, int channels,
int *out_size
);
/**
take an image and convert it to DXT5 (with alpha)
**/
unsigned char*
convert_image_to_DXT5
(
const unsigned char *const uncompressed,
int width, int height, int channels,
int *out_size
);
/** A bunch of DirectDraw Surface structures and flags **/
typedef struct
{
unsigned int dwMagic;
unsigned int dwSize;
unsigned int dwFlags;
unsigned int dwHeight;
unsigned int dwWidth;
unsigned int dwPitchOrLinearSize;
unsigned int dwDepth;
unsigned int dwMipMapCount;
unsigned int dwReserved1[ 11 ];
/* DDPIXELFORMAT */
struct
{
unsigned int dwSize;
unsigned int dwFlags;
unsigned int dwFourCC;
unsigned int dwRGBBitCount;
unsigned int dwRBitMask;
unsigned int dwGBitMask;
unsigned int dwBBitMask;
unsigned int dwAlphaBitMask;
}
sPixelFormat;
/* DDCAPS2 */
struct
{
unsigned int dwCaps1;
unsigned int dwCaps2;
unsigned int dwDDSX;
unsigned int dwReserved;
}
sCaps;
unsigned int dwReserved2;
}
DDS_header ;
/* the following constants were copied directly off the MSDN website */
/* The dwFlags member of the original DDSURFACEDESC2 structure
can be set to one or more of the following values. */
#define DDSD_CAPS 0x00000001
#define DDSD_HEIGHT 0x00000002
#define DDSD_WIDTH 0x00000004
#define DDSD_PITCH 0x00000008
#define DDSD_PIXELFORMAT 0x00001000
#define DDSD_MIPMAPCOUNT 0x00020000
#define DDSD_LINEARSIZE 0x00080000
#define DDSD_DEPTH 0x00800000
/* DirectDraw Pixel Format */
#define DDPF_ALPHAPIXELS 0x00000001
#define DDPF_FOURCC 0x00000004
#define DDPF_RGB 0x00000040
/* The dwCaps1 member of the DDSCAPS2 structure can be
set to one or more of the following values. */
#define DDSCAPS_COMPLEX 0x00000008
#define DDSCAPS_TEXTURE 0x00001000
#define DDSCAPS_MIPMAP 0x00400000
/* The dwCaps2 member of the DDSCAPS2 structure can be
set to one or more of the following values. */
#define DDSCAPS2_CUBEMAP 0x00000200
#define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400
#define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800
#define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000
#define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000
#define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000
#define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000
#define DDSCAPS2_VOLUME 0x00200000
#endif /* HEADER_IMAGE_DXT */

Some files were not shown because too many files have changed in this diff Show More